FreeRTOS-LED-and-RTC-Using-Timers-STM32

Rohit Imandi
3 min readAug 29, 2023

--

This project demonstrates the use of FreeRTOS kernel after completing Mastering RTOS: Hands on FreeRTOS and STM32Fx with Debugging course by Kiran Nayak. This course helped me understand the general principles of any RTOS and the working of FreeRTOS in particular.

Application

Introduction

FreeRTOS tasks are used to blink all the on-board LEDs on STM32NUCLEO-F413ZH, configure and print the on-board real-time-clock (RTC) based on the input provided in the serial terminal. The RTC value printed may vary depending on the MCU board.

The application uses 5 tasks which are categorized into:

  1. I/O tasks that interact with the user via a serial terminal — Menu Task, LED Task, RTC Task
  2. Control task
  3. Helper task — Print Task

Furthermore, the application uses two queues namely, q_data_input and q_data_print that buffers the input/output messages from/to the serial terminal. The size of each queue is 10 bytes.

minicom in Ubuntu was used as the serial terminal for this project.

I/O Tasks Interacting with the User

The application begins with the Menu Task displaying its menu on the serial terminal and requesting an input from the user. Based on the user’s input the application switches to LED task or RTC task.

Menus of the three I/O tasks

Helper Task

The Print Task is a helper task used by the three I/O tasks to interact with the serial terminal. The I/O tasks enqueue a pointer to the input (message) from the terminal into a print queue (of size 10 bytes) which is subsequently dequeued by the print task and sent to the serial terminal via UART.

Print Task

Command Task

The Command Handling Task processes the message received from the serial terminal and notifies the relevant I/O task.

Command Task

State Diagram

Application State Diagram

The state diagram of the application is shown above. As mentioned earlier, the application begins by displaying the main menu from the Menu Task.

  1. After displaying the main menu, the Menu Task waits for a notification from the Command Handling Task by entering the BLOCKED state
  2. When the user provides an input in the serial terminal, the UART ISR unblocks the Command Handling Task. Subsequently, it processes the input message and notifies the Menu Task.
  3. On receiving a notification from the Command Handling Task, the Menu Task unblocks itself and notifies the relevant I/O task or exits the application based on the received input. The Menu Task then enters BLOCKED state.
  4. The corresponding I/O task unblocks itself and executes by processing the user’s input to its menu

--

--

Rohit Imandi
Rohit Imandi

Written by Rohit Imandi

Electronics and Embedded Systems | Programmer | Software Development

No responses yet