2021-02-02 03:14 PM
Hello,
I am a beginner with ble. I have worked with other stm boards in the past. I need help with the STM32WB baord.
I used cube mx to generate the start up code. Enabled rf, rtc and everything.
Enabled custom template in server mode
added a service and a characteristic to that service.
The code generated from cubemx has a file named custom_app.c
in there under the Custom_APP_Init function , i added the following code.
uint8_t bdaddr[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02};
if(aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, 6, bdaddr))
{
APP_DBG_MSG("Setting address failed.\n");
}
aci_hal_set_tx_power_level(0x01,0x1f);
/*
The following 128bits UUIDs have been generated from the random UUID
generator:
D973F2E0-B19E-11E2-9E96-0800200C9A66: Service 128bits UUID
D973F2E1-B19E-11E2-9E96-0800200C9A66: Characteristic_1 128bits UUID
*/
Service_UUID_t service_uuid;
Char_UUID_t char_uuid;
/*Service 128bits UUID */
const uint8_t uuid[16] =
{0x66, 0x9a, 0x0c, 0x20, 0x00, 0x08, 0x96, 0x9e, 0xe2, 0x11, 0x9e, 0xb1, 0xe0, 0xf2, 0x73, 0xd9};
/*Characteristic_1 128bits UUID */
const uint8_t charUuid_1[16] =
{0x66, 0x9a, 0x0c, 0x20, 0x00, 0x08, 0x96, 0x9e, 0xe2, 0x11, 0x9e, 0xb1, 0xe1, 0xf2, 0x73, 0xd9};
Osal_MemCpy(&service_uuid.Service_UUID_128, uuid, 16);
//add service
if(aci_gatt_add_service(UUID_TYPE_128,&service_uuid,PRIMARY_SERVICE,6, Custom_App_Context.srvTestHandle) != BLE_STATUS_SUCCESS)
{
APP_DBG_MSG("GATT SERVICE ADD FAILED.\n");
}
//add characteristic
Osal_MemCpy(&char_uuid.Char_UUID_128, charUuid_1, 16);
if (aci_gatt_add_char(Custom_App_Context.srvTestHandle, UUID_TYPE_128, &char_uuid, 20, CHAR_PROP_READ, ATTR_PERMISSION_NONE, GATT_DONT_NOTIFY_EVENTS, 16, 1, &Custom_App_Context.charTestHandle) != BLE_STATUS_SUCCESS)
{
APP_DBG_MSG("GATT CHAR ADD FAILED.\n");
}
The properties like device name and short name as set in gap via cubeMX.
in main.c , under the main while(1), i have added the following.
UTIL_SEQ_Run(UTIL_SEQ_DEFAULT);
apart form that , i have copied the following from the p2pserver example code.
static void Init_Exti(void)
{
/**< Disable all wakeup interrupt on CPU1 except IPCC(36), HSEM(38) */
LL_EXTI_DisableIT_0_31(~0);
LL_EXTI_DisableIT_32_63((~0) & (~(LL_EXTI_LINE_36 | LL_EXTI_LINE_38)));
return;
}
static void Reset_BackupDomain( void )
{
if ((LL_RCC_IsActiveFlag_PINRST() != FALSE) && (LL_RCC_IsActiveFlag_SFTRST() == FALSE))
{
HAL_PWR_EnableBkUpAccess(); /**< Enable access to the RTC registers */
/**
* Write twice the value to flush the APB-AHB bridge
* This bit shall be written in the register before writing the next one
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();
}
return;
}
static void Reset_IPCC( void )
{
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC);
LL_C1_IPCC_ClearFlag_CHx(
IPCC,
LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4
| LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6);
LL_C2_IPCC_ClearFlag_CHx(
IPCC,
LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4
| LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6);
LL_C1_IPCC_DisableTransmitChannel(
IPCC,
LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4
| LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6);
LL_C2_IPCC_DisableTransmitChannel(
IPCC,
LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4
| LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6);
LL_C1_IPCC_DisableReceiveChannel(
IPCC,
LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4
| LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6);
LL_C2_IPCC_DisableReceiveChannel(
IPCC,
LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4
| LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6);
return;
}
static void Reset_Device(void)
{
#if (CFG_HW_RESET_BY_FW == 1)
Reset_BackupDomain();
Reset_IPCC();
#endif
return;
}
static void Config_HSE(void)
{
OTP_ID0_t *p_otp;
/**
* Read HSE_Tuning from OTP
*/
p_otp = (OTP_ID0_t *)OTP_Read(0);
if (p_otp)
{
LL_RCC_HSE_SetCapacitorTuning(p_otp->hse_tuning);
}
return;
}
i have called the above functions after HAL_Init(); in main.c
The code builds without any error. But nothing is seen on the ble app.
All i want is that the device is discover able and service and characteristic are seen on the app. I want to get started with ble on stmwb. Any help would be highly appreciated.
Thanks in Advance.