0
votes

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

  1. set pins for power, inputs and outputs discovery
  2. Turn on the rcc-> HSE bus
  3. In Clock Configuration, enabled HSE. Configured by manipulated as follows clock
  4. Added an endless loop changing it.
  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);
}
  1. Did I do everything right?
  2. Explain the reason why the LED may not light.
  3. The pins of the microcontroller have their own identifier. Where can I find leg information? Will this fit Discovery Device Description ?
  4. I used the English documentation offered by the author of the lesson, only the version for my controller. Description of STM32F3 HAL and low-layer drivers STM32F373xx

LED pin PC9, PC8

3
I added time and changed pins since I had an error on the LED goes PD9 and PD8Moohammad

3 Answers

0
votes

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.

1
votes

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);
}
0
votes

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.