Skip to content

Commit 72b2fcf

Browse files
authored
Merge pull request #12384 from jeromecoutant/PR_WBDEBUG
STM32WB : update BLE part with better support
2 parents a18259a + a1570f9 commit 72b2fcf

File tree

8 files changed

+745
-216
lines changed

8 files changed

+745
-216
lines changed

features/FEATURE_BLE/targets/TARGET_STM/TARGET_STM32WB/HCIDriver.cpp

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2019 ARM Limited
3+
* Copyright (c) 2019 STMicroelectronics
34
* SPDX-License-Identifier: Apache-2.0
45
*
56
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +27,7 @@
2627
#include "dm_api.h"
2728
#include "bstream.h"
2829
#include "hci_mbed_os_adaptation.h"
29-
#include "mbed-trace/mbed_trace.h"
30+
#include "mbed_trace.h"
3031

3132
/* STM32WB include files */
3233
#include "stm32wbxx_ll_ipcc.h"
@@ -38,6 +39,9 @@
3839
#include "app_conf.h"
3940
#include "otp.h"
4041

42+
/* mbed trace feature is supported */
43+
/* ex in mbed_app.json */
44+
/* "mbed-trace.enable": "1" */
4145
#define TRACE_GROUP "BLWB"
4246

4347
/******************************************************************************
@@ -61,8 +65,12 @@
6165
#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251)
6266
#define MAX_HACI_EVT_SIZE (255+5)
6367

64-
/* activate to add debug traces */
65-
#define PRINT_HCI_DATA 1
68+
/* mbed_trace: debug traces (tr_debug) can be disabled here with no change in mbed_app.json */
69+
// #undef TRACE_LEVEL_DEBUG
70+
// #define TRACE_LEVEL_DEBUG 0
71+
72+
/* tr_debug : add data content in console print */
73+
#define PRINT_HCI_DATA 0
6674

