cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get LED to toggle with STM32Cube

bluevault
Associate II
Posted on March 28, 2014 at 00:34

Hello,

I'm evaluating STM32cube, to see how it performs. I have a simple project in IAR which I created in STM32Cube for the F407 discovery kit. Enable PortD.12 and D/13 as outputs. However when I insert the toggle code in main(), I'm unable to see the LED toggle on D.13 Any help is appreciated. Thanks!

int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13 );
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13 );
/* Code generated for FreeRTOS */
/* Create Start thread */
osThreadDef(USER_Thread, StartThread, osPriorityNormal, 0, 2 * configMINIMAL_STACK_SIZE);
osThreadCreate (osThread(USER_Thread), NULL);
/* Start scheduler */
osKernelStart(NULL, NULL);
/* We should never get here as control is now taken by the scheduler */
/* USER CODE BEGIN 3 */
/* Infinite loop */
while (1)
{
}
/* USER CODE END 3 */
}

5 REPLIES 5
stm32cube-t
Senior III
Posted on March 28, 2014 at 09:30

Check the tutorial in STM32CubeMX User Manual. It shows the configuration in MX UI and the code to add in the main function.

schauer
Associate II
Posted on March 28, 2014 at 11:11

If you toggle a pin two times without delay you won't be able to see the LED toggling with the eye. You might be able to see them with an oscilloscope, depending on the processor's speed.

A HAL_Delay(500) between the toggle commands should suffice to see the LED toggling if the pins are configured correctly.

Hope that helps you, BS

bluevault
Associate II
Posted on March 28, 2014 at 13:01

Thanks... I'm using break points though and stepping through the code.

schauer
Associate II
Posted on March 28, 2014 at 13:09

I've the same situation here, with all 4 LED's (PD12-15) configured on Port D and they are toggling just fine. Maybe the port configuration (MX_GPIO_Init) is wrong? Here's the configuration of the Port D on my uC:

GPIO_InitTypeDef GPIO_InitStruct;
__GPIOD_CLK_ENABLE();
/*Configure GPIO pins : PD12 PD13 PD14 PD15 */
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

bluevault
Associate II
Posted on March 28, 2014 at 13:12

Update: They were not configured as outputs.

Works now.

Thanks!