2019-07-22 09:09 AM
Hi Everyone,
We are using the following code to generate clock pulse for STM32F722 from an external 12MHz crystal. However, whatever we do it sounds the STM32F722 gets its clock pulse from an internal 16 MHz oscillator. The reason for using an external 12MHz crystal is because we want to increase the clock pulse frequency up to 120 MHz or higher. I need to mention that there is no hardware problem with the board that we are using. So any help or recommendation for solving this problem will be highly appreciated, thanks.
Here is the code that we are using for generating clock pulse from an external 12MHz crystal:
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 6;
RCC_OscInitStruct.PLL.PLLN = 140;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 3;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
2019-07-22 09:21 AM
Make sure you clear the RCC_OscInitStruct variable when defining it as a local/auto variable.
Is HAL_RCC_OscConfig() returning an error?
Inspect what the system says it is doing after calling the setup
printf("Core=%d\n", SystemCoreClock);
printf("APB1=%d\n", HAL_RCC_GetPCLK1Freq());
printf("APB2=%d\n", HAL_RCC_GetPCLK2Freq());
Make sure HSE_VALUE is correctly defined.
2019-07-22 11:01 AM
Thanks Clive. I really appreciate for your response with information.
Dan
2019-07-22 11:18 AM
Setting look like they will give you 70 MHz
2019-08-06 08:58 AM
Hi Clive,
We managed to increase the clock speed for STM32F722 using PLL. Now we are wondering how we can keep the baud rate of USART6 to 115200 bit/s (is there any function/capability in STM32F722 that automatically adjusts the USART clock divider and set the baud rate after changing the Micro's clock speed?)
Your quick response is highly appreciated.
Thanks,
Dan
2019-08-06 01:11 PM
Sending USART_Init() again should reconfigure it using current decomposition of clock settings.
https://community.st.com/s/question/0D50X0000BB1OvJSQV/setting-the-usart-baudrate
2019-08-06 02:37 PM
For I2C, but relevant
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = {0};
/*##-1- Enable the HSI clock #*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
/* Error */
Error_Handler();
}
/*##-2- Configure HSI as I2C clock source #*/
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
RCC_PeriphCLKInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
2019-08-06 03:12 PM
Somebody (probably @Tilen MAJERLE ) was too quick to close the other thread https://community.st.com/s/question/0D50X0000BB1OvJSQV/setting-the-usart-baudrate so I comment here: it's nice that USARTs have the option to choose a different clock in RCC of the 'F722, but IMO HSI is not a great option for USART, especially if the other party uses a similar unprecise RC clock, or if there are other external environmental influences (level conversion, long cables), and/or if the application is expected to be subject to wide operation temperature or supply voltage range and does not implement some form of fine-tuning HSI on the go (if such is possible in 'F722 at all).
OTOH, as Clive said, it's dead easy to adjust the baudrate - switch off UART, rewrite BRR, switch it on again. You may want to wait with the switch until transmitter is empty, otherwise transmitted byte gets garbled. Reception may be affected if characters are arriving while changing clocks, but upper-level protocols should take care of both these problems.
One more related option is autobauding, but I doubt you want to go that way.
JW