If called second time - fix the counts to reflect just the size of the new buffer plus the static buffer.
Also as a precaution, resets the TX or RX head tail pointers back to 0 to make sure it is not indexing into memory that may not exist.
An experiement to see how much work again it would take to add the T4 methods to allow user sketches to increase the size of Serial ports RX and TX buffers, without having to edit the Source code which does it then for all sketches.
T3.x SerialN Add extra memory capabilities for Serial1-6
Also
Fixed serialEventX yield handling when you call begin multiple times
There is an issue that if you are not using the serialEvent type code and you call SerialX.begin multiple times, it will add that item to the process list multiple times, which can overrun the memory and cause crash or the like.
Fix was to check the list first and see if we are already in the list.
Migrating the half duplex support I did in the Stagnant and out of date PR to enhance Uarts: https://github.com/PaulStoffregen/cores/pull/419
To try to support Half duplex mode in a similar way like we do for RS485 like support.
With T3.x made use of bitband address for the TX Direction setting, so
Except for the begin which calls format, no code changed, we simply stored the bitband address of the TXDIR flag into the TXDIR variable that was already used for the set direction flag.
For T4.x - it is a little more work as there is no bitband support on M7 processors. For GPIO there is a Set and Clear register which we use, but for the appropriate UART register there is no such setup of registers. So I have to special case we are in that mode and do it... Also since not atomic I cli/sei...
Serial Half Duplex - Fix T4Serial1 and T-LC Serial1-3
Updates: T4
T4 Serial 1 did not have proper settings for IOMUXC_LPUART6_TX_SELECT_INPUT
Tested T4.1 Serial1-8
Tested T3.5 Serial1-6
T3.6 - Added support for LPUART which is Serial6 which now works.
T-LC
Make half duplex work on T-LC on Serials1-3
Tested on on T3.5 1-6
I forgot to remove the default eventhandlers from some of the HardwareSerial files as such the ones in the serialEventX files was not used and why my flags were not set properly.
Could have done simple fix, but decide to make it more consistent with what I did in T3.x/LC code and not look through all the NULLS, but simply have list of active ones and count of active.
Appears to fix the issue so far.
Found a way that appears to work to detect if a sketch has our default serialEvantX functions, and that the users code has not implemented their own. Before on SerialX.begin() I would add that serial ports code to table of function calls to do the if SerialX.available() call serialEvernt..
But I now have a hacked up version where each of the event functions are in their own source file, along with a variable that is defined. Elsewhere I have those same variables defined with an attribute of ((weak)), so if our default implemention is pulled in it is defined with a value of 1, if the weak version is used because the user has their own implemention, then it is defined as a 0... So I can detect this at the begin method and only add the code to do the checks in yield if the user implemented it.
WARNING this also brought in changes for using XBar pins for CTS and RX pins... As I did not wish to split back out and have you maybe have to manually merge.
A couple of minimalist changes.
systick_isr - By default it does nothing with the event responder.
Only if the user calls the attachInterrupt member of EventResponder will it install the version of the ISR that checks the list for any active ISR event Responders.
T4 Yield - try to keep bitfields for things yield should test
Make it such that yield hopefully can test to see there is nothing to do and returns quickly.
There are some interesting limitations, that is that the serialEvent
handling code. Both for USB and hardware Serial can only remove it self
if the default eventHandler is called once, as I don't know anyway to
detect if the default code (weak linkage) is included or if it is a user
version. So waits until called to remove it self from active list.
Sketches can force this by simply calling the event method right after
calling begin on the serial port.
It never came up much with T4 as there were not really alternative pins...
But fixed and tested with simple sketch on T4.1 and simple jumper to TX and RX pins on memory chip locations
Extracted from other PR.
This change only adds the code to look at the RX FIFO when you call available, and read/peak if our software queue is empty, it then checks to see if hardware FIFO has data to extract.
Fixed the Serial2 object to use the new correct pins, plus made Serial8 only valid for T4 B1 (not B2).
Also I defined IO pins for the six signals associated with the SD Card slot.
I have tested these both as IO pins and now as SPI2
Allow the user to call setTX with the one hardware pin, and hopefully allow them to turn on Open Drain mode or turn it back off. I don't currently have any test cases that use this, so not sure how well it works.
Add some support for serialEventX calls when yield is called.
Currently keep table of which SerialX objects are Used (.begin called) and each has their own function which does the
if (Serial1.available()) serialEvent1();
Calling SerialX.end(), removes the call from the list. Also the default weak pointer serialEventX functions call the disable function, as to only be called once as no one is actually processing them...
At some point will integrate this with EventResponder
Put in first pass at SerialX.end(),
Which should disable the Serial object, and I believe set the IO pins to be GPIO pins.
Also defined the extern void SerialEvent1() like functions in header in preperation for callbacks...
Fleshing out some of the missing pieces. - Need to test
copy NVIC execution priority from T3
Set priority per Serial object
RTS pin
CTS pin - only Serial3 supports
setRX, setTX - do nothing none of these have two pins defined.
Maybe temporary - but added from previous code ability to add second buffer for RX and TX
Used macros from OneWIre to fast set/clear the optional Transmitter Enable support.
Also fixed bug in ISR where was not properly looking for TC. This will help make SerialX->flush() to work
This pass has some more support for using the Hardware Serial objects.
Including setting an ISR for doing both reads and writes, sets up the FIFO,
Sitll lots more work to go.
Things like: fifo - need to better understand/set watermarks, also RX need to read in more than one byte if more available.
Also support fo r other features, like formats, 9 bit, ...
BUt at least you can do simple reads/writes