cancel
Showing results for 
Search instead for 
Did you mean: 

Stop advertising due to SCH_SetTask()

Franklin
Associate II

Hello everyone,

I am working on a project on which i would like to send a notification from a board to another when the firts one crosses a threshold with the built-in comparator.

I started from the BLE_p2pServer and BLE_p2pClient examples from STM32Cube_FW_WB_V1.0.0 and modified them a bit to fit my needs. Everything was going well until I tried to send a BLE notification from the HAL_COMP_TriggerCallback() in the server.

I tried to send the notification with the functions in the server example and then wrote my own functions by drawing my inspiration from the ones in the server example but I had the same problem : the server stopped advertising.

I did some researches and found that SCH_SetTask() is responsible, when I comment its line, the server advertises.

Do you have any idea on how to solve this problem or just send a simple notification from the server to the client ?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Christophe Arnal
ST Employee

​Hello,

As long as the behavior changes when you comment out SCH_SetTask() from HAL_COMP_TriggerCallback(), I believe HAL_COMP_TriggerCallback() should be called.

There is one thing that would explain such behavior but in that case, I would expect the CPU to be in Hard Fault state.

I guess you  initialized the COMP early at startup ( likely in the main.c) and at the same time, you enabled the interrupt.

In that case, the problem is that the COMP interrupt handler is coming before the full initialization is done and especially before you call SCH_RegTask() to register the background function in the scheduler.

When the interrupt occurs, it will request the scheduler to run the associated background task but as it is not yet registered, it will jump to a NULL functions which should leads to a Hard Fault.

If this is correct, the best way to fix it is to enable the COMP interrupt only after you registered the function in the scheduler.

A quick way to check this, although not so nice, is to call the SCH_RegTask() from the interrupt handler where you called SCH_SetTask() ( it does not matter if this is before or after but makes more sense before). This is not a nice design but good enough to check if the issue is coming from this. It does not hurt calling several time SCH_RegTask().

Regards.

View solution in original post

6 REPLIES 6
Christophe Arnal
ST Employee

Hello,

SCH_SetTask()  as such does nothing except setting a flag so it cannot be responsible. There should be a function associated with the flag/signal you are setting with SCH_SetTask().

I believe in HAL_COMP_TriggerCallback(), you called SCH_SetTask() to run an asscociated function in the backgound.

There may be something wrong in that function that leads the advertising to stop.

Regards.

Franklin
Associate II

Hello,

Yes, I do call SCH_SetTask() in HAL_COMP_TriggerCallback().

I first tried with the functions provided i.e. SCH_SetTask() was supposed to call

void P2PS_Send_Notification(void)
{
 
  if(P2P_Server_App_Context.ButtonControl.ButtonStatus == 0x00){
    P2P_Server_App_Context.ButtonControl.ButtonStatus=0x01;
  } else {
    P2P_Server_App_Context.ButtonControl.ButtonStatus=0x00;
  }
 
   if(P2P_Server_App_Context.Notification_Status){ 
    APP_DBG_MSG("-- P2P APPLICATION SERVER  : INFORM CLIENT BUTTON 1 PUSHED \n ");
    APP_DBG_MSG(" \n\r");
    P2PS_STM_App_Update_Char(P2P_NOTIFY_CHAR_UUID, (uint8_t *)&P2P_Server_App_Context.ButtonControl);
   } else {
    APP_DBG_MSG("-- P2P APPLICATION SERVER : CAN'T INFORM CLIENT -  NOTIFICATION DISABLED\n "); 
   }
 
  return;
}

but it made the advertising stops. Then I tried with my own function

void P2PS_Send_COMP_Notification(void)
{
	P2PS_STM_App_Update_Char(P2P_NOTIFY_CHAR_UUID, (uint8_t *)&myVar);
	return;
}

but I had the same problem. I finally tried with a test function to see what was causing the advertising to stop

void test(void)
{
	return;
}

and again I had the same problem.

Any idea ?

Christophe Arnal
ST Employee

Hello,

Once you called the SCH_SetTask() from HAL_COMP_TriggerCallback(), did you checked test() is called ?

Could you please insert the code of HAL_COMP_TriggerCallback().

Regards.

Franklin
Associate II

Hello,

Yes I checked and it is not called. In fact, HAL_COMP_TriggerCallback() is not even called because the programme just "blocks". Instead of the LED2 blinking (according to the server example) which means it advertises, I have the LED2 on. After a while, the client who is supposed to connect to the server and have its LED2 blinking also, has its LED2 on and I cannot do anything. The switch button does not work anymore and the comparator neither.

Here is the function you asked for :

void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
{
  BSP_LED_Toggle(LED3);
  BSP_LED_Toggle(LED1);
  APP_BLE_COMP_Action();
  return;
}

and the others you may want to see :

void APP_BLE_COMP_Action(void)
{
	P2PS_APP_COMP_Action();
}
void P2PS_APP_COMP_Action(void)
{
	SCH_SetTask(1 << CFG_TASK_COMP_TRIGGER_ID, CFG_SCH_PRIO_0);
}

I did added CFG_TASK_COMP_TRIGGER_ID in the app_conf.h and registered the function called by SCH_SetTask() with SCH_RegTask() in P2PS_APP_Init() in the p2p_server_app.c so I do not understand where does this issue comes from. Do you have an idea ?

Thank you.

Christophe Arnal
ST Employee

​Hello,

As long as the behavior changes when you comment out SCH_SetTask() from HAL_COMP_TriggerCallback(), I believe HAL_COMP_TriggerCallback() should be called.

There is one thing that would explain such behavior but in that case, I would expect the CPU to be in Hard Fault state.

I guess you  initialized the COMP early at startup ( likely in the main.c) and at the same time, you enabled the interrupt.

In that case, the problem is that the COMP interrupt handler is coming before the full initialization is done and especially before you call SCH_RegTask() to register the background function in the scheduler.

When the interrupt occurs, it will request the scheduler to run the associated background task but as it is not yet registered, it will jump to a NULL functions which should leads to a Hard Fault.

If this is correct, the best way to fix it is to enable the COMP interrupt only after you registered the function in the scheduler.

A quick way to check this, although not so nice, is to call the SCH_RegTask() from the interrupt handler where you called SCH_SetTask() ( it does not matter if this is before or after but makes more sense before). This is not a nice design but good enough to check if the issue is coming from this. It does not hurt calling several time SCH_RegTask().

Regards.

Franklin
Associate II

Hello,

I just checked and indeed it was the problem. I follow your insructions and now it works !

Thank you very much for your help !!