Skip to content

STM32WB : update BLE part with better support #12384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 60 additions & 53 deletions features/FEATURE_BLE/targets/TARGET_STM/TARGET_STM32WB/HCIDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2019 ARM Limited
* Copyright (c) 2019 STMicroelectronics
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -26,7 +27,7 @@
#include "dm_api.h"
#include "bstream.h"
#include "hci_mbed_os_adaptation.h"
#include "mbed-trace/mbed_trace.h"
#include "mbed_trace.h"

/* STM32WB include files */
#include "stm32wbxx_ll_ipcc.h"
Expand All @@ -38,6 +39,9 @@
#include "app_conf.h"
#include "otp.h"

/* mbed trace feature is supported */
/* ex in mbed_app.json */
/* "mbed-trace.enable": "1" */
#define TRACE_GROUP "BLWB"

/******************************************************************************
Expand All @@ -61,8 +65,12 @@
#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251)
#define MAX_HACI_EVT_SIZE (255+5)

/* activate to add debug traces */
#define PRINT_HCI_DATA 1
/* mbed_trace: debug traces (tr_debug) can be disabled here with no change in mbed_app.json */
// #undef TRACE_LEVEL_DEBUG
// #define TRACE_LEVEL_DEBUG 0

/* tr_debug : add data content in console print */
#define PRINT_HCI_DATA 0

/******************************************************************************
* BLE config parameters
Expand Down Expand Up @@ -133,58 +141,56 @@ class HCIDriver : public cordio::CordioHCIDriver {

/* if event is a command complete event */
if (*pMsg == HCI_CMD_CMPL_EVT) {
#if (PRINT_HCI_DATA == 1)
tr_debug("Command complete event\r\n");
tr_debug("Command >> ");
tr_debug("Command Complete Event Command");
#if (PRINT_HCI_DATA)
for (uint8_t i = 0; i < 20; i++) {
tr_debug("%2X ", *((uint8_t *)pMsg + i));
tr_debug(" %02X", *((uint8_t *)pMsg + i));
}
tr_debug("\r\n");
/* parse parameters */
tr_debug("HCI_EVT_HDR_LEN=%d\r\n", HCI_EVT_HDR_LEN);
#endif
/* parse parameters */
tr_debug(" HCI_EVT_HDR_LEN=%d", HCI_EVT_HDR_LEN);
pMsg += HCI_EVT_HDR_LEN;
pMsg++; /* skip num packets */
BSTREAM_TO_UINT16(opcode, pMsg);
pMsg++; /* skip status */

/* decode opcode */
tr_debug(" opcode = %#06x", opcode);
switch (opcode) {
case HCI_OPCODE_RESET:
/* initialize rand command count */
randCnt = 0;
tr_debug("WB Reset Received\r\n");
tr_info("WB Reset Received");
/* Once reset complete evet is received we need
* to send a few more commands:
* Tx power and set bd addr
*/
if (get_bd_address(bd_addr)) {
aciWriteConfigData(CONFIG_DATA_PUBADDR_OFFSET, bd_addr);
tr_debug("Setting Bdaddr: %2x:%2x:%2x:%2x:%2x:%2x\r\n",
bd_addr[0],
bd_addr[1],
bd_addr[2],
bd_addr[3],
bd_addr[4],
bd_addr[5]);
tr_info("Setting Bdaddr: %02x:%02x:%02x:%02x:%02x:%02x",
bd_addr[0],
bd_addr[1],
bd_addr[2],
bd_addr[3],
bd_addr[4],
bd_addr[5]);
} else {
tr_debug("could not find BDaddr\r\n");
tr_info("could not find BDaddr");
/* Skip to next step */
aciSetTxPowerLevel();
}
break;

case ACI_WRITE_CONFIG_DATA_OPCODE:
tr_debug("BD address set\r\n");
tr_debug("Bluetooth Device address set");
/* set the event mask to control which events are generated by the
* controller for the host */
tr_debug("ACI_HAL_SET_TX_POWER_LEVEL\r\n");
aciSetTxPowerLevel();
break;


case ACI_HAL_SET_TX_POWER_LEVEL:
tr_debug("Tx Power Level set\r\n");
tr_debug("Tx Power Level set");
//signal_reset_sequence_done();
HciSetEventMaskCmd((uint8_t *) hciEventMask);
break;
Expand Down Expand Up @@ -323,7 +329,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
break;

default:
tr_debug("Complete Event in reset seq with unknown opcode =0x%4X\r\n", opcode);
tr_info("Complete Event in reset seq with unknown opcode =0x%4X", opcode);
break;
}
} else if (*pMsg == HCI_CMD_STATUS_EVT) {
Expand All @@ -335,7 +341,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
pMsg++;
pMsg++; /* skip num packets */
BSTREAM_TO_UINT16(opcode, pMsg);
tr_debug("Command Status event, status:%d, opcode=0x%4X\r\n", status, opcode);
tr_info("Command Status event, status:%d, opcode=0x%4X", status, opcode);
} else {
/**
* vendor specific event
Expand All @@ -344,9 +350,9 @@ class HCIDriver : public cordio::CordioHCIDriver {
/* parse parameters */
pMsg += HCI_EVT_HDR_LEN;
BSTREAM_TO_UINT16(opcode, pMsg);
tr_debug("Vendor specific event, opcode=0x%4X\r\n", opcode);
tr_debug("Vendor specific event, opcode=0x%4X", opcode);
} else {
tr_debug("Unknown event %d!\r\n", pMsg[0]);
tr_info("Unknown event %d!", pMsg[0]);
}
}
}
Expand Down Expand Up @@ -453,6 +459,15 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
init_debug();
stm32wb_reset();
transport_init();

