2025-01-06 12:39 PM
Hello
I am testing new MCU's. I have a ST-Link V2 and using a STM32F401CCU6.
At the start I had a simple LED flasher application however after I could not run it I started stripping everything out.
This is when I saw that I can actually not even run an empty while loop.
I have a very basic Clock setup that is suppose to be 84MHz. HOWEVER I had several Clock setup functions before and all of them end the same way ending in the while() loop.
This is for me to learn how STM works under the hood so I am not using the HAL. Also this error will also shine some lite on other matters of the STM MCU.
Below I attached some pictures of the steps it takes while crashing.
void SystemInitTrial(void){
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
RCC->CR |= RCC_CR_HSITRIM_4;
RCC->CR |= RCC_CR_HSION;
while (!(RCC->CR & RCC_CR_HSIRDY));
RCC->PLLCFGR |= RCC_PLLCFGR_PLLM_3;
RCC->PLLCFGR |= RCC_PLLCFGR_PLLN_2 | RCC_PLLCFGR_PLLN_4 | RCC_PLLCFGR_PLLN_6;
RCC->PLLCFGR |= RCC_PLLCFGR_PLLQ_2;
RCC->CR |= RCC_CR_PLLON;
while (!(RCC->CR & RCC_CR_PLLRDY));
RCC->CFGR |= RCC_CFGR_PPRE1_0 | RCC_CFGR_PPRE1_1 | RCC_CFGR_PPRE1_2;
RCC->CFGR |= RCC_CFGR_PPRE2_0 | RCC_CFGR_PPRE2_1 | RCC_CFGR_PPRE2_2;
RCC->CFGR |= RCC_CFGR_SWS_1;
while (!(RCC->CFGR & RCC_CFGR_SWS_PLL));
return;
}
int main(void)
{
SystemInitTrial();
while(1) {}
}
In the last picture it starts at the RED arrow and STEPS all the way down to line 100 Blue arrow and then jumps back up to the RED arrow after which it crashes.
Thanks
2025-01-06 01:03 PM
Probably it's in an error handler, perhaps the hard fault handler.
84 MHz is going to require nonzero wait states before you switch to that clock.
2025-01-06 01:42 PM
Make sure your design has a viable 4.7uF capacitor at VCAP pin and you can measure 1.25V there.
Does it fail if you don't mess with the clocks/PLL? Part should be able to run via HSI
main() shouldn't return
2025-01-06 03:04 PM
@Tesla DeLorean This is another strange thing going on. All the registers have this Error message while I can still step through. If I use the HAL generated code it runs fine.
@TDK Sorry but I am not 100% sure what the flag is I have to watch to be ready?
2025-01-06 03:22 PM
Doing repeated RMW doesn't look to be optimally efficient.
ORing everything on presupposes that the content is zero, or initial state, so potential for failure when it isn't.
Error kind of implies the debugger's having a hard time accessing memory. These aren't my tools, I'm not using them like this.
You might want to look at the SPL, it was a lot cleaner than the HAL