I'm using CoIDE and the CMSIS library. The problem is that my programs start up normally only immediately after flashing the board. By disconnecting and reconnecting the board to the usb( just for powering on), the program doesn't start anymore. By adding a delay instruction (for loop) in the beginning of the main function, the board works perfectly and programs run normally.

How do I get my program running correctly?

Here is my code :

#include "stm32f4xx.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"

int main(void)
    for (int i=0;i<0;i++); 
    GPIO_InitTypeDef GPIO_InitStr;



The Led doesn't light up without :

for (int i=0;i<0;i++); 

I was thinking that it was a matter of Time ! : "Something" needs more time to start or so ! :D But when i reduced the counter till zero, that was okk too .. the led turned on :D !

  • \$\begingroup\$ Power On Reset too short? or power on glitches too long? \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Mar 5 '18 at 21:27
  • 1
    \$\begingroup\$ Show your code. \$\endgroup\$ – Eugene Sh. Mar 5 '18 at 21:29
  • \$\begingroup\$ Are you using a dev board with a built in JTAG or the JTAG through USB \$\endgroup\$ – Voltage Spike Mar 5 '18 at 21:53
  • \$\begingroup\$ @Tony: i don't really get your idea.. How can i check or modify theses parameters?! \$\endgroup\$ – KwFx Mar 6 '18 at 0:28
  • \$\begingroup\$ @Eugene Sh: a simple blink Led code without any special configuration.. Just i have to add a delay instruction to make the program run normally (for example a for loop: for (int i=0;i<500000;i++);). \$\endgroup\$ – KwFx Mar 6 '18 at 0:35

I don't know how and why :D but the problem was solved by simply declaring the "GPIO Init Structure" outside the main function.

GPIO_InitTypeDef GPIO_InitStr;
int void main(){...}
  • \$\begingroup\$ No. This is not the solution. Something else changed which actually solved the problem, either in the code or in your experimental conditions. \$\endgroup\$ – Chris Stratton Sep 19 '18 at 14:48
  • \$\begingroup\$ Maybe :D ! forget it ;) \$\endgroup\$ – KwFx Sep 20 '18 at 13:27
  • 2
    \$\begingroup\$ Your struct was not zeroed. And had rubbish in fields you did not explicitly initialize. Moving it outside main moved it from the stack to BSS which is zero initialized. Try adding ={} when it's declared in main. \$\endgroup\$ – Jan Dorniak Nov 24 '18 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.