WirelessFwInfo_t wireless_info_instance;
WirelessFwInfo_t *p_wireless_info = &wireless_info_instance;
if (SHCI_GetWirelessFwInfo(p_wireless_info) != SHCI_Success) {
tr_info("SHCI_GetWirelessFwInfo error");
} else {
tr_info("WIRELESS COPROCESSOR FW VERSION ID = %d.%d.%d", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub);
tr_info("WIRELESS COPROCESSOR FW STACK TYPE = %d", p_wireless_info->StackType);
}
}
}

Expand Down Expand Up @@ -500,7 +515,7 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
/* At this stage, we'll need to wait for ready event,
* passed thru TL_SYS_EvtReceived */
if (!sysevt_wait()) {
tr_debug("ERROR booting WB controler\r\n");
tr_info("ERROR booting WB controler");
return;
}

Expand All @@ -526,49 +541,41 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
// type 02 ACL DATA
// type 03 SCO Voice (not supported)
// type 04 event - uplink (not suported)
#if (PRINT_HCI_DATA == 1)
tr_debug("mbox_write type:%d, len:%d\r\n", type, len);
#endif
tr_debug("mbox_write type:%d, len:%d", type, len);
/* TO DO : MANAGE ACL DATA CASE in separate buffer */
switch (type) {
case 1://BLE command
bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd
memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len);
#if (PRINT_HCI_DATA == 1)
/* We're tracing here the command, after copy in shared mem but before
* * M0 trigger. */
tr_debug("TX>> BLE CMD: ");
tr_info("TX>> BLE CMD");
/* Trace the buffer including Type (+1 on lngth) */
tr_debug("Type %2X ", bleCmdBuf->cmdserial.type);
tr_debug("Cmd %4X ", bleCmdBuf->cmdserial.cmd.cmdcode);
tr_debug("Len %2X ", bleCmdBuf->cmdserial.cmd.plen);
tr_debug("Payload ");
tr_debug(" Type %#x", bleCmdBuf->cmdserial.type);
tr_debug(" Cmd %#x", bleCmdBuf->cmdserial.cmd.cmdcode);
tr_debug(" Len %#x", bleCmdBuf->cmdserial.cmd.plen);
#if (PRINT_HCI_DATA)
for (uint8_t i = 0; i < bleCmdBuf->cmdserial.cmd.plen; i++) {
tr_debug("%2X ", *(((uint8_t *)&bleCmdBuf->cmdserial.cmd.payload) + i));
tr_debug(" %02X", *(((uint8_t *)&bleCmdBuf->cmdserial.cmd.payload) + i));
}
tr_debug("\r\n");
#endif
TL_BLE_SendCmd(NULL, 0); // unused parameters for now
break;
case 2://ACL DATA
if (!acl_data_wait()) {
#if (PRINT_HCI_DATA == 1)
tr_debug("ERROR: previous ACL message not ACK'd\r\n");
#endif
tr_info("ERROR: previous ACL message not ACK'd");
/* return number of bytes sent, 0 in this error case */
return 0;
}
TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(aclDataBuffer + sizeof(TL_PacketHeader_t));
aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd
memcpy(aclDataBuffer + + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len);
TL_BLE_SendAclData(NULL, 0); // unused parameters for now
#if (PRINT_HCI_DATA == 1)
tr_debug(" TX>> BLE ACL: ");
/* Trace the buffer for debug purpose */
tr_info("TX>> BLE ACL");
#if (PRINT_HCI_DATA)
for (uint8_t i = 0; i < len + 1 + 8; i++) {
tr_debug("%2X ", *(((uint8_t *) aclDataBuffer) + i));
tr_debug(" %02x", *(((uint8_t *) aclDataBuffer) + i));
}
tr_debug("\r\n");
#endif
break;
}
Expand Down Expand Up @@ -712,7 +719,7 @@ static void evt_received(TL_EvtPacket_t *hcievt)
break;
default:
// should not happen - let's block to check
tr_error("BLE TL evt_received, wrong type:%d \r\n");
tr_error("BLE TL evt_received, wrong type:%d", hcievt->evtserial.type);
break;
}

