cancel
Showing results for 
Search instead for 
Did you mean: 

BluePill: Program is uploaded but MCU doesn't run correctly

trung1
Associate

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.

14 REPLIES 14
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.

Peter BENSCH
ST Employee

@trung1 

The ST-LINK/V2 you use is a clone of a genuine ST product and the support from ST experts is very limited. To get the support you need, please contact the third party you purchased this product from.

The same applies to your board called Blue Pill, because for years now, it has not been equipped with original STM32F103, but only with clones which are not supported by STMicroelectronics.

For assurance of using authentic ST products, we recommend purchasing exclusively through our official distributors, which you can find listed here: ST Official Distributors.

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

PC13 needs to be LOW to illuminate the LED

...
  GPIOC->BSRR = (1<<(13+16)); // RESET PC13, as LED ON with LOW state
  while(1) {} // Infinite loop, so as not to exit 
  return 0;
}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Sorry for the late reply. I just started on the STM32 so I merely understand

 

RCC->APB2ENR |= (1<<4);
 
GPIOC->CRH |= ((1<<20) | (1<<21)); //Assigning output mode, max speed 50 MHz by writing 1 1 to the 21st 22nd bit of the register
 
GPIOC->CRH &= ~((1<<22) | (1<<21)); //Assigning general purpose output push-pull by writing 0 0 to the 23rd 24th bit of the register
 
as assigning pin function.
 
GPIOC->BSRR = (1<<13); //This line is the one that set the port C13 high
 
I tried wrapping this line inside a while loop or a for loop delay after the line, but neither of them works.
I just want to light up the LED.

I am coding in C C99 standard.

But I was trying to turn it on, it doesn't light up if I was not in Keil debugger mode and having the command paused at 

GPIOC->BSRR = (1<<13);