cancel
Showing results for 
Search instead for 
Did you mean: 

HAL functions and RTOS

sde c.1
Senior II

Hi,

It's awesome to be able to use HAL and RTOS together, i made big applications fast thanks to these tools.

The only disadvantage is that i'm not the architect anymore of my project. (for the HAL and RTOS part).

I'm now at the point where i sometimes get HAL error's like for ADC readouts or Flash writes. I would lilke to prevent investigating each error in order to write work around code, and want to deal with this more fundamental.

The code is now constructed where it is possible that different ADC or Flash functions can be called from different RTOS threads. I think that's the source of the problem.

To solve this i was thinking to create an ADC manager and a Flash manager in their own thread, so each functioncall will be added to a queue and will always execute from1 place only.

My questions to you guy's and Girls.

Is this the way you handle this too, or are there (build in) ways ?

i'm no expert in RTOS as i created before everyting myself, including my task switcher.

But to save time i have starting using these tools the moment i started with STM.

Thank you

Steve

3 REPLIES 3
Bob S
Principal

Same as with any resource that can be shared/used by more than one thread. The HAL code is NOT thread safe. Mutexes are your friend (kind of a fundamental RTOS concept). You don't necessarily need a dedicated task for each resource (A/D, Flash, etc.), though that is another way to ensure only one thread at a time accesses the resource. Depends on what the rest of your application is doing.

Pavel A.
Evangelist III

>  i was thinking to create an ADC manager and a Flash manager in their own thread, so each functioncall will be added to a queue and will always execute from1 place only.

Why not, if this works for you. Simple usually beats complicated.

Be aware that ST HAL libraries use delay function which is just a RTOS-hostile busy loop, based on a separate HAL timer.

And there are other integration issues related to the C runtime library aka newlib.

Good luck.

S.Ma
Principal

Sonetime I implement one peripheral handler with fifo or queues, like printer spools. Usually works with amd without rtos. Mulltiple threads can queue to time multiplex the hw peripheral, if the basic minimal contiguous transaction is defined. For I2C it is a write directly followed by a read.