A general question about serial data (usart) and an RTOS
I have a specific problem, I'm trying to read data from a serial source, length unknown, transmission length known, in an RTOS environment (FreeRTOS to be exact). I'm using the HAL drivers because at least, they set things up for me.
I have several problems with this.
My operational problem is that using HAL transmit (no DMA, no IRQ because it works well, I can survive if the transmit task is interrupted) to an ESP8266 sends well.
Receiving works mostly, misses some characters, and messes up some pointers and a data structure attached to the receive.
In an operating system environment, any task (and this is one) can be interrupted at any time for any reason. So my receive has to survive being interrupted. The interrupt time can be a millisecond or more and at a 115200 baud input rate, that's about 10 characters. The hardware USART in the chip has a buffer of one character.
We won't go into how inconvenient that is, whether or not the decision even makes sense, but it is what it is and we can't expect the hardware to be redesigned.
So we have to fix it in software....
I'm currently using DMA receive, CubeMX generated code (and no, I"d prefer not to use LL drivers, not yet, they don't get along well with HAL drivers). Every once and a while, the DMA HAL driver does something, or the system does something, and the RX buffer is messed up. Remember that this is an RTOS driven system, and any task (receive, get character, put in buffer) can be interrupted. Several characters are missed, and earlier characters in the string are missing. I am also getting the RX buffer (fed by DMA) filled with a lot of zeros. You can argue that this is a bad pointer, but it's set up by code, one way or another. The transmit, but not receive, is protected by a semaphore.
While the buffer is filled with zeros to start with, that the buffer has lots of leading zeros says that the DMA routine is putting them in once a timed receive is executed. I've looked at the serial stream coming in, it has no omissions.
I have a few observations, and then some questions:
Firstly, that the HAL routines for serial transmission are flawed, and flawed critically.
THIS IS A BUG.
NOBODY who wrote the HAL routines ever considered the situation where a serial peripheral would return a variable number of bytes. EVER.....
Sorry, but reality wins here. ESP8266 is one case, and so (apparently) is a GPS peripheral.
Indedd, while the LL drivers enable the IDLE LINE flag, the HAL drivers do not.
Haven't seen that fixed yet.
It may be possible (in this particular situation) to designate a particular character as a "stop" character. No facility for this exists in the HAL drivers.
it may be possible to designate a time by which all replies should be generated. No facility for this exists in the HAL drivers.
This list is a sart.
