Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino Ring Buffer is not suitable for serial interface #154

Open
hn opened this issue Aug 11, 2023 · 3 comments
Open

Arduino Ring Buffer is not suitable for serial interface #154

hn opened this issue Aug 11, 2023 · 3 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@hn
Copy link
Contributor

hn commented Aug 11, 2023

Libretiny uses the Arduino Ring Buffer for serial port i/o. However, the implementation is not interrupt-safe and there are no plans to change this.

This causes hard to debug problems with serial i/o. One pain point is that the Arduino Ring buffer is very error prone when used in such a situation (it uses a redundant way to store its state). And if it breaks, it will never be good again (no self-healing). You have to (in most cases) reboot the device or restart the component in question.

As far as I can (quickly) see the ESP8266 and ESP32 serial port components do not use the Arduino Ring Buffer, but implement some own 'magic' for the buffer.

I suggest replacing the Arduino Ring Buffer within the serial component with a better option (at least it should not break permanently).

@hn hn changed the title Arduino ring buffer is not suitable for serial interface Arduino Ring Buffer is not suitable for serial interface Aug 11, 2023
@kuba2k2 kuba2k2 added bug Something isn't working enhancement New feature or request labels Aug 11, 2023
@hn
Copy link
Contributor Author

hn commented Aug 12, 2023

Please consider the work of @KurtE for a possible solution: hn/ginlong-solis#4 (comment) and hn/ginlong-solis#4 (comment)

I'm using hn/ginlong-solis@76d81ce as a temporary workaround.

@kuba2k2
Copy link
Member

kuba2k2 commented Aug 12, 2023

It seems that using the SafeRingBuffer would be a viable option, since it's only a small wrapper around the RingBuffer from Arduino API. On that note, it's pretty disappointing that the API is so much different from most actual official Arduino cores (even things like Serial.printf(), which makes Arduino devs very angry when mentioned).

If the wrapper adds too much overhead by using the synchronized blocks, it could be rewritten to use FreeRTOS' mutexes or semaphores instead.

@hn
Copy link
Contributor Author

hn commented Aug 20, 2023

If I understand correctly, ESP32 uses this:

#define UART_MUTEX_LOCK()    do {} while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS)
#define UART_MUTEX_UNLOCK()  xSemaphoreGive(uart->lock)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants