Example for using UART driver (STM32L432)
Posted: Mon Sep 24, 2018 12:28 pm
Hi,
I'm trying to use the UART driver (not the serial one) with an STM32L432, using the RX way only - no TX.
I've not been able to find many examples about how to use it, and I guess I'm not doing the expected calls.
For testing purposes, UART1 RX receives a constant stream of ASCII char, so it's easy to debug and spot lost bytes. My example code simply copy back the received stream to another UART2 TX which acts as debug port. I know this looks like the serial driver use case, but the goal of the final implementation is to:
- use RX at high speed (8-10Mbps)
- filter data (about every other byte needs to be discarded)
- understand how to use the UART driver
I'm using rxend_cb to push the RX data into a ring buffer, and a RT thread is simply popping the ring buffer to print the data out.
I've configured the RX DMA buffer for 128 byte transfer.
No data is lost in a single buffer, but bytes are lost from one buffer to the next one. I'm not sure how to use the UART API, as I wonder how to properly call the UART driver so that no data is lost between rxend_cb is called, and a new DMA buffer is pushed to the UART driver. I think what I'm missing is what should be done when rxend_cb, i.e. DMA buffer has been filled, to provide a fresh buffer to the UART driver/HW and resume RX immediately.
I would have expected rxchar_cb to be called when data is received and no buffer is available, but it never gets called, so I probably did not get what is is meant for.
The API doc (uartStartReceive*) refers to "data frames" not to bytes. What does it actually mean? BTW, uartStartReceive* refers to data frame to *send*, not to receive.
Thanks for any help/pointers to an example implementation.
I'm trying to use the UART driver (not the serial one) with an STM32L432, using the RX way only - no TX.
I've not been able to find many examples about how to use it, and I guess I'm not doing the expected calls.
For testing purposes, UART1 RX receives a constant stream of ASCII char, so it's easy to debug and spot lost bytes. My example code simply copy back the received stream to another UART2 TX which acts as debug port. I know this looks like the serial driver use case, but the goal of the final implementation is to:
- use RX at high speed (8-10Mbps)
- filter data (about every other byte needs to be discarded)
- understand how to use the UART driver
I'm using rxend_cb to push the RX data into a ring buffer, and a RT thread is simply popping the ring buffer to print the data out.
I've configured the RX DMA buffer for 128 byte transfer.
No data is lost in a single buffer, but bytes are lost from one buffer to the next one. I'm not sure how to use the UART API, as I wonder how to properly call the UART driver so that no data is lost between rxend_cb is called, and a new DMA buffer is pushed to the UART driver. I think what I'm missing is what should be done when rxend_cb, i.e. DMA buffer has been filled, to provide a fresh buffer to the UART driver/HW and resume RX immediately.
I would have expected rxchar_cb to be called when data is received and no buffer is available, but it never gets called, so I probably did not get what is is meant for.
The API doc (uartStartReceive*) refers to "data frames" not to bytes. What does it actually mean? BTW, uartStartReceive* refers to data frame to *send*, not to receive.
Thanks for any help/pointers to an example implementation.