2025-06-19 9:09 AM
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.
/* 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 */
2025-06-19 9:16 AM