Reputation: 13
I have a problem lighting the LED in the microcontroller device discovery stm32f373
I used STM32 cube mx and the HAL library the program was executed, but the LED did not light up. Performed work according to STM instruction. Lesson 4. HAL library. STM32 CUBE MX. LEDs and button link russian
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(5000); //1 minut
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_8);
HAL_Delay(5000);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_8);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_9);
HAL_Delay(5000);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_9);
}
LED pin PC9, PC8
Upvotes: 0
Views: 1132
Reputation: 2335
Have you configured the GPIO as outputs in STM32CubeMX?
Is interrupts enabled? If not, you will notice when debugging that HAL_Delay never returns. Try to place a couple of breakpoints and see if your while-loop actually executes.
Upvotes: 0
Reputation: 3524
You need to enable the clock for the GPIO peripheral which the LED is connected to, before you set up pins as outputs and try to toggle them.
In the RCC->AHBENR
there are bits to turn individual GPIO ports clocks on and off, GPIOD is bit 20, so RCC->AHBENR |= (1 << 20);
would do. There will be defines existing depending on which librarys you're using, so use those instead of the (1 << 20)
magic number.
EDIT After your edit, you've added at the bottom that the LEDs are pins PC8 & PC9, your code is toggling PD8 and PD9. Check which way it should be.
Upvotes: 0
Reputation: 1891
You need a second delay with HAL_Delay
. Otherwise you toggle the LED, jump to the begin of the while
and toggle the LED again. So it might be that the LED is switched on for only a few clock cycles depending on the initial state of the I/O.
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(500);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_8);
HAL_Delay(500);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_8);
}
Upvotes: 1