cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_IncTick() not being called...

Ricko
Senior III

Hi,

I am using a STM32WB5MMGH6 BLE module and for some reason HAL_IncTick() is not being called. It is baffling because it was working perfectly well when I was recently working on it before switching to another project for a week.

I stripped the project down to almost nothing and placed a HAL_Delay() right after the CubeMX-generated initialization code in main(). So no custom code could do anything to affect that behavior (like turning off interrupts etc). However, the delay never completes.

The code is stuck inside the while loop in HAL_Delay() because HAL_IncTick() is never being called (i.e. the system tick is not incrementing) so the HAL_GetTick() always returns 0.

 

__weak void HAL_Delay(uint32_t Delay)
{
  uint32_t tickstart = HAL_GetTick();
  uint32_t wait = Delay;

  /* Add a freq to guarantee minimum wait */
  if (wait < HAL_MAX_DELAY)
  {
    wait += (uint32_t)(uwTickFreq);
  }

  while ((HAL_GetTick() - tickstart) < wait)
  {
  }
}

 

The Timebase Source is set to SysTick and see that SysTick->VAL register keeps changing, so I assume it is actually running.

 

I thought perhaps:

- the interrupt is not triggered

- or something incorrect in the clock configuration tab in CubeMX

But in CubeMX - in the three screenshots below - all the settings seem correct. So perhaps there are other settings I should look at, but if so I have no idea which ones and where?

I also attached the .ioc file if someone could kindly have a look is you spot any wrong setting?

 

image.png

image.pngimage.png

 

It also does not seem related to some other code disabling interrupts because before then the only code is the one generated by CubeMX. You can see here for confirmation.

 

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* 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();

  /* Configure the peripherals common clocks */
  PeriphCommonClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
  MX_LPUART1_UART_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */

    HAL_GPIO_WritePin(PSU_CE_GPIO_Port, PSU_CE_Pin, GPIO_PIN_RESET);
    HAL_Delay(200);
    HAL_GPIO_WritePin(LED_DRV_EN_GPIO_Port, LED_DRV_EN_Pin, GPIO_PIN_SET);

 

Any gelp would be very much appreciated. Many thanks as always. :smiling_face_with_smiling_eyes:

Rick

 

1 REPLY 1
Saket_Om
ST Employee

Hello @Ricko 

Did you try enabling global IRQs in the code (e.g. using __enable_irq();)?

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