Skip to main content
antonius
Associate III
April 2, 2017
Question

FreeRTOS Mutex example ?

  • April 2, 2017
  • 4 replies
  • 9549 views
Posted on April 03, 2017 at 00:53

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.
This topic has been closed for replies.

4 replies

Barry.Richard
Visitor II
April 3, 2017
Posted on April 03, 2017 at 06:17

Try the

http://www.freertos.org/a00113.html

 or better still the

http://www.freertos.org/Documentation/RTOS_book.html

.
antonius
antoniusAuthor
Associate III
April 3, 2017
Posted on April 03, 2017 at 11:14

Thanks for the link, I appreciate that, can you tell me which directory containing an example for semaphore in FreeRTOS9 directory ? thanks

Amel NASRI
ST Technical Moderator
April 3, 2017
Posted on April 03, 2017 at 16:55

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

http://www.st.com/content/ccc/resource/technical/document/user_manual/2d/60/ff/15/8c/c9/43/77/DM00105pdf/files/DM00105pdf/jcr:content/translations/en.DM00105pdf

''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

http://www.st.com/content/ccc/resource/technical/document/application_note/ca/34/db/d3/71/50/44/9b/DM002135pdf/files/DM002135pdf/jcr:content/translations/en.DM002135pdf

:(

0690X00000606gwQAA.png

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
antonius
antoniusAuthor
Associate III
April 4, 2017
Posted on April 04, 2017 at 00:23

Thank you very much for the advice.

dechawat
Associate
April 3, 2017
Posted on April 03, 2017 at 21:12

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);

            }

      }

}
antonius
antoniusAuthor
Associate III
April 4, 2017
Posted on April 04, 2017 at 08:58

That's good idea to try, thanks

antonius
antoniusAuthor
Associate III
April 5, 2017
Posted on April 05, 2017 at 11:49

Is it relevant with :

http://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html

 

?

I tried putting the real task, and it seems that it never looped anymore and stack in one task.