2024-05-08 04:05 PM - last edited on 2024-05-09 01:21 AM by SofLit
Hello,
My board is STM32F429I-Disco1, the LED pin is PG13 and PG14, and the pins are set to 1. (So, after I click the run button,the LEDs light up).
After I write the code "HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);" and "HAL_Delay(500);" in the "while (1)" of main.c, I click the run button and the console shows "Download verified successfully". But the LED does not blink.
When I click run button,startup_stm32f429zitx.s appears next to main.c . The 61st line ("ldr sp, =_estack /* set stack pointer */") of startup_stm32f429zitx.s is marked.
May I ask how to handle this problem? Thank you very much.
Solved! Go to Solution.
2024-05-09 01:11 AM
Hello,
But you didn't mention you're using FreeRTOS which was an important information!
Indeed what are you seeing is a normal behavior. This is what you did:
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* 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 */
HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
HAL_Delay(500);
/* USER CODE BEGIN 3 */
}
You're toggling the LED after the call of osKernelStart(). So the while loop is no more reacheable.
So either you remove the usage of the FreeRTOS in your code as following:
/* Create the thread(s) */
/* definition and creation of defaultTask */
// osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
// defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* 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 */
HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
HAL_Delay(500);
/* USER CODE BEGIN 3 */
}
Or simply toggle the LED in one of the created tasks and remove it from the while loop in main(). In your case: StartDefaultTask():
.
.
.
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* 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 */
}
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const * argument)
{
/* init code for USB_HOST */
MX_USB_HOST_Init();
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
osDelay(500);
}
/* USER CODE END 5 */
}
Hope it does answer your question.
2024-05-08 09:19 PM
Hello,
Your issue is not clear. Could you please attach your project so we can have a look/test it?
2024-05-09 12:54 AM
2024-05-09 01:11 AM
Hello,
But you didn't mention you're using FreeRTOS which was an important information!
Indeed what are you seeing is a normal behavior. This is what you did:
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* 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 */
HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
HAL_Delay(500);
/* USER CODE BEGIN 3 */
}
You're toggling the LED after the call of osKernelStart(). So the while loop is no more reacheable.
So either you remove the usage of the FreeRTOS in your code as following:
/* Create the thread(s) */
/* definition and creation of defaultTask */
// osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
// defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* 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 */
HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
HAL_Delay(500);
/* USER CODE BEGIN 3 */
}
Or simply toggle the LED in one of the created tasks and remove it from the while loop in main(). In your case: StartDefaultTask():
.
.
.
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* 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 */
}
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const * argument)
{
/* init code for USB_HOST */
MX_USB_HOST_Init();
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
osDelay(500);
}
/* USER CODE END 5 */
}
Hope it does answer your question.
2024-05-09 07:31 AM
Hello SofLit,
Yes, your suggestion work. I am a newbie.
I just compile the generated code but do not know it includes FreeRTOS .
Thanks!