2022-09-13 03:38 AM
Hello,
I use STM32F091VC the from 4 year without problem, I have used more than 20000 STM32F091VC.
Recently, I have several STM32F091VC who have a big problem of accuracy on the clock HSI. The error is about 30% ! For exemple, the STM32F091VC give about 7000 ms instead 10000 ms in real. The maximum error for the STM32F091VC should be 1%. I have try to change the value RCC_OscInitStruct.HSICalibrationValue but this resolve not the problem.
With the shortage components, I had to change supplier for the last order. Is possible that I have received an order with faulty STM32F091VC?
Can you help me please?
Here the configuration of the clock :
void SystemClock_Config(void)
{
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
RCC_OscInitStruct.HSI14CalibrationValue = 16;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
/* Initialization Error */
while(1);
}
/* Select PLL as system clock source and configure the HCLK and PCLK1 clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI ; RCC_SYSCLKSOURCE_HSI
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1)!= HAL_OK)
{
/* Initialization Error */
while(1);
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_I2C1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
2022-09-13 03:42 AM
> For exemple, the STM32F091VC give about 7000 ms instead 10000 ms in real.
What are these numbers?
Can you try with some very simple program, perhaps outputting HSI onto MCO pin, or setting a timer to PWM; and then read out and post content of relevant RCC, and if used, TIM registers?
JW
2022-09-13 05:17 AM
2022-09-13 05:38 AM
Hello @Arnaud,
As @Community member mentioned, the proper way to check the HSI frequency is to enable the MCO output and check the frequency in oscilloscope.
Even with a wrong calibration, HSI doesn't drift out of 30%.
Best Regards,
Gwénolé
2022-09-13 10:21 AM
In that program, you are using layers and layers of Cube. How do you know you haven't introduced some error there?
Try without Cube. If PA8 or PA9 is available, MCO is straighforward; you don't even need to write any code for it, you can simply enable it in debugger (you need to set PA8 or PA9 to AF and proper AFR[] in GPIO, though, but that's not that hard be done in debugger too).
JW
2022-09-14 12:59 AM
Hello,
Thanks for your feedback.
I am not sure to understand how do without Cube. I will try to learn this without cube.
By default, the clock is HSI at 8Mz whe the MCU is power on, so I could remove the code HAL_Init(); and SystemClock_Config(); (programme in attachment)
I have tried, I have the same problem. I have configure an output to see the timer, the toggle is set at 1000 ms, I can see that there is still a delay for about 30%. Please see the pictures below.
2022-09-14 01:16 AM
Hello @Arnaud,
If you want you can do it by CubeMX.
First create a new project in CubeMX. Then , in RCC tab under System Core, check the box "Master Clock Output" (to enable the MCO pin).
After that, go to Clock Configuration, on MCO source Mux, please select HSI source. You should see that PA8 configuring as RCC_MCO.
After generating the code, HSI will be available on PA8. You can display it on oscilloscope and measure the frequency.
Best Regards,
Gwénolé
2022-09-14 01:35 AM
In your code :
htim6.Init.Prescaler = (uint32_t)(SYSTEM_CLOCK_ALFANO / 10000) - 1; // (uint32_t)(SystemCoreClock / 10Khz) -
//permet davoir le timer avec une base de temps de 0.0001 seconde
This is not right: as SYSTEM_CLOCK_ALFANO is 8000000, you get 800Hz, not 1000Hz
As you get 1.38s instreed of 1.25s I thing your HSI is 7250000 Hz.
Bonne journée!
2022-09-14 02:19 AM
I have used the code given by STM, the example is the project below :
stm32cube_fw_f0_v160\STM32Cube_FW_F0_V1.6.0\Projects\STM32F091RC-Nucleo\Examples\TIM\TIM_TimeBase\MDK-ARM
Here the code given by STM, maybe somebody can confirm that this code is correct? :
int main(void)
{
/* STM32F0xx HAL library initialization:
- Configure the Flash prefetch
- Systick timer is configured by default as source of time base, but user
can eventually implement his proper time base source (a general purpose
timer for example or other time source), keeping in mind that Time base
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
handled in milliseconds basis.
- Low Level Initialization
*/
HAL_Init();
/* Configure LED2 */
BSP_LED_Init(LED2);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/*##-1- Configure the TIM peripheral #######################################*/
/* -----------------------------------------------------------------------
In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1),
since APB1 prescaler is equal to 1.
TIM2CLK = PCLK1
PCLK1 = HCLK
=> TIM2CLK = HCLK = SystemCoreClock
To get TIM2 counter clock at 10 KHz, the Prescaler is computed as following:
Prescaler = (TIM2CLK / TIM2 counter clock) - 1
Prescaler = (SystemCoreClock /10 KHz) - 1
Note:
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f0xx.c file.
Each time the core clock (HCLK) changes, user had to update SystemCoreClock
variable value. Otherwise, any configuration based on this variable will be incorrect.
This variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetSysClockFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
----------------------------------------------------------------------- */
/* Compute the prescaler value to have TIMx counter clock equal to 10000 Hz */
uwPrescalerValue = (uint32_t)(SystemCoreClock / 10000) - 1;
/* Set TIMx instance */
TimHandle.Instance = TIMx;
/* Initialize TIMx peripheral as follows:
+ Period = 10000 - 1
+ Prescaler = (SystemCoreClock/10000) - 1
+ ClockDivision = 0
+ Counter direction = Up
*/
TimHandle.Init.Period = 10000 - 1;
TimHandle.Init.Prescaler = uwPrescalerValue;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.RepetitionCounter = 0;
if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Start the TIM Base generation in interrupt mode ####################*/
/* Start Channel1 */
if (HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
while (1)
{
}
}
2022-09-14 02:27 AM