cancel
Showing results for 
Search instead for 
Did you mean: 

Program is uploaded but MCU doesn't run correctly

trung1
Visitor

Hi, I'm getting started at embedded programming, I've got this blue pill board having the STM32F103C6 MCU and ST-LINK v2 programmer.

Here's my code, just to light up the LED on port C 13:

#include "stm32f10x.h"
 
int main() {
RCC->APB2ENR |= (1<<4);
 
GPIOC->CRH |= ((1<<20) | (1<<21));
 
GPIOC->CRH &= ~((1<<22) | (1<<21));
 
GPIOC->BSRR = (1<<13);
 
return 0;
}

 

Despite the IDE flashes successfully the LED doesn't light up as I wanted, It will only lights up if I add a break point on debugging mode on Keil uVision

trung1_0-1757031227071.pngtrung1_4-1757031406660.jpegtrung1_5-1757031413287.jpeg

And here are my flash configurations:

trung1_6-1757031487180.pngtrung1_7-1757031507356.png

Any help is appreciated.

4 REPLIES 4
Pavel A.
Super User

Replace return 0; with while(1){}

 

It didn't work

Try to comment out GPIOC->BSRR = (1<<13);

 

Rodo
Senior

It looks like your coding in assembly language? You don't have any comments on the lines of code for what they each do. But if the LED works in step mode in debugging then your program is probably ok but when you run it it runs too fast for human eyes to see it. It only blinks once and then your program ends. If you want to see a constant blinking you need to slow down the blinking like: LED on, delay, LED off.  Also, put the code in a forever loop if you want it to blink ... forever instead of just once.