STM32WB HCIDriver trace update

pull/12384/head
jeromecoutant 2020-02-20 09:20:36 +01:00
parent 829a3cded3
commit 55b42a683e
1 changed files with 51 additions and 53 deletions

View File

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2019 ARM Limited * Copyright (c) 2019 ARM Limited
* Copyright (c) 2019 STMicroelectronics
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -26,7 +27,7 @@
#include "dm_api.h" #include "dm_api.h"
#include "bstream.h" #include "bstream.h"
#include "hci_mbed_os_adaptation.h" #include "hci_mbed_os_adaptation.h"
#include "mbed-trace/mbed_trace.h" #include "mbed_trace.h"
/* STM32WB include files */ /* STM32WB include files */
#include "stm32wbxx_ll_ipcc.h" #include "stm32wbxx_ll_ipcc.h"
@ -38,6 +39,9 @@
#include "app_conf.h" #include "app_conf.h"
#include "otp.h" #include "otp.h"
/* mbed trace feature is supported */
/* ex in mbed_app.json */
/* "mbed-trace.enable": "1" */
#define TRACE_GROUP "BLWB" #define TRACE_GROUP "BLWB"
/****************************************************************************** /******************************************************************************
@ -61,8 +65,12 @@
#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) #define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251)
#define MAX_HACI_EVT_SIZE (255+5) #define MAX_HACI_EVT_SIZE (255+5)
/* activate to add debug traces */ /* mbed_trace: debug traces (tr_debug) can be disabled here with no change in mbed_app.json */
#define PRINT_HCI_DATA 1 // #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 * BLE config parameters
@ -133,34 +141,33 @@ public:
/* if event is a command complete event */ /* if event is a command complete event */
if (*pMsg == HCI_CMD_CMPL_EVT) { if (*pMsg == HCI_CMD_CMPL_EVT) {
#if (PRINT_HCI_DATA == 1) tr_debug("Command Complete Event Command");
tr_debug("Command complete event\r\n"); #if (PRINT_HCI_DATA)
tr_debug("Command >> ");
for (uint8_t i = 0; i < 20; i++) { 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 #endif
/* parse parameters */
tr_debug(" HCI_EVT_HDR_LEN=%d", HCI_EVT_HDR_LEN);
pMsg += HCI_EVT_HDR_LEN; pMsg += HCI_EVT_HDR_LEN;
pMsg++; /* skip num packets */ pMsg++; /* skip num packets */
BSTREAM_TO_UINT16(opcode, pMsg); BSTREAM_TO_UINT16(opcode, pMsg);
pMsg++; /* skip status */ pMsg++; /* skip status */
/* decode opcode */ /* decode opcode */
tr_debug(" opcode = %#06x", opcode);
switch (opcode) { switch (opcode) {
case HCI_OPCODE_RESET: case HCI_OPCODE_RESET:
/* initialize rand command count */ /* initialize rand command count */
randCnt = 0; randCnt = 0;
tr_debug("WB Reset Received\r\n"); tr_info("WB Reset Received");
/* Once reset complete evet is received we need /* Once reset complete evet is received we need
* to send a few more commands: * to send a few more commands:
* Tx power and set bd addr * Tx power and set bd addr
*/ */
if (get_bd_address(bd_addr)) { if (get_bd_address(bd_addr)) {
aciWriteConfigData(CONFIG_DATA_PUBADDR_OFFSET, bd_addr); aciWriteConfigData(CONFIG_DATA_PUBADDR_OFFSET, bd_addr);
tr_debug("Setting Bdaddr: %2x:%2x:%2x:%2x:%2x:%2x\r\n", tr_info("Setting Bdaddr: %02x:%02x:%02x:%02x:%02x:%02x",
bd_addr[0], bd_addr[0],
bd_addr[1], bd_addr[1],
bd_addr[2], bd_addr[2],
@ -168,23 +175,22 @@ public:
bd_addr[4], bd_addr[4],
bd_addr[5]); bd_addr[5]);
} else { } else {
tr_debug("could not find BDaddr\r\n"); tr_info("could not find BDaddr");
/* Skip to next step */ /* Skip to next step */
aciSetTxPowerLevel(); aciSetTxPowerLevel();
} }
break; break;
case ACI_WRITE_CONFIG_DATA_OPCODE: 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 /* set the event mask to control which events are generated by the
* controller for the host */ * controller for the host */
tr_debug("ACI_HAL_SET_TX_POWER_LEVEL\r\n");
aciSetTxPowerLevel(); aciSetTxPowerLevel();
break; break;
case ACI_HAL_SET_TX_POWER_LEVEL: 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(); //signal_reset_sequence_done();
HciSetEventMaskCmd((uint8_t *) hciEventMask); HciSetEventMaskCmd((uint8_t *) hciEventMask);
break; break;
@ -323,7 +329,7 @@ public:
break; break;
default: 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; break;
} }
} else if (*pMsg == HCI_CMD_STATUS_EVT) { } else if (*pMsg == HCI_CMD_STATUS_EVT) {
@ -335,7 +341,7 @@ public:
pMsg++; pMsg++;
pMsg++; /* skip num packets */ pMsg++; /* skip num packets */
BSTREAM_TO_UINT16(opcode, pMsg); 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 { } else {
/** /**
* vendor specific event * vendor specific event
@ -344,9 +350,9 @@ public:
/* parse parameters */ /* parse parameters */
pMsg += HCI_EVT_HDR_LEN; pMsg += HCI_EVT_HDR_LEN;
BSTREAM_TO_UINT16(opcode, pMsg); 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 { } else {
tr_debug("Unknown event %d!\r\n", pMsg[0]); tr_info("Unknown event %d!", pMsg[0]);
} }
} }
} }
@ -500,7 +506,7 @@ private:
/* At this stage, we'll need to wait for ready event, /* At this stage, we'll need to wait for ready event,
* passed thru TL_SYS_EvtReceived */ * passed thru TL_SYS_EvtReceived */
if (!sysevt_wait()) { if (!sysevt_wait()) {
tr_debug("ERROR booting WB controler\r\n"); tr_info("ERROR booting WB controler");
return; return;
} }
@ -526,35 +532,29 @@ private:
// type 02 ACL DATA // type 02 ACL DATA
// type 03 SCO Voice (not supported) // type 03 SCO Voice (not supported)
// type 04 event - uplink (not suported) // type 04 event - uplink (not suported)
#if (PRINT_HCI_DATA == 1) tr_debug("mbox_write type:%d, len:%d", type, len);
tr_debug("mbox_write type:%d, len:%d\r\n", type, len);
#endif
/* TO DO : MANAGE ACL DATA CASE in separate buffer */ /* TO DO : MANAGE ACL DATA CASE in separate buffer */
switch (type) { switch (type) {
case 1://BLE command case 1://BLE command
bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd
memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len); 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 /* We're tracing here the command, after copy in shared mem but before
* * M0 trigger. */ * * M0 trigger. */
tr_debug("TX>> BLE CMD: "); tr_info("TX>> BLE CMD");
/* Trace the buffer including Type (+1 on lngth) */ /* Trace the buffer including Type (+1 on lngth) */
tr_debug("Type %2X ", bleCmdBuf->cmdserial.type); tr_debug(" Type %#x", bleCmdBuf->cmdserial.type);
tr_debug("Cmd %4X ", bleCmdBuf->cmdserial.cmd.cmdcode); tr_debug(" Cmd %#x", bleCmdBuf->cmdserial.cmd.cmdcode);
tr_debug("Len %2X ", bleCmdBuf->cmdserial.cmd.plen); tr_debug(" Len %#x", bleCmdBuf->cmdserial.cmd.plen);
tr_debug("Payload "); #if (PRINT_HCI_DATA)
for (uint8_t i = 0; i < bleCmdBuf->cmdserial.cmd.plen; i++) { 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 #endif
TL_BLE_SendCmd(NULL, 0); // unused parameters for now TL_BLE_SendCmd(NULL, 0); // unused parameters for now
break; break;
case 2://ACL DATA case 2://ACL DATA
if (!acl_data_wait()) { if (!acl_data_wait()) {
#if (PRINT_HCI_DATA == 1) tr_info("ERROR: previous ACL message not ACK'd");
tr_debug("ERROR: previous ACL message not ACK'd\r\n");
#endif
/* return number of bytes sent, 0 in this error case */ /* return number of bytes sent, 0 in this error case */
return 0; return 0;
} }
@ -562,13 +562,11 @@ private:
aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd
memcpy(aclDataBuffer + + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len); memcpy(aclDataBuffer + + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len);
TL_BLE_SendAclData(NULL, 0); // unused parameters for now TL_BLE_SendAclData(NULL, 0); // unused parameters for now
#if (PRINT_HCI_DATA == 1) tr_info("TX>> BLE ACL");
tr_debug(" TX>> BLE ACL: "); #if (PRINT_HCI_DATA)
/* Trace the buffer for debug purpose */
for (uint8_t i = 0; i < len + 1 + 8; i++) { 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 #endif
break; break;
} }
@ -712,7 +710,7 @@ static void evt_received(TL_EvtPacket_t *hcievt)
break; break;
default: default:
// should not happen - let's block to check // 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; break;
} }
@ -795,7 +793,7 @@ static bool sysevt_check(void)
static void syscmd_status_not(SHCI_TL_CmdStatus_t status) 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; return;
} }
@ -816,7 +814,7 @@ void shci_cmd_resp_wait(uint32_t timeout)
{ {
/* TO DO: manage timeouts if we can return an error */ /* TO DO: manage timeouts if we can return an error */
if (sys_resp_sem.wait(timeout) < 1) { 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");
} }
} }
@ -832,9 +830,9 @@ void shci_register_io_bus(tSHciIO *fops)
*/ */
static void init_debug(void) static void init_debug(void)
{ {
tr_debug("WB init_debug: ");
/* In case of MBED debug profile, configure debugger support */ /* In case of MBED debug profile, configure debugger support */
#if (defined(MBED_DEBUG) || (CFG_DEBUGGER_SUPPORTED == 1)) #if (defined(MBED_DEBUG) || (CFG_DEBUGGER_SUPPORTED == 1))
tr_info("init_debug ENABLED");
/** /**
* Keep debugger enabled while in any low power mode * Keep debugger enabled while in any low power mode
*/ */
@ -847,7 +845,7 @@ static void init_debug(void)
LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48);
#else #else
tr_debug("DISABLED\r\n"); tr_info("init_debug DISABLED");
GPIO_InitTypeDef gpio_config = {0}; GPIO_InitTypeDef gpio_config = {0};
@ -883,7 +881,7 @@ bool get_bd_address(uint8_t *bd_addr)
udn = LL_FLASH_GetUDN(); udn = LL_FLASH_GetUDN();
if (udn != 0xFFFFFFFF) { 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(); company_id = LL_FLASH_GetSTCompanyID();
device_id = LL_FLASH_GetDeviceID(); device_id = LL_FLASH_GetDeviceID();
@ -902,7 +900,7 @@ bool get_bd_address(uint8_t *bd_addr)
memcpy(bd_addr, ((OTP_ID0_t *)otp_addr)->bd_address, CONFIG_DATA_PUBADDR_LEN); memcpy(bd_addr, ((OTP_ID0_t *)otp_addr)->bd_address, CONFIG_DATA_PUBADDR_LEN);
bd_found = false; bd_found = false;
} else { } 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; bd_found = true;
} }
} }