cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to toggle a LED with STM32F429I-Disco1

DJ_YANG
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

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.

View solution in original post

4 REPLIES 4
SofLit
ST Employee

Hello,

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

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.

Hello SofLit,

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

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.

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.

Hello SofLit,

Yes, your suggestion work. I am a newbie.

I just compile the generated code but do not know it includes FreeRTOS .

Thanks!