# Stm32F4-Discovery starting problem

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)
{
/*SystemInit();
RCC_HSEConfig(RCC_HSE_ON);
while(!RCC_WaitForHSEStartUp());*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
for (int i=0;i<0;i++);
GPIO_InitTypeDef GPIO_InitStr;
GPIO_InitStr.GPIO_Pin=GPIO_Pin_13;
GPIO_InitStr.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStr.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_InitStr.GPIO_Speed=GPIO_Speed_2MHz;
GPIO_Init(GPIOD,&GPIO_InitStr);

GPIO_SetBits(GPIOD,GPIO_Pin_13);

}


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 !

• Power On Reset too short? or power on glitches too long? – Sunnyskyguy EE75 Mar 5 '18 at 21:27
• Show your code. – Eugene Sh. Mar 5 '18 at 21:29
• Are you using a dev board with a built in JTAG or the JTAG through USB – laptop2d Mar 5 '18 at 21:53
• @Tony: i don't really get your idea.. How can i check or modify theses parameters?! – KwFx Mar 6 '18 at 0:28
• @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++);). – KwFx Mar 6 '18 at 0:35

GPIO_InitTypeDef GPIO_InitStr;

• 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. – Jan Dorniak Nov 24 '18 at 20:43