2019-07-27 08:50 AM
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.
Solved! Go to Solution.
2019-08-05 05:25 AM
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.
2019-07-27 01:33 PM
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...
*/
2019-07-28 03:06 AM
Alright I'll try this solution. Thanks for the quick response.
2019-07-28 08:40 AM
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.
2019-07-28 08:49 AM
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?
2019-07-29 12:53 AM
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);
}
2019-07-30 10:35 AM
Alright thanks for the help. I shall update you after trying this solution.
2019-07-31 08:16 AM
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.
2019-07-31 01:39 PM
can you single step ?
You can always just set a timer yourself, set the interrupt on overflow, and "inc mS" as I do...
2019-08-01 09:03 PM
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.