6775
/******************************************************************************
6876
* BLE config parameters
@@ -133,58 +141,56 @@ class HCIDriver : public cordio::CordioHCIDriver {
133141

134142
/* if event is a command complete event */
135143
if (*pMsg == HCI_CMD_CMPL_EVT) {
136-
#if (PRINT_HCI_DATA == 1)
137-
tr_debug("Command complete event\r\n");
138-
tr_debug("Command >> ");
144+
tr_debug("Command Complete Event Command");
145+
#if (PRINT_HCI_DATA)
139146
for (uint8_t i = 0; i < 20; i++) {
140-
tr_debug("%2X ", *((uint8_t *)pMsg + i));
147+
tr_debug(" %02X", *((uint8_t *)pMsg + i));
141148
}
142-
tr_debug("\r\n");
143-
/* parse parameters */
144-
tr_debug("HCI_EVT_HDR_LEN=%d\r\n", HCI_EVT_HDR_LEN);
145149
#endif
150+
/* parse parameters */
151+
tr_debug(" HCI_EVT_HDR_LEN=%d", HCI_EVT_HDR_LEN);
146152
pMsg += HCI_EVT_HDR_LEN;
147153
pMsg++; /* skip num packets */
148154
BSTREAM_TO_UINT16(opcode, pMsg);
149155
pMsg++; /* skip status */
150156

151157
/* decode opcode */
158+
tr_debug(" opcode = %#06x", opcode);
152159
switch (opcode) {
153160
case HCI_OPCODE_RESET:
154161
/* initialize rand command count */
155162
randCnt = 0;
156-
tr_debug("WB Reset Received\r\n");
163+
tr_info("WB Reset Received");
157164
/* Once reset complete evet is received we need
158165
* to send a few more commands:
159166
* Tx power and set bd addr
160167
*/
161168
if (get_bd_address(bd_addr)) {
162169
aciWriteConfigData(CONFIG_DATA_PUBADDR_OFFSET, bd_addr);
163-
tr_debug("Setting Bdaddr: %2x:%2x:%2x:%2x:%2x:%2x\r\n",
164-
bd_addr[0],
165-
bd_addr[1],
166-
bd_addr[2],
167-
bd_addr[3],
168-
bd_addr[4],
169-
bd_addr[5]);
170+
tr_info("Setting Bdaddr: %02x:%02x:%02x:%02x:%02x:%02x",
171+
bd_addr[0],
172+
bd_addr[1],
173+
bd_addr[2],
174+
bd_addr[3],
175+
bd_addr[4],
176+
bd_addr[5]);
170177
} else {
171-
tr_debug("could not find BDaddr\r\n");
178+
tr_info("could not find BDaddr");
172179
/* Skip to next step */
173180
aciSetTxPowerLevel();
174181
}
175182
break;
176183

177184
case ACI_WRITE_CONFIG_DATA_OPCODE:
178-
tr_debug("BD address set\r\n");
185+
tr_debug("Bluetooth Device address set");
179186
/* set the event mask to control which events are generated by the
180187
* controller for the host */
181-
tr_debug("ACI_HAL_SET_TX_POWER_LEVEL\r\n");
182188
aciSetTxPowerLevel();
183189
break;
184190

185191

186192
case ACI_HAL_SET_TX_POWER_LEVEL:
187-
tr_debug("Tx Power Level set\r\n");
193+
tr_debug("Tx Power Level set");
188194
//signal_reset_sequence_done();
189195
HciSetEventMaskCmd((uint8_t *) hciEventMask);
190196
break;
@@ -323,7 +329,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
323329
break;
324330

325331
default:
326-
tr_debug("Complete Event in reset seq with unknown opcode =0x%4X\r\n", opcode);
332+
tr_info("Complete Event in reset seq with unknown opcode =0x%4X", opcode);
327333
break;
328334
}
329335
} else if (*pMsg == HCI_CMD_STATUS_EVT) {
@@ -335,7 +341,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
335341
pMsg++;
336342
pMsg++; /* skip num packets */
337343
BSTREAM_TO_UINT16(opcode, pMsg);
338-
tr_debug("Command Status event, status:%d, opcode=0x%4X\r\n", status, opcode);
344+
tr_info("Command Status event, status:%d, opcode=0x%4X", status, opcode);
339345
} else {
340346
/**
341347
* vendor specific event
@@ -344,9 +350,9 @@ class HCIDriver : public cordio::CordioHCIDriver {
344350
/* parse parameters */
345351
pMsg += HCI_EVT_HDR_LEN;
346352
BSTREAM_TO_UINT16(opcode, pMsg);
347-
tr_debug("Vendor specific event, opcode=0x%4X\r\n", opcode);
353+
tr_debug("Vendor specific event, opcode=0x%4X", opcode);
348354
} else {
349-
tr_debug("Unknown event %d!\r\n", pMsg[0]);
355+
tr_info("Unknown event %d!", pMsg[0]);
350356
}
351357
}
352358
}
@@ -453,6 +459,15 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
453459
init_debug();
454460
stm32wb_reset();
455461
transport_init();
462+
463+
WirelessFwInfo_t wireless_info_instance;
464+
WirelessFwInfo_t *p_wireless_info = &wireless_info_instance;
465+
if (SHCI_GetWirelessFwInfo(p_wireless_info) != SHCI_Success) {
466+
tr_info("SHCI_GetWirelessFwInfo error");
467+
} else {
468+
tr_info("WIRELESS COPROCESSOR FW VERSION ID = %d.%d.%d", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub);
469+
tr_info("WIRELESS COPROCESSOR FW STACK TYPE = %d", p_wireless_info->StackType);
470+
}
456471
}
457472
}
458473

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

