I am working with a STM32F303 microcontroller with a Nucleo board and my code gets stuck in the SysTick_Handler
routine of the startup_stm32f303xe.s file. (My code is based on an example Nucleo project, but rebuilt from scratch for learning purposes).
This post suggests that I need to set the Systick Interrupt to higher priority, which I did and doesn't fix the problem. This post suggests that the Systick Exception occurs when the system timer reaches 0... but I don't think I am using the system timer in my code.
In debug view with some breakpoints, I can see that the code executes to the two GPIO_TogglePin functions, after which it goes into the exception handler.
How can I prevent the program from causing the Systick Exception?
Here is my code:
int main(void) {
HAL_Init();
SystemClock_Config();
LED2_GPIO_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = LED2_PIN;
HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_8;
HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
// Also tried HAL_InitTick(0);
while(1) {
HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_8);
// Project code
}
}
void SystemClock_Config(void) {
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
/* HSI Oscillator already ON after system reset, activate PLL with HSI as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
Error_Handler();
}
}