cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with advertising when using HAL_Delay in main funcion.

Kolab
Senior

Hello! I am trying to control a set of leds through bluetooth. In the main function ,after the main task I call the function that manage the leds and into this function there is HAL_Delay that has to receive its argument from bluetooth. The problem starts when I try to find the board using ST BLE Sensor app :

1) It takes a remarkable time to appear on the devices' list. When I connect successfuly to board then appear the second issue:

2) when I send the data (write characteristic) it also delays. How could I solve these delays?

22 REPLIES 22
Remi QUINTIN
ST Employee

My wording may be no clear. As there is no operating system running on the STM32WB (it is a basic bare metal implementation), the only way to interrupt a code execution is an interrupt.

The sequencer (a big while loop) was introduced to cope with this lack of real time OS. You can use the wait_event functionality to let some execution time to another task while waiting for an event.

Now you can understand that the complete BLE event process is not performed only under interrupt. One part is done in a task registered to the sequencer with a certain priority level.

Kolab
Senior

Thanks very much for the datailed answer. I'm going to try the wait_event functionality.

Kolab
Senior

hello! @Remi QUINTIN​  I tried to use UTIL_SEQ_WaitEvt to let a time for my task and wait for the event (reception of bluetooth data) but when UTIL_SEQ_WaitEvt is set the system enters the low power mode, that is, my cicle just gets stuck. I am doing something wrong?

And could you please explain a bit more about raising the priority of the background task?

Remi QUINTIN
ST Employee

Did you get the interrupt?​

Remi QUINTIN
ST Employee

​Entering the low power should not prevent the reception of any interrupt or event.

There should be something wrong with the UTIL_SEQ_WaitEvt .

Could you explain/expose the part of code you modified?

Kolab
Senior

here is the loop

0693W000003PnAbQAK.png

and here the recepetion of the data

0693W000003PnBAQA0.png

Remi QUINTIN
ST Employee

​It looks good!

You can play with the priority of the task using the UTIL_SEQ_SetTask( UTIL_SEQ_bm_t TaskId_bm , uint32_t Task_Prio ) function.

But in the end, the sequencer is a loop. So all tasks should be executed.

In our examples, all our tasks have the same priority.

Kolab
Senior

That is, I can put my function (Effect_1) in a task with a low priority and call it in an infinite loop(i.e. in main) ? Then BLE event will stay in a higher priority?

Kolab
Senior

the low power mode didn't stop the reception of the event concretelly, but has stopped the loop, that is, when the program enters in the loop it gets stuck in the wait function while there is no event . And at this moment the loop doesn't go forward as it should go. I would like so as to while the system waits for the event the loop runnned.

Remi QUINTIN
ST Employee

​Please find a basic presentation of the sequenceur. the last 2 pages could be a way to do what you want.

You have to overload the UTIL_SEQ_EvtIdle() function (have a look at the BLE examples)

void UTIL_SEQ_EvtIdle( UTIL_SEQ_bm_t task_id_bm, UTIL_SEQ_bm_t evt_waited_bm )

{

  UTIL_SEQ_Run( UTIL_SEQ_DEFAULT );

}

 This enables all tasks to run (even re-entering in the current task)

The implementation by default is

__WEAK void UTIL_SEQ_EvtIdle( UTIL_SEQ_bm_t TaskId_bm, UTIL_SEQ_bm_t EvtWaited_bm )

{

 UTIL_SEQ_Run(~TaskId_bm);

 return;

}

This allows all tasks to run except the current one.