cancel
Showing results for 
Search instead for 
Did you mean: 

Get serial port buffer size

Peter Penzov
Associate II
Posted on December 18, 2017 at 08:14

Hi All,

   I'm using FreeRTOS and NUCLEO-F746ZG. Is there a way to get the size of the serial port buffer memory? The only way that I found is using register but I'm looking for a better solution.

@arg UART_FLAG_RXNE: Receive data register not empty flag

Can you propose some solution, please?

#free-rtos #nucleo
7 REPLIES 7
Doug Kehn
Senior
Posted on December 18, 2017 at 13:38

There is no buffer provided by the peripheral/MCU, just RDR register. A buffer can be provided by using interrupt or DMA. See the

http://www.st.com/content/ccc/resource/technical/document/reference_manual/c5/cf/ef/52/c0/f1/4b/fa/DM00124865.pdf/files/DM00124865.pdf/jcr:content/translations/en.DM00124865.pdf

for information.
Posted on December 18, 2017 at 15:02

In my case I use interrupts to read data from serial port. Let me give you little more information.

I have a problem with the incoming data. Each time the data size is different. We use RFID reader via serial port connection. Data is send to Nucleo board in different size each time.

How I can use 

buffer from interrupts and get the size of the buffer?

What if I will use a FIFO struct linked to serial port, and every time there is a new byte, into ISR I will read byte and PUSH into FIFO.

After this, outside the ISR, 'higher level' application can check FIFO available data and POP from FIFO the received data.

For sure, FIFO struct have to be linked to a buffer large enough to save maximum length command received from serial port.

Is this a common way to manage receiving data from serial port

Posted on December 18, 2017 at 17:07

You would need to provide your own buffering and reporting methods. I typically use a software FIFO scheme, in extreme cases I use DMA bufferring where I understand the data stream properties, or must account for significant service latency.

Some of the newer parts (L4+, H7) have 8 or 16 word FIFOs, but the depth is not exposed.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 18, 2017 at 17:16

Thanks for the reply. Do you know where I can find code snippet for this solution?

Posted on December 19, 2017 at 14:16

Sure, a FIFO can be used. It really just depends on your application, use-cases, etc.

For my application, I used a circular buffer. The ISR inserted into the buffer. An application task removed from the buffer. The circular buffer was sized to not overflow under 'normal' operation.

Posted on December 19, 2017 at 20:12

Can you show me code snippet or working example?

Posted on December 19, 2017 at 20:29

The use of a Ring Buffer - aka Circular Buffer or FIFO - is pretty much a universal standard when it comes to handling UARTs.

http://www.lmgtfy.com?q=microcontroller+UART+Ring+Buffer