Today, as I was working on implementing the different servers from my last post, I realized a problem occurring on the UART connection between the main_esp and the main_stm. As I previously discussed in that post, I had to tackle the issue of distributing the traffic on the UART data bus.
To this end, I began to write a sort of server on the ESP32. It copies the port system on an internet server. The first byte of each frame encodes the function the following data line must be transferred to. In this approach, two problems must be tackled.
First, as previously mentioned, it is hard to customize the output of the STM32 shell. Thus, I decided to recreate it myself and have the prompt given by the ESP instead. Indeed, we only need the shell to run basics commands and the UART server already gives an interface similar to an actual shell.
Second, as my UART server separate bytes blocks thanks to line separators, there is a real need to ensure integrity when sending and receiving and to not mix data from different processes together. As far as receiving is concerned, it is actually pretty easy as only one thread receives. However, any thread can send data to the UART. I therefore created a dedicated thread to send which sends the content of a blocking queue. An element of the queue is a structure with a pointer to the buffer to send, as well as the length to send. The last element is a handle on the sending thread. Indeed, I believe that it is better for the sending function to be blocking while the data has not been sent. Thus, the sending thread pauses after sending to the queue and waits to be notified by the sending thread before resuming.