STM32duino SysTick

STM32G474RE


SysTick_Config

STM32G071RB


Twice initialization


Code

  • HAL_Init():
    SystemCoreClock = 16'000'000 Hz = 16 MHz
  • SystemClock_Config():
    SystemCoreClock = 64'000'000 Hz = 64 MHz
#ifndef F_CPU
  #define F_CPU SystemCoreClock
#endif
void hw_config_init(void)
{
  /* Initialize the HAL */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();
}
/* The SystemCoreClock variable is updated in three ways:
    1) by calling CMSIS function SystemCoreClockUpdate()
    2) by calling HAL API function HAL_RCC_GetHCLKFreq()
    3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
       Note: If you use this function to configure the system clock; then there
             is no need to call the 2 first functions listed above, since SystemCoreClock
             variable is updated automatically.
*/
uint32_t SystemCoreClock = 16000000UL;
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
{
  [...]

  /* Update the SystemCoreClock global variable */
  SystemCoreClock = (HAL_RCC_GetSysClockFreq() >> ((AHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos]) & 0x1FU));

  /* Configure the source of time base considering new system clocks settings*/
  return HAL_InitTick(uwTickPrio);
}
void noOsSystickHandler() { } // empty

void osSystickHandler() __attribute__((weak, alias("noOsSystickHandler")));
void SysTick_Handler(void)
{
  HAL_IncTick();
  HAL_SYSTICK_IRQHandler();
  osSystickHandler();
}

Leave a Reply

Your email address will not be published. Required fields are marked *