2023-02-08 07:42 AM
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.
2023-02-08 08:20 AM
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.
2023-02-08 02:09 PM
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
2023-02-08 09:50 PM
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
2023-02-09 02:41 AM
Hello @ONadr.1
Can you suggest some solution for it??
2023-02-09 09:57 AM
@Peter BENSCH
Can i use HAL_Delay(100); over here? or will it be optimized too?
Because I can't press reset button every time since MCU will be inside casing..
2023-02-10 12:19 AM
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
2023-02-10 03:48 AM
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 */
}
2024-04-18 03:37 AM
worked for me thanks.