LED blinks only in debug mode
Hi!
I have a basic code - blinking LED code which uses onboard LED (PC13). The problem is that it doesn't toggle at all, it just stay switched on and doesn't go off after delay. I've tested that code in debug mode and everything worked fine, it toggled, but it doesn't work out of debug. I can't get why it works only during debugging and how to fix that.
Board - STM32F103C8T6
Utility is STM32 ST-LINK Utility v4.4.0
Driver is STSW-LINK009
Programmer st-link v2
Code:
------------------------------------------------------------------------------------------
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
GPIO_InitTypeDef GPIO_InitStruct;
void delay(int a);
int main(void)
{
// Enable clock for GPIOC
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
// Configure PC13
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStruct);
while (1)
{
// Turn on LED on PC13
GPIO_ResetBits(GPIOC, GPIO_Pin_13);
delay(5000);
// Turn off LED on PC13
GPIO_SetBits(GPIOC, GPIO_Pin_13);
delay(5000);
}
}
void delay (int a)
{
volatile int i,j;
for (i=0 ; i < a ; i++)
{
j++;
}
return;
}
----------------------------------------------------------------------------------------------------
Waiting for your advice a lot ;)
