Skip to main content
Explorer
May 8, 2024
Solved

Failed to toggle a LED with STM32F429I-Disco1

  • May 8, 2024
  • 1 reply
  • 1390 views

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.

    This topic has been closed for replies.
    Best answer by mƎALLEm

    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.

    1 reply

    Technical Moderator
    May 9, 2024

    Hello,

    Your issue is not clear. Could you please attach your project so we can have a look/test it?

    DJ_YANGAuthor
    Explorer
    May 9, 2024

    Hello SofLit,

    Following is project. Actually, I just write "HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);" and "HAL_Delay(500);". Thanks.

    mƎALLEmAnswer
    Technical Moderator
    May 9, 2024

    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.