Showing results for 
Search instead for 
Did you mean: 

How to transform a project without RTOS into a project with Azure RTOS?

Associate III

Hi all,

thank you very much for the valuable advices.

I am writing to you because I would like to understand how I can convert an existing program without Azure RTOS ThreadX with a program in which I use Azure RTOS ThreadX.
For example I would like to add Azure RTOS ThreadX on an existing program that reads a series of values ​​with GPIO, ADC, or by communicating with external components with SPI and I2C and sets digital signals with PWM and GPIO. It also communicates via the serial port with another board.
What should I do with CubeMX?
Do I take the existing project and add ThreadX in the "Middleware" section and change the timebase source for "SYS" from SysTick to TIM6 in the "System Core" section?
Do I need to make further changes in CubeMX?
At the code level I will have to use Threads, but how can I structure the program?
Currently the commands arrive on the serial port through the interrupt and I insert them into the relevant buffer which is read by a function present in the while(1) of the main. The readings of some digital and analog signals are made every few milliseconds and to do this I use interrupts. I would like to understand how I can structure the program. How can I organize at file level, today almost all the code is in the main.c file and I would like to understand with what logic I create the threads and assign them to the various activities (GPI readings, ADC readings, reading from external components with SPI and I2C, management of the serial buffer and related responses, writes to memory, etc.).

Let me know what rules I should follow to structure the code well.

Thank you very much for the support.

Andrew Neil
Evangelist III

Don't forget to add a link to this in your previous thread!

And did you take a look at those introductory resources?

No, you can't just "bolt on" an RTOS to an existing project.

Running under an RTOS is a whole new way of structuring your system - you need to design your task structure, think about priorities, think about how tasks will communicate, etc, etc ...

Hi @Andrew Neil ,

yes I read the documentation quite fast and I checked also the webinar on the ST youtube channel about Azure RTOS ThreadX. The example of the toggle led with and without RTOS is very easy, but what about a more complex program?

It could be very useful to understand step by step how to design the task structure. I do not have experience with RTOS and if you have some advices or some step by step documentation or projects about how to design a project with Azure RTOS ThreadX, it could be very useful.

Thank you very much for the support.

In classic app you dont require RTOS, only IRQ and DMA is capable todo all required, but this ends when multiclient peripheral exist. For example ethernet or audio stream... Here MCU require more as one thread system.

Your question switch to RTOS is simple all from main while you manualy move into first task... Next steps is your job

Pavel A.
Evangelist III

Here you can find advice and help with all aspects of your STM32 project.


Hi @MM..1 ,

thank you very much for the answer.

I want to better understand how to design the project in the best way. Suppose we have a simpler project with:

1) a timer interrupt that runs every 1 ms. Every 1 ms 5 GPIOs input signal are read to see quickly if these digital inputs change.
2) Using the 1 ms interrupt timer I read the analog signals every 100 ms
3) I communicate through the serial, then I use the interrupt on the serial to load the data into the serial buffer
4) In main I analyze the serial buffer and then carry out some actions

How do I convert this to an Azure RTOS ThreadX OS project?

1) I keep the interrupt on the serial port which loads the data into the serial buffer
2) I create a thread to analyze the serial buffer
3) I create a thread with higher priority for digital input readings
4) I create another thread for reading analog signals

Could it be a valid structure?
Now the readings of analog and digital signals are done with times defined with the Threads and the operating system, how do I know how often they would be read?
How do I define the priority of the various threads?

Let me know!

Thank you very much for the support.

Hi all,
Could anyone give me some feedback or advices?
Thank you very much for the support!

Have you been through the full video series - there's at least 5:




Of course, Azure RTOS is not an ST thing - so there are loads of general resources out there.

Note that it's now open-source, and known as Eclipse ThreadX: