cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to run STM32F401 at 84 MHz Sysclk (works fine at 48 MHz)

Robin7331
Associate II

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:

0693W000008yrF6QAI.png

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:

0693W000008yrFzQAI.pngAnd this is my RCC configuration:

0693W000008yrHCQAY.png

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.

0693W000008yrOSQAY.png 

I have no idea what is going on here 🤷�?♂�?

Thanks for your help!

Cheers,

Robin

21 REPLIES 21

https://2.bp.blogspot.com/-Q5FtnBZkFdM/Wsd250LFFkI/AAAAAAAAIzw/kx2-Ud3FJQMoFWB_dOHgB80Hht8W4RgzQCLcBGAs/s1600/black+pill+schematic.jpg

Take off that unnecessary R3 pull-up from NRST line and it will start normally. I suppose the R2 10M parallel to HSE crystal Y1 actually was an attempt to fix the "sometimes not starting" issue. If the designers would read the manuals, they wouldn't put that R3 there and there wouldn't be such an issue in the first place.

I'm going to cross post this here, so I can find it later, and other fellow travellers can add it to the checklist..

https://community.st.com/s/question/0D53W00000evOqtSAE/outofspec-temperature-behavior-of-stm32f412-hard-fault-

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..