Skip to main content
tizdipietro
Associate III
February 29, 2024
Solved

Freertos semaphore not initialised correctly by CubeMX

  • February 29, 2024
  • 4 replies
  • 2690 views

By setting up a new project in STM32CubeMX 6.10.0, when adding a Semaphore in FREERTOS, the generated code is not correct, and the binary semaphores are initialised in a Taken state ( initial_count=0 of osSemaphoreNew() )  - resulting in the fact that the application will never be able to take the semaphore - see code snippet below. 

 

 

 

/**
 * @brief FreeRTOS initialization
 * None
 * @retval None
 */
void MX_FREERTOS_Init(void) {
	/* USER CODE BEGIN Init */

	/* USER CODE END Init */

	/* USER CODE BEGIN RTOS_MUTEX */
	/* add mutexes, ... */
	/* USER CODE END RTOS_MUTEX */

	/* Create the semaphores(s) */
	/* creation of i2sHalfCpltReadySem */
	i2sHalfCpltReadySemHandle = osSemaphoreNew(1, 0, &i2sHalfCpltReadySem_attributes);

 

 

 

 The correct function call should be with initial_count=1 as here below and how it was in older MX versions

 

 

 

foo = osSemaphoreNew(1,1, &bar);

 

 

For users having the same issue: quick fix is to add these line after initialisation

/* USER CODE BEGIN RTOS_SEMAPHORES */
osSemaphoreRelease(i2sHalfCpltReadySemHandle);

 

For ST Employees: please fix Cube MX to properly initialise.

Best answer by mƎALLEm

Issue fixed in the latest version of CubeMx 6.12.0

4 replies

mƎALLEm
Technical Moderator
February 29, 2024

Hello,

Thank you for raising this issue. Will raise this internally to be fixed.

Internal Ticket 174972 (not accessible by ST community members).

"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."
mƎALLEm
mƎALLEmBest answer
Technical Moderator
July 5, 2024

Issue fixed in the latest version of CubeMx 6.12.0

"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."
Visitor II
March 12, 2025

Hi: 

The bug is still there, ver is CubeMx6.13/6.14, the initial state of Semaphore is always 1, would you check it?

mƎALLEm
Technical Moderator
March 13, 2025

Hello @seajeep ,

According to the internal team, the issue has been fixed in the MCU part numbers supporting native FREERTOS such as H7RS, F1 etc .. However, it still exist in other MCU part numbers that are not supporting natively X-Cube-FREERTOS pack and it will be fixed in the coming revisions of X-Cube-FREERTOS.

"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."
Visitor II
March 15, 2025

Hello, that's true. We have no problem using L4/L4+, but this problem has been found in U575. Thank you. We hope this problem will be solved in the next version!