Today, thanks to Xavier’s tips, I finally managed to write a satisfying workflow for the UART server. I used the ChibiOS’ mailbox system on the STM32 and emulated it with queues on the ESP32.
Each applications is in charge of allocating the actual memory space of the data. The server only manages a 256 words long table to store a single pointer for each of the 256 possible ports. This pointer references two mailboxes. One enables the application to provide a buffer and its length to the server while the other enables the server to signal that a given buffer has been filled with a given number of bytes.
Thanks to this setup, the application can create mailboxes larger than only one mail storage capacity. Then it statically allocates as many buffers as there are boxes in the mailboxes. This way, the server will not block if messages arrive faster than they are consumed. Note that sending buffers to the server and getting them back filled are to separate functions. This guaranties that set buffers will never block. Indeed, you begins by filling the mailbox with the exact number of buffers. Then, each time you consume one buffer on the second mailbox, you are certified than one was previously consumed on the first one. In other words, a place was freed.
Up to now, however, I did not test my code. It compiles, as well as an echo function. I hope tomorrow’s debugging will be fast !