cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with generated code from STM32CubeMX (using HAL), SysTick_Handler is never called.

MBrox
Associate

Hi, I have a problem with a minimal project using STM32CubeMX (version 4.27), an STM32F407VG and generating code for MDK-ARM5 (Keil). I create a new project, configure UART3 on pins PD8 and PD9. I add a simple printout on the UART in the main loop (not in an interrupt) giving the HAL_GetTick() as an ascii string and the value stays at zero continously. Similarly, any calls to HAL_Delay etc. hangs the processor.

I've also tested to configure the RCC (HSE crystal) and clock settings (HSE 8mhz, using "resolve clock issues") in addition to the UART, but with the same results. Am I missing some other important configuration to be done in the CubeMX gui or should I add any user code to ensure that SysTick_Handler is called?

The only added code are as below, in the sections indicated by the USER CODE comments in Src/main.c.

/* USER CODE BEGIN 0 */ 
void uart_send (const char *str) {
    uint16_t size;
    for (size=0; str[size] != 0; size++);
    HAL_UART_Transmit(&huart3, (uint8_t *) str, size, HAL_MAX_DELAY);
}
 
void format_digit(char *str, uint8_t digits, uint32_t value){
    str[digits] = 0;
    for (; digits > 0; digits--)  {
        str[digits - 1] = '0' + (value % 10);
        value = value / 10;
    }
}
/* USER CODE END 0 */
 
  /* USER CODE BEGIN 1 */
    char str[256];
  /* USER CODE END 1 */
 
 
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      format_digit(str, 6, HAL_GetTick());
      uart_send(str);
      uart_send("\n\r");
  /* USER CODE END WHILE */
 

1 ACCEPTED SOLUTION

Accepted Solutions
MBrox
Associate

Thank you, I figured out that the problem was that I had re-located the code with an offset in the linker script due to a bootloader -- this shifted the placement of the IRQ table and I had to manually override the value of SCB->VTOR in the generated Src/system_stm32f4xx.c file.

View solution in original post

2 REPLIES 2

Review working code examples in the CubeF4 code trees.

The SysTick is usually configured in code within, or called by, HAL_Init()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MBrox
Associate

Thank you, I figured out that the problem was that I had re-located the code with an offset in the linker script due to a bootloader -- this shifted the placement of the IRQ table and I had to manually override the value of SCB->VTOR in the generated Src/system_stm32f4xx.c file.