How do you really stop BLE advertising?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
EdHa_4455331
Level 5
Level 5
25 replies posted 25 sign-ins 10 replies posted

I'm running a PSOC6 system with BLE and RTOS. I am trying to get the BLE stack to stop advertising. It seemed like a simple call to Cy_BLE_GAPP_StopAdvertisement should do the trick:

        // Stop BLE advertising.

        Cy_BLE_GAPP_StopAdvertisement();

       

        cy_en_ble_adv_state_t advertisingState;

       

        while( Cy_BLE_GetAdvertisementState() != CY_BLE_ADV_STATE_STOPPED )

        {

          advertisingState = Cy_BLE_GetAdvertisementState();

          vTaskDelay(25);

        }

But... the system stays stuck in the CY_BLE_ADV_STATE_STOP_INITIATED state AND the BLE stack doesn't stop advertising, either. I drilled down into Cy_BLE_GAPP_StopAdvertisement() and found that it called Cy_BLE_GAPP_ExitDiscoveryMode(), which sounded like the function that should do the heavy lifting. But the only definition I could find for that function in my generated source code is shown below. And THAT function sure seems to be missing any active code.

So, have I just missed an option in the BLE component that I need to check? Do I have a bad version? Any help would be appreciated.

Ed H.

/******************************************************************************

* Function Name: Cy_BLE_GAPP_ExitDiscoveryMode

***************************************************************************//**

*

*  This function is used by the GAP Peripheral application to stop the advertisement.

*  This is a non-blocking function.

*

*  On stopping the advertisement, GAP Peripheral application receives

*  CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP event.

*

* \note

*  CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP event is generated for calling Cy_BLE_GAPP_EnterDiscoveryMode and

*  Cy_BLE_GAPP_ExitDiscoveryMode APIs. Application should keep track of which function

*  resulted in this event.

*

* \return

*  cy_en_ble_api_result_t : Return value indicates whether the function succeeded or

*  failed. Following are the possible error codes.

*

*   Errors codes                             | Description

*   ------------                             | -----------

*   CY_BLE_SUCCESS                           | On successful operation.

*   CY_BLE_ERROR_MEMORY_ALLOCATION_FAILED    | Memory allocation failed.

*   CY_BLE_ERROR_INSUFFICIENT_RESOURCES      | BLE Stack resources are unavailable.

*

******************************************************************************/

cy_en_ble_api_result_t Cy_BLE_GAPP_ExitDiscoveryMode

(

    void

);

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hi Ed,

And Creator 4.3 doesn't appear to provide any way to change the selected device after the project is created.

Actually, you can change the device in PSoC Creator after project is created. You can right click on the project--> Click on Device selector--> Select series --> Select the device. Please find the image below:

Can you please solve one mystery in the mean time? Where is the REAL definition of Cy_BLE_GAPP_ExitDiscoveryMode()? Even in the project that you just sent, the only definition I can find using a workspace wide search is the following from cy_ble_stack_gap_peripheral.h:

And this definition can't possibly be the version that actually causes the stack to exit discovery mode.

The PSoC BLE stack is not completely exposed to the customers. So you are not able to see the implementation of that particular API.

Does this call somehow get routed to the cm0 core?

This call is handled by the core in which the Controller is implemented. You can see the setting in the BLE configuration tab to select in which core the Host and Controller should run.

Please find the attached project with CYBLE-416045-02. Please check if this project is working for you. It will advertise the device name FindMeTarget for the first 10 seconds after programming and then it stops advertising.

Thanks

Ganesh

View solution in original post

0 Likes
5 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi,

When you call the API Cy_BLE_GAPP_StopAdvertisement(); the PSoC 6 BLE stops sending the advertisement packets in the air.

When you call the API Cy_BLE_GAPP_EnterDiscoveryMode(); the PSoC 6 BLE goes into the mode such that it responds to the scan request sent by the Central devices. So if you are seeing the Peripheral device even after you have stopped the advertisement the following things might be the reason:

1. Peripheral called Cy_BLE_GAPP_StartAdvertisement() API with custom advertising type and

2. Central performs active scan.

For more details please refer the Cy_BLE_GAPP_StartAdvertisement() API implementation in cy_ble_gap.c file.

Thanks

Ganesh

0 Likes

Yes, that is how it is SUPPOSED to work. In my system, the BLE stack does NOT stop advertising after a call to Cy_BLE_GAPP_StopAdvertisement(). And the probable reason is that the generated code for Cy_BLE_GAPP_ExitDiscoveryMode is bogus.

cy_en_ble_api_result_t Cy_BLE_GAPP_ExitDiscoveryMode

(

    void

);

0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

I undestood. Please tell us more about your Central device. Does it perform active scanning?

Can you test with CySmart Android/ioS application and check if you are seeing the advertisement even after calling the Cy_BLE_GAPP_StopAdvertisement().

Can you please attach a truncated version of your project for us to verify at our side?

You can also find the attached project which is the modified version of Find me code example. Here we used the

Cy_BLE_GAPP_StopAdvertisement() API to stop the advertisement after 10 seconds.

Thanks

Ganesh

0 Likes

My central device (for now) IS CySmart. And it IS seeing advertisement after calling BLE_GAPP_StopAdvertisement. I have put a breakpoint in the loop after the call to y_BLE_GAPP_StopAdvertisemen (see first post) so I know that the code gets trapped there. While it is in that loop, CySmart can still find my device.

One snafu with the test project: I am running on a CYBLE-41605-02 module. I probably should have mentioned that sooner. My bad. The test project is for a CY8C6347BZI-BLD53, which my downloader declares to be incompatible with a CYBLE-41605-02. And Creator 4.3 doesn't appear to provide any way to change the selected device after the project is created. If you provide me with a CYBLE-41605-02 version, I will be more than willing try this experiment again.

Can you please solve one mystery in the mean time? Where is the REAL definition of Cy_BLE_GAPP_ExitDiscoveryMode()? Even in the project that you just sent, the only definition I can find using a workspace wide search is the following from cy_ble_stack_gap_peripheral.h:

cy_en_ble_api_result_t Cy_BLE_GAPP_ExitDiscoveryMode

(

    void

);

And this definition can't possibly be the version that actually causes the stack to exit discovery mode. I am also running a dual CPU configuration. Does this call somehow get routed to the cm0 core?

Thank you for your patient assistance,

Ed H.

0 Likes
lock attach
Attachments are accessible only for community members.

Hi Ed,

And Creator 4.3 doesn't appear to provide any way to change the selected device after the project is created.

Actually, you can change the device in PSoC Creator after project is created. You can right click on the project--> Click on Device selector--> Select series --> Select the device. Please find the image below:

Can you please solve one mystery in the mean time? Where is the REAL definition of Cy_BLE_GAPP_ExitDiscoveryMode()? Even in the project that you just sent, the only definition I can find using a workspace wide search is the following from cy_ble_stack_gap_peripheral.h:

And this definition can't possibly be the version that actually causes the stack to exit discovery mode.

The PSoC BLE stack is not completely exposed to the customers. So you are not able to see the implementation of that particular API.

Does this call somehow get routed to the cm0 core?

This call is handled by the core in which the Controller is implemented. You can see the setting in the BLE configuration tab to select in which core the Host and Controller should run.

Please find the attached project with CYBLE-416045-02. Please check if this project is working for you. It will advertise the device name FindMeTarget for the first 10 seconds after programming and then it stops advertising.

Thanks

Ganesh

0 Likes