2020-12-18 04:40 AM
Hi,
using STM32WBRG, I was able to connect to the board via BLE: i installed the app "ST BLE Sensor" and then i was able to turn off/on the led. (Code generated by CubeMX). all works fine. In fact, I followed "STM32WB_workshop" proposed by ST.
In the next step, i tried to add my own service (without any characteristic). The purpose is to add successfully a custom service.
But, i can't connect my android app to the board. I install also LightBlue to see the different service and characteristic. But i didn't work. Not able to connect the the board. when i delete the service that i have added, all works fine. So, I am not able to added my own service.
Here is the service that i have added. Note that the uuid of this service is generated by "https ://www.uuidgenerator.net".
Please see the snippet code in file "custom_stm.c" where i developped the service:
#include "common_blesvc.h"
#include "custom_stm.h"
typedef struct{
uint16_t CustomSvcHdle; /**< Service handle */
}CustomContext_t;
#define UUID_128_SUPPORTED 1
#if (UUID_128_SUPPORTED == 1)
#define BM_UUID_LENGTH UUID_TYPE_128
#else
#define BM_UUID_LENGTH UUID_TYPE_16
#endif
#define BM_REQ_CHAR_SIZE (3)
PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") static CustomContext_t CustomContext;
static SVCCTL_EvtAckStatus_t Custom_STM_Event_Handler(void *pckt);
#define COPY_UUID_128(uuid_struct, uuid_15, uuid_14, uuid_13, uuid_12, uuid_11, uuid_10, uuid_9, uuid_8, uuid_7, uuid_6, uuid_5, uuid_4, uuid_3, uuid_2, uuid_1, uuid_0) \
do {\
uuid_struct[0] = uuid_0; uuid_struct[1] = uuid_1; uuid_struct[2] = uuid_2; uuid_struct[3] = uuid_3; \
uuid_struct[4] = uuid_4; uuid_struct[5] = uuid_5; uuid_struct[6] = uuid_6; uuid_struct[7] = uuid_7; \
uuid_struct[8] = uuid_8; uuid_struct[9] = uuid_9; uuid_struct[10] = uuid_10; uuid_struct[11] = uuid_11; \
uuid_struct[12] = uuid_12; uuid_struct[13] = uuid_13; uuid_struct[14] = uuid_14; uuid_struct[15] = uuid_15; \
}while(0)
//The uuid generated by https ://www.uuidgenerator.net": 1885c1f8-6652-4f79-a5da-1db714f18194
//So The uuid of this service
#define COPY_CUSTOM_SERVICE_UUID(uuid_struct) COPY_UUID_128(uuid_struct,0x18,0x85,0xc1,0xf8,0x66,0x52,0x4f,0x79,0xa5,0xda,0x1d,0xb7,0x14,0xf1,0x81,0x49)
static SVCCTL_EvtAckStatus_t Custom_STM_Event_Handler(void *Event)
{
SVCCTL_EvtAckStatus_t return_value;
hci_event_pckt *event_pckt;
evt_blue_aci *blue_evt;
/* USER CODE BEGIN Custom_STM_Event_Handler_1 */
/* USER CODE END Custom_STM_Event_Handler_1 */
return_value = SVCCTL_EvtNotAck;
event_pckt = (hci_event_pckt *)(((hci_uart_pckt*)Event)->data);
switch(event_pckt->evt)
{
case EVT_VENDOR:
blue_evt = (evt_blue_aci*)event_pckt->data;
switch(blue_evt->ecode)
{
case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED:
/* USER CODE BEGIN EVT_BLUE_GATT_ATTRIBUTE_MODIFIED */
/* USER CODE END EVT_BLUE_GATT_ATTRIBUTE_MODIFIED */
break;
case EVT_BLUE_GATT_READ_PERMIT_REQ :
/* USER CODE BEGIN EVT_BLUE_GATT_READ_PERMIT_REQ */
/* USER CODE END EVT_BLUE_GATT_READ_PERMIT_REQ */
break;
case EVT_BLUE_GATT_WRITE_PERMIT_REQ:
/* USER CODE BEGIN EVT_BLUE_GATT_WRITE_PERMIT_REQ */
/* USER CODE END EVT_BLUE_GATT_WRITE_PERMIT_REQ */
break;
default:
/* USER CODE BEGIN EVT_DEFAULT */
/* USER CODE END EVT_DEFAULT */
break;
}
/* USER CODE BEGIN EVT_VENDOR*/
/* USER CODE END EVT_VENDOR*/
break; /* EVT_VENDOR */
/* USER CODE BEGIN EVENT_PCKT_CASES*/
/* USER CODE END EVENT_PCKT_CASES*/
default:
break;
}
void SVCCTL_InitCustomSvc(void)
{
Char_UUID_t uuid;
/* USER CODE BEGIN SVCCTL_InitCustomSvc_1 */
/* USER CODE END SVCCTL_InitCustomSvc_1 */
/**
* Register the event handler to the BLE controller
*/
SVCCTL_RegisterSvcHandler(Custom_STM_Event_Handler);
/* USER CODE BEGIN SVCCTL_InitCustomSvc_2 */
COPY_CUSTOM_SERVICE_UUID(uuid.Char_UUID_128);
aci_gatt_add_service(UUID_TYPE_128,
(Service_UUID_t *) &uuid,
PRIMARY_SERVICE,
1,
&(CustomContext.CustomSvcHdle));
/* USER CODE END SVCCTL_InitCustomSvc_2 */
return;
}
Please what's missid, what shouldi do when adding a custom service.
2020-12-18 04:41 AM
Hello @Remi QUINTIN,
Please help or any solution for this issue.
Many thanks in advance.
2020-12-18 04:54 AM
Did you remove the oreviots service before adding yours.
In fact as I mentionned in another post on the community, The size of the SRAM area dedicated to the memory allocation for services and characteristics is limited.
it is never sure that the services you define will fit in that area.
The process to check if it is OK is:
Then check the return value of the SHCI_C2_BLE_Init() function. If it is not zero, the configuration is too big for the available memory space.
So just add 1 to the CFG_BLE_NUM_GATT_SERVICES parameter as you do not have any additonnal characteristics and check whther it works.
2020-12-18 06:01 AM
Hello,
Thanks for your quick response.
If fact, the program works fine when it has juste one service and two characteristic (Generated by CubeMX) for controlling led et button notificaion.
The problem occurs when i try to add my own service with a custom UUID.
So i try to do what did you notice:
And the issue still exist.
I cant connect to the bord.
did I misunderstand what are you saying?
Btw, how can i increase the size of SRAM area dedicated to the memory allocation for services and characteristics.
Thanks in advance
2020-12-18 06:42 AM
Connecting to the board has nothing to do with service discovery. So the issue is somewhere else, even before any RF activity.
Are you able to see your device with the BLE sensor application on your mobile? This question is to discriminate in between a real RF issue (no advertising) or only a connection issue.
Did you attach a debugger to see where it could hang? infinite loop or waiting for an event?
2020-12-18 09:58 AM
Yes, i am able to see the device on my mobile.
I added a toggling led when the board advertising, but when i try to connect my android app to the board, the led stop toggling and the program enter to the infinite loop of the main:
int main(void)
{
.......
.......
.......
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
UTIL_SEQ_Run(~0);
}
/* USER CODE END 3 */
}
I attach the code
2020-12-18 10:06 AM
OK. Your android app is not the ST BLE sensor application ... correct?
Try just to connect and do not request the service discovery, just to see if the connection is correct at least.
If the connection is possible , there is something wrong during the service discovery.
2020-12-18 11:30 AM
i am using ST BLE sensor and also i tried also with the app "LightBlue" and i had the same problem.
when i comment this part of code in the file "custom_stm.c" , the program works fine;
/* USER CODE BEGIN SVCCTL_InitCustomSvc_2 */
// COPY_CUSTOM_SERVICE_UUID(uuid.Char_UUID_128);
// aci_gatt_add_service(UUID_TYPE_128,
// (Service_UUID_t *) &uuid,
// PRIMARY_SERVICE,
// 1,
// &(CustomContext.CustomSvcHdle));
/* USER CODE END SVCCTL_InitCustomSvc_2 */
return;
}
2020-12-21 01:13 AM
So, there is problem just when adding a custom service. the board still advertising (Green Led blinking) until i try to connect the board to my android app.
SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
{
hci_event_pckt *event_pckt;
evt_le_meta_event *meta_evt;
evt_blue_aci *blue_evt;
hci_le_phy_update_complete_event_rp0 *evt_le_phy_update_complete;
uint8_t TX_PHY, RX_PHY;
tBleStatus ret = BLE_STATUS_INVALID_PARAMS;
event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data;
/* USER CODE BEGIN SVCCTL_App_Notification */
/* USER CODE END SVCCTL_App_Notification */
switch (event_pckt->evt)
{
........
.......
.......
case EVT_VENDOR:
blue_evt = (evt_blue_aci*) event_pckt->data;
/* USER CODE BEGIN EVT_VENDOR */
/* USER CODE END EVT_VENDOR */
switch (blue_evt->ecode)
{
......
.....
.....
#if(RADIO_ACTIVITY_EVENT != 0)
case ACI_HAL_END_OF_RADIO_ACTIVITY_VSEVT_CODE:
/* USER CODE BEGIN RADIO_ACTIVITY_EVENT*/
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
/* USER CODE END RADIO_ACTIVITY_EVENT*/
break; /* RADIO_ACTIVITY_EVENT */
#endif
........
........
........
}
when i comment the part of code dedicated for adding a custom service, the program works fine and i can connect my android app to the board.
void SVCCTL_InitCustomSvc(void)
{
Char_UUID_t uuid;
/* USER CODE BEGIN SVCCTL_InitCustomSvc_1 */
/* USER CODE END SVCCTL_InitCustomSvc_1 */
/**
* Register the event handler to the BLE controller
*/
SVCCTL_RegisterSvcHandler(Custom_STM_Event_Handler);
/* USER CODE BEGIN SVCCTL_InitCustomSvc_2 */
// COPY_CUSTOM_SERVICE_UUID(uuid.Char_UUID_128);
// aci_gatt_add_service(UUID_TYPE_128,
// (Service_UUID_t *) &uuid,
// PRIMARY_SERVICE,
// 1,
// &(CustomContext.CustomSvcHdle));
/* USER CODE END SVCCTL_InitCustomSvc_2 */
return;
}
2020-12-21 05:34 AM
Hi @Christophe Arnal ,
Please help and thanks in advance.