6 years, 9 months ago.

How does the RX buffer synchronization/critical section work?

Hi Sam,

Can you explain how the RX buffer synchronization works. Bytes are inserted in an IRQ function and extracted by 'main' but I don't see any synchronization, disabling interrupts, etc?

(I want to use it in an app that can have a fast burst of incoming bytes).

Question relating to:

Inherit from Serial and use software buffers for TX and RX. This allows the UART peripherals to operate in a IRQ driven mode. Overrides most (but not all) stdio functions … buffer, BufferedSerial, BufferSerial, Serial

Thanks for the prompt answer. You are using the Buffers class and for the RX push from an IRQ and pull from main. This requires critical section protection to avoid pushing while a pull is in progress. Have you made sure that Buffers protects itself and if not, did you add critical section protection in your buffered serial class?

You can read more about it here https://developer.mbed.org/cookbook/Serial-Interrupts#critical-sections-using-enable-and . Notice how they disable the interrupt to avoid an IRQ while the buffer is accessed by main.

posted by Zapta Z. 06 Apr 2015

2 Answers

6 years, 8 months ago.

I have a clone and added some code, not sure how to commit to this lib.

Import libraryBufferedSerial

Inherit from Serial and use software buffers for TX and RX. This allows the UART peripherals to operate in a IRQ driven mode. Overrides most (but not all) stdio functions as Serial did

6 years, 8 months ago.

Since it uses a circular buffer with seperate read/write pointers it is a relative save buffer implementation. However I do see that the compiles result might very well increase the buffer counter before writing the data, so then it would be possible you read data before it was written to the buffer, and that could indeed be a problem.