TouchGFX initialization should not use FreeRTOS API before initialization
I probably found a design issue by the code generated by the STM32CubeMX for TouchGFX project.
When using project generated by STM32CubeMX, the main.c initialization looks like this:
int main(void)
{
// Generated initialisation code ...
MX_TouchGFX_Init();
/* Call PreOsInit function */
MX_TouchGFX_PreOSInit();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */
MX_FREERTOS_Init();
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}Here you see the MX_TouchGFX_Init() function called to initialize the TouchGFX library. Underlaying it calls the name_init() which is part of the static linked library. During the nema initialization the static linked code somewhere calls the FreeRTOS API by calling osSemaphoreNew().
Calling FreeRTOS API functions before initializing the FreeRTOS is not intended, so the global interrupts are disabled.
If a FreeRTOS API function is called before the scheduler has been started then interrupts will deliberately be left disabled, and not re-enable again until the first task starts to execute. From FreeRTOS FAQ
I had the same issue from my own code and also see that some other users have problems, because all custom code using HAL_Delay funtions between TouchGFX initialisation and FreeRTOS initialization will block the whole application. See discussion here.
Can the generated TouchGFX Code be adapted, so that the initialization does not call FreeRTOS API functions or the initialization is done within the TouchGFX Task it self?
Best regards
Martin
