cancel
Showing results for 
Search instead for 
Did you mean: 

What could cause System Timer not to run?

KMill
Senior

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?

12 REPLIES 12

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

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

Oooh now that sounds like something I should check. I'll check that now...

@TDK You're a genuis - thank you. I used STM32CubeProgrammer to set the option bytes and the problem has gone away. 

Now if only there was a way to programme option bytes using the CuveIDE...