Skip to main content
alianvari
Associate III
October 5, 2019
Question

Hi.I am using stm32l496 but systick every 20s There is a difference of 20ms.I paste my code and clock config in stm32cube.

  • October 5, 2019
  • 3 replies
  • 996 views

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_MSI;

 RCC_OscInitStruct.LSIState = RCC_LSI_ON;

 RCC_OscInitStruct.MSIState = RCC_MSI_ON;

 RCC_OscInitStruct.MSICalibrationValue = 0;

 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_8;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 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_MSI;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV8;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

 {

  Error_Handler();

 }

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_LPTIM1;

 PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;

 PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSI;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure the main internal regulator output voltage 

 */

 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

 {

  Error_Handler();

 }

}

This topic has been closed for replies.

3 replies

S.Ma
Principal
October 5, 2019

What is the clock LSI tolerance spec in %?

What is the clock error of 20msec vs 20 sec?

Tesla DeLorean
Guru
October 5, 2019

The MSI is pretty sloppy. Things with timing criticality like CAN, USB or Ethernet need a crystal, and Radio a TCXO.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
alianvari
alianvariAuthor
Associate III
October 5, 2019

The micro prints a sentence once every 20 seconds,By comparing the printing time of the sentences I find that:

Time interval of 2 printed words of 20 seconds,It takes about 20 seconds and 20 milliseconds.