2021-04-07 02:39 AM
Hello guys :waving_hand:
I am having a STM32F401CDU6TR on a custom board and I am not able to run it at 84 MHz SYSCLK. The source is an external 8 MHz crystal with two 22pF caps as seen here:
I created the project in CubeMX as a Makefile project. I only use CubeMX for configuring the GPIOs as well as the clock. The actual code is written and flashed via VSCode. Works great so far.
Here is my current 84 MHz clock configuration in CubeMX:
And this is my RCC configuration:
When I flash this code I always end up in a HardFault_Handler before the SystemClock_Config(); function returns.
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
When I activate MCO1 I can measure the HSE and PLLCLK signals with the expected frequency.
When I set the SYSCLK to 48 MHz as seen here everything works as expected.
I have no idea what is going on here 🤷�?♂�?
Thanks for your help!
Cheers,
Robin
Solved! Go to Solution.
2021-04-07 05:50 AM
Mine's more of a tesseract than a cube..
2021-04-07 06:04 AM
Well here's another measurement. Looks a lot better I guess :)
Will test if the MCU boots in about an hour.
But thanks so far!
2021-04-07 06:51 AM
Did you check that at least something is working?
Debug it and ensure that the mcu is actually running.
2021-04-07 07:24 AM
Guys. It works! :party_popper:
The problem was that I took the wrong cap value for VCAP.
I took 2.2nF instead of 4.7uF.
Now, there is no problem anymore with having a SYSCLK of 84 MHz.
Thanks for the heads up @Community member
You made my day :waving_hand:
2021-04-07 07:47 AM
It's magic that it worked with only 2.2nF :D
2021-04-07 08:09 AM
Absolutely. But it had another problem as well. USB DFU was not working.
And sometimes BOOT0 = HIGH was not recognized and it would boot right into flash instead of using the integrated bootloader.
All those problems: vanished 🤩✌�?
And it makes sense when I think about it now. I am super glad that his fixed all those issues ;p
2021-04-07 08:15 AM
I've seen that problem in the 32F411 "black pills".
Apparently the crystal starting is too slow when cold.
And how to fix it? Put the finger on top of the mcu for a few seconds to warm it up, then connect, it works everytime!
It might be caused by a cheap chinese magic too.
2021-04-07 08:37 AM
Please at least pay attention, the top post indicates it runs at a lower speed.
And the problem was solved/addressed before you posted.
2021-04-07 11:31 AM
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
And here is another related bug - according to datasheet the voltage scale 2 must be used for frequencies above 60 MHz.
2021-04-07 11:33 AM
Your right. Thanks for that.
It initially was on scale 2 but as I was desperate so I tried many things.
Including a different voltage scale :grinning_face_with_sweat: