mirror of https://github.com/ARMmbed/mbed-os.git
STM32WB HCIDriver trace update
parent
829a3cded3
commit
55b42a683e
|
@ -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");
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -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
|
||||
|
@ -133,34 +141,33 @@ public:
|
|||
|
||||
/* 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",
|
||||
tr_info("Setting Bdaddr: %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
bd_addr[0],
|
||||
bd_addr[1],
|
||||
bd_addr[2],
|
||||
|
@ -168,23 +175,22 @@ public:
|
|||
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;
|
||||
|
@ -323,7 +329,7 @@ public:
|
|||
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) {
|
||||
|
@ -335,7 +341,7 @@ public:
|
|||
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
|
||||
|
@ -344,9 +350,9 @@ public:
|
|||
/* 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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -500,7 +506,7 @@ private:
|
|||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -526,35 +532,29 @@ private:
|
|||
// 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;
|
||||
}
|
||||
|
@ -562,13 +562,11 @@ private:
|
|||
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;
|
||||
}
|
||||
|
@ -712,7 +710,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;
|
||||
}
|
||||
|
||||
|
@ -795,7 +793,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;
|
||||
}
|
||||
|
||||
|
@ -816,7 +814,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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -832,9 +830,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
|
||||
*/
|
||||
|
@ -847,7 +845,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};
|
||||
|
||||
|
@ -883,7 +881,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();
|
||||
|
@ -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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue