cancel
Showing results for 
Search instead for 
Did you mean: 

HAL tick not working with FreeRTOS for STM32H7

CTapp.1
Senior III

I have an STM32H7 project (created by TouchGFX) that uses FreeRTOS.

FreeRTOS uses the systick, so the HAL uses TIM2 for it's timebase.

However, HAL_IncTick is never called, so calls to HAL_Delay never return.

HAL_InitTick() is being called during startup and this results in TIM2 counting and its update interrupt flag being set. However, the interrupt handler never gets called.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)
9 REPLIES 9
SAID_embadded
Associate II

i have problem a little bit similar to yours but iam using AZURE RTOS i just start with blink an LED task it blink at the first time so the problem hapen in tx_thread_sleep it didnt work still SUSPENDED by system timer 

TDK
Super User

TIM2 needs to be running and configured, TIM2 interrupt needs to exist, be enabled, and be higher (numerically lower) than the thread you're calling HAL_GetTick from. One of those isn't happening.

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

Add a HAL_Delay(2) call  in your main() before creating any RTOS thingy and starting the scheduler.

If this call won't return as expected - the TIM interrupt does not work. Check why. Especially check that the  vectors table pointer is set correctly and the TIM interrupt priority is very high (numerically small or equal to 0).

If this little test passed, but the interrupt fails to tick later after the scheduler started: again check the TIM interrupt priority vs the RTOS synchronization priority. The TIM handler does not touch any RTOS service so the prio should be very high. Or (much worse) suspect memory or stack corruption.

 

 

CTapp.1
Senior III

Thanks All,

The timer is running - I can see it counting if I set a breakpoint in HAL_Delay().

The call to HAL_Delay() that 'gets stuck' takes place before the RTOS is started:

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */
/* USER CODE BEGIN Boot_Mode_Sequence_0 */

/* USER CODE END Boot_Mode_Sequence_0 */

  /* Enable the CPU Cache */

  /* Enable I-Cache---------------------------------------------------------*/
  SCB_EnableICache();

/* USER CODE BEGIN Boot_Mode_Sequence_1 */
  //SCB_EnableDCache();

/* USER CODE END Boot_Mode_Sequence_1 */
  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();  // This calls HAL_InitTick(), which configures and starts TIM2

  /* USER CODE BEGIN Init */
  //uwTickPrio = 4;
  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* Configure the peripherals common clocks */
  PeriphCommonClock_Config();
/* USER CODE BEGIN Boot_Mode_Sequence_2 */

/* USER CODE END Boot_Mode_Sequence_2 */

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_MDMA_Init();
  MX_LTDC_Init();
  MX_USART1_UART_Init();
  MX_I2C4_Init();
  MX_DAC1_Init();
  MX_DMA2D_Init();
  MX_SPI1_Init();
  MX_TIM1_Init();
  MX_TIM5_Init();
  MX_UART4_Init();
  MX_UART8_Init();
  MX_CRC_Init();
  MX_I2C2_Init();
  MX_LPTIM2_Init();
  MX_SPI2_Init();
  MX_TIM15_Init();
  MX_DSIHOST_DSI_Init();  // First call to HAL_Delay() is in here
  // More init calls, followed by calls to start FreeRTOS.

 If I set a breakpoint in HAL_Delay() and force it to return then the code executes as expected (so the only issue is HAL_IncTick() not being called.

The template configures the TIM2 interrupt to run at priority 15 (which is ok, as it's only really used to generate some non-critical delays within the HAL). I have tried rebuilding with it set to 0, but that made no difference.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)
CTapp.1
Senior III

Strange. I've made no changes, but the delays have now started working.

I'm wondering if this is related.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)
CTapp.1
Senior III

How do I get the "Accepted solution" removed from this thread?

The problem still exists - my "Thanks All" message was simply reporting that the timer was running, not that the interrupt was being called. 

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)

@CTapp.1 wrote:

How do I get the "Accepted solution" removed from this thread?


Instructions here.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

For important stuff: don't use HAL :D

And a simple "SysTick simulation" / basic system timer is set up quite easily without HAL, even in H7.

I also recommend not using the HAL IRQ handler for such simple timer use, so much overhead to reset one register / bit.

CTapp.1
Senior III

This is a TouchGFX project created from a template, so I have to live with what it uses ;)

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)