cancel
Showing results for 
Search instead for 
Did you mean: 

STM32wb55 HAL_Delay() Function

AKetc
Associate III

Hi everyone,

I have been stuck at a problem. I have been trying to configure HAL_Delay function to work in STM32 BLE_Server example in the STM32WB SDK. However, for some reason, the code gets stuck inside the HAL_Delay() Function. I have searched over the internet and tried the solution to increase Systick interrupt priority. Still there's no solution to my problem. Please help me out.

1 ACCEPTED SOLUTION

Accepted Solutions
Christophe Arnal
ST Employee

​Hello,

In all BLE Applications, the HAL_Delay() was not used so in order to save power ( avoiding the systick periodic interrupt timer), it was decided to disable the systick.

As long as the systick is not enabled, the HAL_Delay() cannot exit anymore.

In main.c, the two following weak functions have been overloaded with empty function

This prevents the HAL to enable the systick.

/**
 * This function is empty to avoid starting the SysTick Timer
 */
HAL_StatusTypeDef HAL_InitTick( uint32_t TickPriority )
{
	return (HAL_OK);
}
 
/**
 * This function is empty as the SysTick Timer is not used
 */
void HAL_Delay(__IO uint32_t Delay)
{
	return;
}

In order to get back the systick, you need to remove these two implementations from main.c

In the next release v1.3.0, the HAL_Delay() will be available by default as the lost of power consumption is marginal versus the fact it is a friendly service to be used in the appplication

Regards.

View solution in original post

20 REPLIES 20
T J
Lead

sometimes you have to manually start systick, not sure why.

can you use a break point ?

try to stop inside this function:

void SysTick_Handler(void)

this is my usual fix

I leave this note in my initialization code, so when I start a new project, I know where to find it...

   /* dont forget to add this line in

   void SysTick_Handler(void)

   {

    // USER CODE BEGIN SysTick_IRQn 0

   HAL_SYSTICK_Callback();   <--- this one is missing...

   */

AKetc
Associate III

Alright I'll try this solution. Thanks for the quick response.​

AKetc
Associate III

I used the debugger but it never went to any function such as Systick_Handler() . I don't know why. I haven't edited anything in the HAL_Delay() function.

AKetc
Associate III

If there's a way to create a delay with using HAL_Delay() Function, it would be great.

I studied the example and found that a certain function in app_ble.c file does the delay without using HAL_Delay().

The function used is HW_TS_Create(), I want to implement this function in p2p_server.c file but not able to do so.

Any help?

T J
Lead

On some boards for some reason the Systick is not enabled by the cube, not sure why, but I had to use this to get it started.

void enableSystick(void) {
    /*  dont forget to add this line in 
    void SysTick_Handler(void)
    {
     // USER CODE BEGIN SysTick_IRQn 0 
    HAL_SYSTICK_Callback();   <--- this one is missing... // my mS counter is running in that callback
    */
    
    //  HAL_RCC_MCOConfig(RCC_MCO, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_16);
    /**Configure the Systick interrupt time */
    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
    /**Configure the Systick */
    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
    /* SysTick_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
    
    
}

AKetc
Associate III

Alright thanks for the help. I shall update you after trying this solution.

AKetc
Associate III

Still not working. I don't think the problem lies with the Systick not enabled. This is because apart from BLE_p2pServer Example, the HAL_Delay() function works in all other examples. Could you determine the reason for this odd behavior now? What I interpreted from the debugger is that the code is getting stuck inside the function and at the point where the number of ticks increase. It keeps on increasing the ticks infinitely without coming out of loop.

T J
Lead

can you single step ?

You can always just set a timer yourself, set the interrupt on overflow, and "inc mS" as I do...

AKetc
Associate III

Well, I was able to implement a timer for my application using an already built function inside the BLE_p2pServer application. The function is HW_TS_INIT() , I am using that, however, I am not able to implement the desired delay. It only creates a very short time delay which is not sufficient for my application. Can you study that function inside the example and guide me? Thanks.