cancel
Showing results for 
Search instead for 
Did you mean: 

Freertos semaphore initialised wrong in CubeMX

Taha
Associate

CubeMX always generates binary semaphores with an initial count of 1 (full) in CMSIS-RTOS2, even if the user wants the semaphore to start depleted (count = 0). There is no option to set the initial count to depleted during configuration, but when generating the code, it will be with initial count of 1.

Taha_0-1750349263021.png

/* creation of myBinarySem01 */
  myBinarySem01Handle = osSemaphoreNew(1, 1, &myBinarySem01_attributes);

  /* creation of myBinarySem02 */
  myBinarySem02Handle = osSemaphoreNew(1, 1, &myBinarySem02_attributes);

only way I solve it is acquiring the semaphore after creating it

* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  osSemaphoreAcquire(myBinarySem02Handle, 10);

  /* USER CODE END RTOS_SEMAPHORES */

 

1 REPLY 1
Andrew Neil
Super User

https://community.st.com/t5/stm32-mcus-embedded-software/freertos-binary-semaphore-initial-state-bug/m-p/803175 ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.