Skip to content

RingBuffer interrupt issue (with simple solution) #287

@Klaus-KK

Description

@Klaus-KK

This issue was discovered by the following thread in the Arduino forum.

https://forum.arduino.cc/t/issue-receiving-serial-data-on-nano-33-ble-uart/851945

The RingBuffer implementation for the Arduino Nano 33 BLE (and others) is not interrupt safe, because it uses a variable to keep track of the number of elements in the buffer (_numElems), instead of calculating it from the write and read index (_iHead, _iTail). I could not find the RingBuffer.h file in this repository but believe it is in the following location.

This RingBuffer.h is not interrupt safe
https://github.com/arduino/ArduinoCore-API/blob/master/api/RingBuffer.h

By accident I found the Nano 33 IoT has a different RingBuffer.h file that handles this correctly by calculating the available elements in the buffer.

This RingBuffer.h is interrupt safe.
https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/RingBuffer.h

Can you update the RingBuffer.h file to the version already used in the ArduinoCore-samd?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions