cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_GetTick() doesn't works in examples provided for BL072Z LoRa board

jg_spitfire
Senior

Hi, i am using the BL072Z board and in the ADC examples with interrupts the HAL_GetTick() function doesn't works, it returns 0 , also in the examples of LoRa like the called "end_node" happens the same, now i have built a project with cubemx and HAL_GetTick() works but not as it use to works with other boards like the stm32f411 , in that board i did not need to put the HAL_GetTick() inside the while loop (because is fired by an interrupt) but in the BL072Z LoRa board is necessary to put that function inside the loop, why?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Jairo,

It's pretty obtuse, but if you look in mlm32l0xx_hal_msp.c line 42 and line 53, you will see that HAL_InitTick() and HAL_Delay() is being overridden (as it is declared as __weak in the HAL library):

HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
   /* Return function status */
  return HAL_OK;
}
 
/**
  * @brief This function provides delay (in ms)
  * @param Delay: specifies the delay time length, in milliseconds.
  * @retval None
  */
void HAL_Delay(__IO uint32_t Delay)
{
  HW_RTC_DelayMs( Delay ); /* based on RTC */
}

The LoraWAN code base is different. It tries to keep the STM32 in STOP mode most of the time, wake up to do something and then go back to STOP mode. The RTC alarm interrupt is used to wake up the STM32. There is a timeServer.h & timeServer.c that allows you to create timer objects to wake up the STM32. It uses a linked list of objects, so be careful how you use it, or you could break the list and your timers will stop working.

Hope that helps!

Pieter

View solution in original post

7 REPLIES 7

The LRWAN software uses a different model, where the RTC provides the timebase, not SysTick.

If you use SysTick and the HAL Tick in interrupts and callbacks, it must have higher priority or dead-locks will occur.

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

How do you know that?, and then do you recommend me to forget the systick and use the rtc?,if you got that info in a document or video please share it, thanks ​

Hi Jairo,

It's pretty obtuse, but if you look in mlm32l0xx_hal_msp.c line 42 and line 53, you will see that HAL_InitTick() and HAL_Delay() is being overridden (as it is declared as __weak in the HAL library):

HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
   /* Return function status */
  return HAL_OK;
}
 
/**
  * @brief This function provides delay (in ms)
  * @param Delay: specifies the delay time length, in milliseconds.
  * @retval None
  */
void HAL_Delay(__IO uint32_t Delay)
{
  HW_RTC_DelayMs( Delay ); /* based on RTC */
}

The LoraWAN code base is different. It tries to keep the STM32 in STOP mode most of the time, wake up to do something and then go back to STOP mode. The RTC alarm interrupt is used to wake up the STM32. There is a timeServer.h & timeServer.c that allows you to create timer objects to wake up the STM32. It uses a linked list of objects, so be careful how you use it, or you could break the list and your timers will stop working.

Hope that helps!

Pieter

Hi Pieter, thanks, now i understand

SBour.9
Associate II

Some of the HAL driver are using the HAL_GetTick( ) functiun ( such as HAL_UART for timeout ) so to not be stuck in an infinte loop i redifined HAL_GetTick() in mlm32l0xx_hal_msp.c:

uint32_t HAL_GetTick(void){
  return HW_RTC_Tick2ms(HW_RTC_GetTimerValue());
}

I don't know if this patch is good or not but it seems to work fine at least, for the UART driver.

RPalm.1189
Associate

It works for me, thanks.

It works for me, thanks.