Skip to main content
KMill
Senior
January 26, 2024
Solved

What could cause System Timer not to run?

  • January 26, 2024
  • 12 replies
  • 4957 views

I'm developing a new project based on STM32G431RB using STM32CubeIDE 14.1.0 on macOS

I'm having touble where the program will hang at the first call of HAL_Delay() and digging deeper it's hanging because HAL_GetTick always returns 0

It looks like the SysTick timer is not running, or it's interrupt is not being called.

I do not have interrupts enabled on any other peripherals.

I have TIM1 configured as CH1_CH1N and that is working.

I have TIM2 configured in Encoder mode, and that is working too.

The only thing that is not working seems to be the System Timer.

What could I possibly have done to disable it?

My clock source is set to HSI

Here is my "main"

int main(void)
{
  /* USER CODE BEGIN 1 */
uint8_t msg[64];
uint32_t lastCount;


  /* 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_TIM2_Init();
  MX_USART2_UART_Init();
  MX_SPI1_Init();
  MX_TIM1_Init();

  /* USER CODE BEGIN 2 */
HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL);
HAL_Delay(100); /* <-- IT HANGS HERE !!! */
brake_set();

lastCount = TIM2->CNT;
sprintf((char*) msg, "Startup count: %ld\r\n", lastCount);
HAL_UART_Transmit(&huart2, msg, strlen((char*) msg), 500);

motor_spinup_test();

  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
while (1) {
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
}

  /* USER CODE END 3 */
}

It hangs where I've shown in the comment above at HAL_Delay(100)

Any ideas?

This topic has been closed for replies.
Best answer by TDK

The nucleo uses option bytes to boot into flash. Are yours set to do the same?

TDK_0-1706294018848.png

 

12 replies

TDK
January 26, 2024

HAL_InitTick is called at the end of HAL_Init. Step through, does it return HAL_OK? Is it using systick or some other timer?

Are interrupts enabled? They should be, but you can add __enable_irq(); to ensure.

"If you feel a post has answered your question, please click ""Accept as Solution""."
KMill
KMillAuthor
Senior
January 26, 2024

Thanks for your reply.

To test this I created an empty project based on Nucleo-G431RB board and ran it on a Nucleo board and it works perfectly. But when run on my own board the exact same project hangs on any call to HAL_Delay()

So something in my design is not letting the system timer run. Hmmm.

I've attached my schematic.

 

mƎALLEm
ST Technical Moderator
January 26, 2024

Check your BOOT pin. It's floating.

 

SofLit_0-1706284005974.png

Check the application note AN5093 Getting started with STM32G4 series hardware development boards / Figure 8 

 

 

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
mƎALLEm
ST Technical Moderator
January 26, 2024

Hello,

Try to isolate the systick function and remove all the stuff not related to it: ADC, SPI TIM etc .. Do you face the same issue?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
TDK
January 26, 2024

> But if I disconnect the programmer and reboot - it hangs at the first call to HAL_Delay.

How are you determining this exactly without a debugger attached?

Feels like a floating BOOT0 pin would explain the general behavior.

"If you feel a post has answered your question, please click ""Accept as Solution""."
KMill
KMillAuthor
Senior
January 26, 2024

>>How are you determining this exactly without a debugger attached?

I'm observing the output of PWM on TIM 1 CH1 using an oscilloscope.

>>Feels like a floating BOOT0 pin would explain the general behavior.

Yes maybe, but the NUCLEO boards do have this pin floating. Also, if BOOT0 was to blame, it would be booting from SRAM which would not run Main and I wouldn't see my PWM on the oscilloscpe.

However, to be sure I will tie the BOOT0 pin to GND and see what happens.

Tesla DeLorean
Guru
January 26, 2024

In most STM32 BOOT0 is it's own pin, here it shares functionality with PB8

Check that their aren't Option Byte settings to perform an equivalent function, ie boot into user flash by default.

Make sure that SystemInit() sets SCB->VTOR to your Vector Table address

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