@@ -526,49 +541,41 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
526541
// type 02 ACL DATA
527542
// type 03 SCO Voice (not supported)
528543
// type 04 event - uplink (not suported)
529-
#if (PRINT_HCI_DATA == 1)
530-
tr_debug("mbox_write type:%d, len:%d\r\n", type, len);
531-
#endif
544+
tr_debug("mbox_write type:%d, len:%d", type, len);
532545
/* TO DO : MANAGE ACL DATA CASE in separate buffer */
533546
switch (type) {
534547
case 1://BLE command
535548
bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd
536549
memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len);
537-
#if (PRINT_HCI_DATA == 1)
538550
/* We're tracing here the command, after copy in shared mem but before
539551
* * M0 trigger. */
540-
tr_debug("TX>> BLE CMD: ");
552+
tr_info("TX>> BLE CMD");
541553
/* Trace the buffer including Type (+1 on lngth) */
542-
tr_debug("Type %2X ", bleCmdBuf->cmdserial.type);
543-
tr_debug("Cmd %4X ", bleCmdBuf->cmdserial.cmd.cmdcode);
544-
tr_debug("Len %2X ", bleCmdBuf->cmdserial.cmd.plen);
545-
tr_debug("Payload ");
554+
tr_debug(" Type %#x", bleCmdBuf->cmdserial.type);
555+
tr_debug(" Cmd %#x", bleCmdBuf->cmdserial.cmd.cmdcode);
556+
tr_debug(" Len %#x", bleCmdBuf->cmdserial.cmd.plen);
557+
#if (PRINT_HCI_DATA)
546558
for (uint8_t i = 0; i < bleCmdBuf->cmdserial.cmd.plen; i++) {
547-
tr_debug("%2X ", *(((uint8_t *)&bleCmdBuf->cmdserial.cmd.payload) + i));
559+
tr_debug(" %02X", *(((uint8_t *)&bleCmdBuf->cmdserial.cmd.payload) + i));
548560
}
549-
tr_debug("\r\n");
550561
#endif
551562
TL_BLE_SendCmd(NULL, 0); // unused parameters for now
552563
break;
553564
case 2://ACL DATA
554565
if (!acl_data_wait()) {
555-
#if (PRINT_HCI_DATA == 1)
556-
tr_debug("ERROR: previous ACL message not ACK'd\r\n");
557-
#endif
566+
tr_info("ERROR: previous ACL message not ACK'd");
558567
/* return number of bytes sent, 0 in this error case */
559568
return 0;
560569
}
561570
TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(aclDataBuffer + sizeof(TL_PacketHeader_t));
562571
aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd
563572
memcpy(aclDataBuffer + + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len);
564573
TL_BLE_SendAclData(NULL, 0); // unused parameters for now
565-
#if (PRINT_HCI_DATA == 1)
566-
tr_debug(" TX>> BLE ACL: ");
567-
/* Trace the buffer for debug purpose */
574+
tr_info("TX>> BLE ACL");
575+
#if (PRINT_HCI_DATA)
568576
for (uint8_t i = 0; i < len + 1 + 8; i++) {
569-
tr_debug("%2X ", *(((uint8_t *) aclDataBuffer) + i));
577+
tr_debug(" %02x", *(((uint8_t *) aclDataBuffer) + i));
570578
}
571-
tr_debug("\r\n");
572579
#endif
573580
break;
574581
}
@@ -712,7 +719,7 @@ static void evt_received(TL_EvtPacket_t *hcievt)
712719
break;
713720
default:
714721
// should not happen - let's block to check
715-
tr_error("BLE TL evt_received, wrong type:%d \r\n");
722+
tr_error("BLE TL evt_received, wrong type:%d", hcievt->evtserial.type);
716723
break;
717724
}
718725

@@ -795,7 +802,7 @@ static bool sysevt_check(void)
795802

796803
static void syscmd_status_not(SHCI_TL_CmdStatus_t status)
797804
{
798-
tr_debug("syscmd_status_not, status:%d\r\n", status);
805+
tr_debug("syscmd_status_not, status:%d", status);
799806
return;
800807
}
801808

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

@@ -832,9 +839,9 @@ void shci_register_io_bus(tSHciIO *fops)
832839
*/
833840
static void init_debug(void)
834841
{
835-
tr_debug("WB init_debug: ");
836842
/* In case of MBED debug profile, configure debugger support */
837843
#if (defined(MBED_DEBUG) || (CFG_DEBUGGER_SUPPORTED == 1))
844+
tr_info("init_debug ENABLED");
838845
/**
839846
* Keep debugger enabled while in any low power mode
840847
*/
@@ -847,7 +854,7 @@ static void init_debug(void)
847854
LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48);
848855

849856
#else
850-
tr_debug("DISABLED\r\n");
857+
tr_info("init_debug DISABLED");
851858

852859
GPIO_InitTypeDef gpio_config = {0};
853860

@@ -883,7 +890,7 @@ bool get_bd_address(uint8_t *bd_addr)
883890
udn = LL_FLASH_GetUDN();
884891

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

888895
company_id = LL_FLASH_GetSTCompanyID();
889896
device_id = LL_FLASH_GetDeviceID();
@@ -902,7 +909,7 @@ bool get_bd_address(uint8_t *bd_addr)
902909
memcpy(bd_addr, ((OTP_ID0_t *)otp_addr)->bd_address, CONFIG_DATA_PUBADDR_LEN);
903910
bd_found = false;
904911
} else {
905-
tr_debug("Cannot find BD ADDRESS to program - will leave hw default\r\n");
912+
tr_debug("Cannot find Bluetooth Device ADDRESS to program - will leave hw default");
906913
bd_found = true;
907914
}
908915
}

targets/TARGET_STM/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ This table summarizes the STM32Cube versions currently used :
2424
| L1 | 1.8.1 | https://github.com/STMicroelectronics/STM32CubeL1 |
2525
| L4 | 1.11.0 | https://github.com/STMicroelectronics/STM32CubeL4 |
2626
| L5 | 1.1.0 | https://github.com/STMicroelectronics/STM32CubeL5 |
27-
| WB | 1.0.0 | https://github.com/STMicroelectronics/STM32CubeWB |
27+
| WB | 1.4.0 | https://github.com/STMicroelectronics/STM32CubeWB |

0 commit comments

Comments
 (0)