Serial UART design for various size transfers
Hello,
I'm writing an application on the STM32F303 Nucleo board that uses the serial UART to receive commands and send responses. I believe example code from the standard peripherals library shows either single byte transfers or fixed size buffer transfers. That is, the UART receive interrupt is fired only after N bytes are received. But N is fixed... This doesn't work for the case where you may be receiving a variable number of characters in your input stream to make up a command.
I've got a system limping along asking for and receiving a single character interrupt at a time but this is less than a reasonable solution and it fails randomly with a HAL_UART_ErrorCallback as other things are going on in the Nucleo code. The error occurs much more frequently when I am simultaneously reading/writing the I2C bus.
Is there a way to peek into the RX UART handle and see how many characters are in the RX buffer and grab them? Polling the number of characters received at the top of the main loop and pulling them into my own circular buffer would probably work more reliably than single character interrupts.
Any thoughts on the best solution?
Thanks,
Dave