cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Blue pill doesn't execute code on power up, execution starts after i press reset

Mshar.2
Associate II

Hello,

I'm using stm32 blue pill and my code communicates with several sensor using UART and displays it on LCD using i2c. My code works perfectly fine on debug.

But when i power it again, it doesn't start execution. Although power LED is ON but code execution doesn't start. It only starts after i press reset button.

I read some other solutions saying changing capacitor next to reset button, or connecting BOOT0 to GND. but I'm not sure how to do it.

Can someone explain how can i do it through software.

Similar - https://community.st.com/s/question/0D50X0000ArSX5ISQW/why-my-mcu-doesnt-work-when-powerup-it-only-starts-code-if-i-do-a-reset

This discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

This relates to a so-called Blue Pill, which uses illegally cloned STM32F103. ST resources are only dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes products work properly with the firmware we provide.

We recommend to purchase genuine products from STMicroelectronics and purchase them from known and trusted distributors.

This thread will now be locked. However, if you face difficulties while using genuine ST products, we’re here to assist you. Please feel free to start a new thread, and our team, along with community members, will be ready to help you with any issues/questions you encounter.

Thank you for your understanding.

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.

View solution in original post

9 REPLIES 9
Mshar.2
Associate II

I can share a turn around until someone suggests a proper solution.

The root cause is that if the power doesn't rise as sharply, SystemClock_Config(); won't be able to initialize clocks and hence program won't run until reset manually.

So I gave a small delay before SystemClock_Config(); and now code executes automatically even when i connect to external power source.

0693W00000YAHUEQA5.png

Peter BENSCH
ST Employee

Regardless of the fact that fakes of the STM32F103 are usually equipped with so-called Blue Pill boards, the behaviour of which varies greatly depending on the counterfeiter: a loop like this

for(i=0;i<50000;i++){}

will normally disappear without a trace during optimisation because it does not perform any meaningful action. One used something like this as a time loop in the early years of MCUs, but this is very quickly recognised by the optimisation functions of the C compilers and rightly removed - if one does not deactivate or limit them.

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.
ONadr.1
Senior III

My experience is that this is usually caused by the crystal oscillator being slow to ramp up. The MCU then switches to the internal oscillator and the code ends up in an endless "ErrorCode" loop

Mshar.2
Associate II

Hello @ONadr.1​ 

Can you suggest some solution for it??

Mshar.2
Associate II

@Peter BENSCH​ 

Can i use HAL_Delay(100); over here? or will it be optimized too?

0693W00000YAOSZQA5.png 

Because I can't press reset button every time since MCU will be inside casing..

Peter BENSCH
ST Employee

Delay loops will not solve the problem, because as @ONadr.1​ also wrote, the issue is probably caused by unsuccessful start of the crystal initialisation. It might help to test other maximum times for the start of LSE and HSE in this routine.

However, it is impossible for STMicroelectronics to make statements about an STM32F103, which is almost certainly a fake (feel free to prove otherwise) and may well behave differently from an original part.

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.
ONadr.1
Senior III

You can try insert reset into ErrorHandler routine

void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
 HAL_NVIC_SystemReset(); //this can solve the problem, but not the root of problem
  /* USER CODE END Error_Handler_Debug */
}

worked for me thanks.

Peter BENSCH
ST Employee

This relates to a so-called Blue Pill, which uses illegally cloned STM32F103. ST resources are only dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes products work properly with the firmware we provide.

We recommend to purchase genuine products from STMicroelectronics and purchase them from known and trusted distributors.

This thread will now be locked. However, if you face difficulties while using genuine ST products, we’re here to assist you. Please feel free to start a new thread, and our team, along with community members, will be ready to help you with any issues/questions you encounter.

Thank you for your understanding.

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.