cancel
Showing results for 
Search instead for 
Did you mean: 

What could cause System Timer not to run?

KMill
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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

TDK_0-1706294018848.png

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

12 REPLIES 12
TDK
Guru

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".
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.
KMill
Associate III

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.

 

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

Thank you again,

Yes, I considered the boot0 pin - but it is also floating in the NUCLEO board

Screenshot 2024-01-26 at 16.00.39.png

Plus, the code does start and run. Just the system timer is not running.

I'm beginning to suspect faulty or damaged chips. They were assembled by a reputable PCB firm in China.
I'm very careful with ESD using an ESD mat on the workbench, and proper ESD wrist straps etc. 
I think I will transplant the STM32 from the nucleo board onto my board and see if the problem persists or goes away.

So I have 10 of these prototype boards, and so I pulled out a brand new one, programmed it with the project and it worked... kindof.

If I start the project with the dbugger attached using the RUN button then it works fine. All the timers and UART etc are doing there thing.

But if I disconnect the programmer and reboot - it hangs at the first call to HAL_Delay. So something is causing the system timer not to start. I cannot find out what it is. I've checked all the VSS and VDD pins, all are good, VDD is 3.3 V and nice and clean. Reset signal is present and correct. If I manually reset (by taking NRST pin to gnd,) I get the same symptoms. I tried adding __enable_irq() but it made no difference at all. The chip looks genuine.

 

Screenshot 2024-01-26 at 17.44.10.png

TDK
Guru

> 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
Associate III

>>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.

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
Up vote any posts that you find helpful, it shows what's working..