2017-04-02 03:53 PM
Everyone,
Does anyone know where I can find a simple example for FreeRTOS on Mutex ?
I want to do two task but the first task never finishes and jump already to the second one because of the systick,
how can I make the first one finish and do the second one with Mutex ?
Thanks for reading and advicing
#multitasking #rtos #stm32f1xx #mutex Note: this post was migrated and contained many threaded conversations, some content may be missing.2017-04-02 09:17 PM
Try the
or better still the .2017-04-03 04:14 AM
Thanks for the link, I appreciate that, can you tell me which directory containing an example for semaphore in FreeRTOS9 directory ? thanks
2017-04-03 07:55 AM
Hello
H.Rick
,In all STM32Cube packages, you will find an example called ''FreeRTOS_Mutexes''.
Just search it in the package you are using.
You can getmore details about mutexes in the
''Developing Applications on STM32Cube with RTOS'', sub-section ''Mutexes example''.If you are using an STM32F4, the example ''
FreeRTOS_Mutexes'' is available as application example for boards marked with ''x'' in this table (extracted from
:(-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2017-04-03 12:12 PM
I think use semaphore instead of mutex is easier.
SemaphoreHandle_t Sem1, Sem2;
int main(void) {
/* Create semaphore. */
Sem1 = xSemaphoreCreateBinary();
Sem2 = xSemaphoreCreateBinary();.... Create task and run scheduler.
}
void Task1(void *param) {
/* Give once for first time. */ xSemaphoreGive(Sem1);while(1) {
/* Wait for Sem1 */
if(xSemaphoreTake(Sem1, portMAX_DELAY) == pdTURE) {/* Your first task code */
/* Wake
the
second task. */xSemaphoreGive(Sem2);
}}
}void Task2(void *param) {
while(1) {
/* Wait for Sem2 */
if(xSemaphoreTake(Sem2, portMAX_DELAY) == pdTURE) {/* Your second task code */
/* Wake
the
first task. */xSemaphoreGive(Sem1);
}}
}2017-04-03 05:23 PM
Thank you very much for the advice.
2017-04-04 01:58 AM
That's good idea to try, thanks
2017-04-04 10:51 PM
What should I add on task2 if task 2 time is much longer than task 1 ? and task 2 time is much longer than default systick ?
It seemed that it's doing task 1 but failed on task 2 then stop forever ?
thanks
2017-04-04 11:04 PM
Did you read the chapter on mutexes in the book I posted a link to in my first reply? In particular read the part about using mutexes from tight loops.
2017-04-05 12:20 AM
This chapter : 7.3 Mutexes (and Binary Semaphores) ?
Which part exactly ? May be I missed it ?