2024-09-17 07:31 AM
Hello,
I have an older project that I am trying to move forward.
The original design was done with the STM32F401(RE) using System Workbench.
The new design is planned to be using the STM32F446(RE) using STM32Cube IDE (v1.16).
I planned on using the internal 16 MHz clock through the PLL. I am using USB in this design and need a 48 MHz clock.
Here is the code that I was using with the STM32F401.
#if USE_INTERNAL_16MHZ
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 16;
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 busses 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; //OLED worked with this
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
#endif
With the STM32CubeIDE, I am tried to set up the clock in the same manner but it gives me an error.
Attached are two screenshots.
When I hover over the PLL Source Mux, the IDE shows PLL Mux should have HSE as input.
When I look at the reference manual for the 446 this looks like it should be valid.
Am I missing something?
The code still compiles. I have yet to load it on my hardware but will be doing that hopefully soon.
Thanks.
Solved! Go to Solution.
2024-09-17 07:50 AM
The accuracy requirements of USB require you to use a crystal or HSE bypass as a clock source. The internal HSI is not accurate enough. It might work, but CubeMX is correct to flag it as an error.
Other chips can use HSI for USB, but not the STM32F4.
2024-09-17 07:50 AM
The accuracy requirements of USB require you to use a crystal or HSE bypass as a clock source. The internal HSI is not accurate enough. It might work, but CubeMX is correct to flag it as an error.
Other chips can use HSI for USB, but not the STM32F4.
2024-09-17 07:53 AM
Hello,
Thanks for the fast response. I guess it is a good thing I designed the hardware so I could easily add an external crystal. I was hoping to just cut some cost if possible.
Thanks.