This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Turn On a LED on STM32F4-discovery

Hi everyone,

I want to turn on a LED on my STM32F4-discovery board

Here is the code :

int main()
{

// Enable the GPIO Clock

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

// GPIO Configuration

GPIO_InitTypeDef GPIO_InitStruct;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14; // Led 6 Blue selected

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; // Mod out !

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // 50 MHZ clock frequency

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // Push pull mod

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // Pull up

GPIO_Init(GPIOD, &GPIO_InitStruct);

// Turn on the LED

GPIO_SetBits(GPIOD, GPIO_Pin_14);

return 0;
}

I'm using uvision 5.13.0.0

It compiles and flash succesfully but nothing happen after. I don't know what is wrong with this. I also tried with this :

STM_EVAL_LEDInit(LED6);
STM_EVAL_LEDOn(LED6);

but there is no worked.

Can you help me ?
Many thanks :)

Parents
  • I think there is also some code before main in the start up file that will be performed
    to set up the clocks. That is why I suggested that you use system viewer to look at the RCC.

    Can you right click on the project so you can get to project options and the debug tab.
    and the Unclick the run to main checkbox. then run debug. choose to single step into the code.

    What function does the debugger go to. Does it go into a function probably called system_init.
    This is where it would initialize the clock stuff. this code is before the main function in another file that is assembly code.

    also can you find a function to clear the led.

    Hope this helps

Reply
  • I think there is also some code before main in the start up file that will be performed
    to set up the clocks. That is why I suggested that you use system viewer to look at the RCC.

    Can you right click on the project so you can get to project options and the debug tab.
    and the Unclick the run to main checkbox. then run debug. choose to single step into the code.

    What function does the debugger go to. Does it go into a function probably called system_init.
    This is where it would initialize the clock stuff. this code is before the main function in another file that is assembly code.

    also can you find a function to clear the led.

    Hope this helps

Children
  • I launched a debug session with your advises and it runs until System init function like you said.

    175:                  LDR     R0, =SystemInit
    0x0800020C 4809      LDR           r0,[pc,#36]  ; @0x08000234
    

    .

    Then there is this code but i can't find a function to clear the LED :

      LDR     R0, =SystemInit
                     BLX     R0
                     LDR     R0, =__main
                     BX      R0
                     ENDP
    
    

    Then with the system viewer i checked some registers. In RCC, i checked AHB1ENR and nothing is activated. In GPIOD, i checked BSRR register and nothing is activated too. It seems that clocks are not well initialized. Do you know what i must change to correct it ?

    Many thanks !

  • One more thing that came to mind. Make sure you have the debug selected and not simulation. I think simulation might be the default mode. You should find the check box in the same place you unchecked run to main.

  • do some more single stepping and verify that the clock registers are really being written to.