Design Considerations for Serial Communications in an RTOS Environment
Serial communications such as console are prevalent in the embedded software development. This workshop will explore options and tradeoffs when implementing serial communications in an RTOS environment, in particular the methods to receive serial data and the interactions between ISR and the data receiving task. The workshop will go through standard techniques and present a simple yet powerful design for high-speed and bursty serial traffic.
The workshop uses an STM32 board for hands-on experience. Any STM32 board is fine. STM32CubeIDE is used to generate the initial startup code to save time. A simple terminal program named Termite is used for serial communications between the STM32 board and a Windows computer. To maximize the benefits of hands-on experience, the hardware and software requirements are detailed below:
- STM32 board – an STM32 Nucleo-64 board is recommended since it is low-cost and uses a single USB cable for power, debugging, programing, and serial communications. It requires little effort to get started quickly.
- USB cable to connect the STM32 board to a Windows computer.
- IDE – Create a user account, download STM32CubeIDE from ST website https://www.st.com/en/
development-tools/ , and install it on a Windows computer.stm32cubeide.html - Terminal program – go to the Termite website https://www.compuphase.com/software_termite.htm, click the “Termite version 3.4 (program only) (76 KiB)” link, unzip the downloaded file in any folder on a Windows computer, and double-click Terminite.exe to run the program.
It would save time to review one of the following documents to identify the UART Rx/Tx pins and the user LED pin (optional) before the start of the workshop:
- user manual – under the Documentation tab of the board webpage, or
- schematic – under the CAD Resources tab of the board webpage
For example, the STM32 Nucleo-F303RE webpage is https://www.st.com/en/evaluation-tools/nucleo-f303re.html#. Under the Documentation tab, there is a link to the user manual “UM1724STM32 Nucleo-64 boards (MB1136)”. Under the CAD Resources tab, there are three links to the Rev. C03/C04/C05 board schematics. On STM32 Nucleo-64 boards marked with the MB1136 identifier, USART2 interface is available on the PA2/PA3 pins and LD2 is a user controlled green LED connected to the PA5 pin.
Note that the examples from the workshop are only intended to illustrate concepts. For the ease of presentation, they are much simpler than the production-level source code developed in real-world projects.
What main reason did the speaker give for using DMA with idle-line detection instead of byte-by-byte UART interrupts for high-speed or bursty serial traffic?
For the use case of a slow user typing one character at a time with a long gap between characters at a console, idle line detection will be triggered after each and every character, including the actual end of a serial command. It defeats the purpose of using idle line detection. The DMA + idle line detection-based solution is intended for handling high-speed and bursty serial traffic, i.e., data are sent in chunks and there is a small gap between the two adjacent chunks. The condition of Rx line being idle is detected due to the gap between the two adjacent chunks. The last slide of the presentation recommended an interrupt-based solution for console type of applications. In the case of slow typing, even a polling-based solution would work. Hope it helps.
It does! Thank you!
Fun presentation, Peifang! Could you or someone else help me find documentation on the functions "HAL_UARTEx_RxEventCallback()" and "HAL_UARTEx_ReceiveToIdle_DMA()"? I can't seem to find then in the STM32F3 HAL reference manual.
Thanks, Nathan! You can find the documentation on the function HAL_UARTEx_RxEventCallback() in the UM1725 "Description of STM32F4 HAL and low-layer drivers". Hope it helps.
Ah, thanks, I see it now!
Really interesting, thankyou
Glad to hear that it was interesting and useful. Thanks for taking the time to provide your feedback!
Excellent workshop. Clearly explained and practical starting point for an application. I can tell Mr. Zhou is passionate about his development. Thanks!
Thanks for attending the workshop and taking the time to write such a kind note! It has been a wonderful experience to listen to questions/feedback and learn real-world experiences from everyone.
I hope to see you return to the next EOC again!
Is there a recording for this presentation? Sadly I could not attend live.
Yes, coming soon.









Also, since typing speed is slow (by computer standards) won't the UART line idle after each character sent by a user who is typing at a console? How does the DMA version of these projects tell the difference between a slow typist and the actual end of a serial command?