cancel
Showing results for 
Search instead for 
Did you mean: 

SysTick_Handler triggering before main initialization is complete

STuser2
Visitor

I am using custom STM32G4 board and generated code using the MCSDK 6.2.0. I am observing that the SysTick_Handler(void) function is called before the peripheral initializations, and it is leading to hardware fault.

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_ADC2_Init();
#ifdef DACENABLED
  MX_DAC1_Init();
#endif

  MX_CORDIC_Init();
  
  MX_OPAMP1_Init();
  MX_OPAMP2_Init();
  MX_OPAMP3_Init();
  MX_TIM1_Init();
  MX_TIM4_Init();
  MX_FDCAN1_Init();
  /* USER CODE BEGIN 2 */
  MX_MotorControl_Init();
  /* Initialize interrupts */
  MX_NVIC_Init();
  HAL_FDCAN_Start(&hfdcan1);
  system_ready = true;
#ifdef DACENABLED
  HAL_DAC_Start(&hdac1,DAC_CHANNEL_1);
#endif

  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
   while (1)
  {
    /* USER CODE END WHILE */
	  // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_12);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

But the Systick interrupt is enabled only in MX_MotorControl_Init(). Then why it is called sometime after the HAL_Init();

 

2 REPLIES 2
LCE
Principal II

"...is leading to hardware fault"

Do you mean that HardFaultHandler() is called ? 

I'm pretty sure that the SysTick is enabled in HAL_init(), because some SystemClock_Config() parts usually have timeouts using SysTick.

Debug-step through your code to find out what's exactly going wrong.

I could solve the problem because the pointer was not initialized, but the main question is 

MC_RunMotorControlTasks(); is called in void SysTick_Handler(void) which is expected to be called after the 

MX_MotorControl_Init();

but the sequence is not followed, that is the main issue. Is it ok to use some strategy to overcome this issue? which i have implemented using the variable 

 system_ready = true;