SysTick with STM32CubeMX

OK, so it appears that with projects generated through STM32CubeMX the place where to insert custom SysTick code is not within the HAL, but in one of the auto-generated “User” files, stm32f1xx_it.c. This file contains the definition of active IRQ handlers.

Here’s what the SysTick handler looks like once I modified it:

* @brief This function handles System tick timer.
void SysTick_Handler(void)
  /* USER CODE BEGIN SysTick_IRQn 0 */
  static uint32_t led_timer;
  /* USER CODE END SysTick_IRQn 0 */


  /* USER CODE BEGIN SysTick_IRQn 1 */
  if (++led_timer >= 500) {
    led_timer = 0;
    /* Toggle LED state */
    HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
  /* USER CODE END SysTick_IRQn 1 */

Sadly, once again, the above code does not seem to have any effect for the board I am using despite most of the code and initialization is auto-generated by STM32CubeMX. The USB setup, however, works fine. Activating the USB CDC class implementation is proving to be far easier than flipping a LED with STM32CubeMX 😀

About Luigi Di Fraia

I am a Senior DevOps Engineer so I get to work with the latest technologies and open-source software. However, in my private time I enjoy retro-computing.
This entry was posted in Technical and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s