Expand Down Expand Up @@ -795,7 +802,7 @@ static bool sysevt_check(void)

static void syscmd_status_not(SHCI_TL_CmdStatus_t status)
{
tr_debug("syscmd_status_not, status:%d\r\n", status);
tr_debug("syscmd_status_not, status:%d", status);
return;
}

Expand All @@ -816,7 +823,7 @@ void shci_cmd_resp_wait(uint32_t timeout)
{
/* TO DO: manage timeouts if we can return an error */
if (sys_resp_sem.wait(timeout) < 1) {
tr_error("shci_cmd_resp_wait timed out\r\n");
tr_error("shci_cmd_resp_wait timed out");
}
}

Expand All @@ -832,9 +839,9 @@ void shci_register_io_bus(tSHciIO *fops)
*/
static void init_debug(void)
{
tr_debug("WB init_debug: ");
/* In case of MBED debug profile, configure debugger support */
#if (defined(MBED_DEBUG) || (CFG_DEBUGGER_SUPPORTED == 1))
tr_info("init_debug ENABLED");
/**
* Keep debugger enabled while in any low power mode
*/
Expand All @@ -847,7 +854,7 @@ static void init_debug(void)
LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48);

#else
tr_debug("DISABLED\r\n");
tr_info("init_debug DISABLED");

GPIO_InitTypeDef gpio_config = {0};

Expand Down Expand Up @@ -883,7 +890,7 @@ bool get_bd_address(uint8_t *bd_addr)
udn = LL_FLASH_GetUDN();

if (udn != 0xFFFFFFFF) {
tr_debug("Found UDN: 0x%8lX\r\n", udn);
tr_info("Found Unique Device Number: %#06x", udn);

company_id = LL_FLASH_GetSTCompanyID();
device_id = LL_FLASH_GetDeviceID();
Expand All @@ -902,7 +909,7 @@ bool get_bd_address(uint8_t *bd_addr)
memcpy(bd_addr, ((OTP_ID0_t *)otp_addr)->bd_address, CONFIG_DATA_PUBADDR_LEN);
bd_found = false;
} else {
tr_debug("Cannot find BD ADDRESS to program - will leave hw default\r\n");
tr_debug("Cannot find Bluetooth Device ADDRESS to program - will leave hw default");
bd_found = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion targets/TARGET_STM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ This table summarizes the STM32Cube versions currently used :
| L1 | 1.8.1 | https://github.com/STMicroelectronics/STM32CubeL1 |
| L4 | 1.11.0 | https://github.com/STMicroelectronics/STM32CubeL4 |
| L5 | 1.1.0 | https://github.com/STMicroelectronics/STM32CubeL5 |
| WB | 1.0.0 | https://github.com/STMicroelectronics/STM32CubeWB |
| WB | 1.4.0 | https://github.com/STMicroelectronics/STM32CubeWB |
Loading