1
1
/*
2
2
* Copyright (c) 2019 ARM Limited
3
+ * Copyright (c) 2019 STMicroelectronics
3
4
* SPDX-License-Identifier: Apache-2.0
4
5
*
5
6
* Licensed under the Apache License, Version 2.0 (the "License");
26
27
#include " dm_api.h"
27
28
#include " bstream.h"
28
29
#include " hci_mbed_os_adaptation.h"
29
- #include " mbed-trace/ mbed_trace.h"
30
+ #include " mbed_trace.h"
30
31
31
32
/* STM32WB include files */
32
33
#include " stm32wbxx_ll_ipcc.h"
38
39
#include " app_conf.h"
39
40
#include " otp.h"
40
41
42
+ /* mbed trace feature is supported */
43
+ /* ex in mbed_app.json */
44
+ /* "mbed-trace.enable": "1" */
41
45
#define TRACE_GROUP " BLWB"
42
46
43
47
/* *****************************************************************************
61
65
#define MAX_HCI_ACL_PACKET_SIZE (sizeof (TL_PacketHeader_t) + 5 + 251 )
62
66
#define MAX_HACI_EVT_SIZE (255 +5 )
63
67
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
66
74
67
75
/* *****************************************************************************
68
76
* BLE config parameters
@@ -133,58 +141,56 @@ class HCIDriver : public cordio::CordioHCIDriver {
133
141
134
142
/* if event is a command complete event */
135
143
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)
139
146
for (uint8_t i = 0 ; i < 20 ; i++) {
140
- tr_debug (" %2X " , *((uint8_t *)pMsg + i));
147
+ tr_debug (" %02X " , *((uint8_t *)pMsg + i));
141
148
}
142
- tr_debug (" \r\n " );
143
- /* parse parameters */
144
- tr_debug (" HCI_EVT_HDR_LEN=%d\r\n " , HCI_EVT_HDR_LEN);
145
149
#endif
150
+ /* parse parameters */
151
+ tr_debug (" HCI_EVT_HDR_LEN=%d" , HCI_EVT_HDR_LEN);
146
152
pMsg += HCI_EVT_HDR_LEN;
147
153
pMsg++; /* skip num packets */
148
154
BSTREAM_TO_UINT16 (opcode, pMsg);
149
155
pMsg++; /* skip status */
150
156
151
157
/* decode opcode */
158
+ tr_debug (" opcode = %#06x" , opcode);
152
159
switch (opcode) {
153
160
case HCI_OPCODE_RESET:
154
161
/* initialize rand command count */
155
162
randCnt = 0 ;
156
- tr_debug (" WB Reset Received\r\n " );
163
+ tr_info (" WB Reset Received" );
157
164
/* Once reset complete evet is received we need
158
165
* to send a few more commands:
159
166
* Tx power and set bd addr
160
167
*/
161
168
if (get_bd_address (bd_addr)) {
162
169
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 ]);
170
177
} else {
171
- tr_debug (" could not find BDaddr\r\n " );
178
+ tr_info (" could not find BDaddr" );
172
179
/* Skip to next step */
173
180
aciSetTxPowerLevel ();
174
181
}
175
182
break ;
176
183
177
184
case ACI_WRITE_CONFIG_DATA_OPCODE:
178
- tr_debug (" BD address set\r\n " );
185
+ tr_debug (" Bluetooth Device address set" );
179
186
/* set the event mask to control which events are generated by the
180
187
* controller for the host */
181
- tr_debug (" ACI_HAL_SET_TX_POWER_LEVEL\r\n " );
182
188
aciSetTxPowerLevel ();
183
189
break ;
184
190
185
191
186
192
case ACI_HAL_SET_TX_POWER_LEVEL:
187
- tr_debug (" Tx Power Level set\r\n " );
193
+ tr_debug (" Tx Power Level set" );
188
194
// signal_reset_sequence_done();
189
195
HciSetEventMaskCmd ((uint8_t *) hciEventMask);
190
196
break ;
@@ -323,7 +329,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
323
329
break ;
324
330
325
331
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);
327
333
break ;
328
334
}
329
335
} else if (*pMsg == HCI_CMD_STATUS_EVT) {
@@ -335,7 +341,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
335
341
pMsg++;
336
342
pMsg++; /* skip num packets */
337
343
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);
339
345
} else {
340
346
/* *
341
347
* vendor specific event
@@ -344,9 +350,9 @@ class HCIDriver : public cordio::CordioHCIDriver {
344
350
/* parse parameters */
345
351
pMsg += HCI_EVT_HDR_LEN;
346
352
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);
348
354
} else {
349
- tr_debug (" Unknown event %d!\r\n " , pMsg[0 ]);
355
+ tr_info (" Unknown event %d!" , pMsg[0 ]);
350
356
}
351
357
}
352
358
}
@@ -453,6 +459,15 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
453
459
init_debug ();
454
460
stm32wb_reset ();
455
461
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
+ }
456
471
}
457
472
}
458
473
@@ -500,7 +515,7 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
500
515
/* At this stage, we'll need to wait for ready event,
501
516
* passed thru TL_SYS_EvtReceived */
502
517
if (!sysevt_wait ()) {
503
- tr_debug (" ERROR booting WB controler\r\n " );
518
+ tr_info (" ERROR booting WB controler" );
504
519
return ;
505
520
}
506
521
@@ -526,49 +541,41 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
526
541
// type 02 ACL DATA
527
542
// type 03 SCO Voice (not supported)
528
543
// 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);
532
545
/* TO DO : MANAGE ACL DATA CASE in separate buffer */
533
546
switch (type) {
534
547
case 1 :// BLE command
535
548
bleCmdBuf->cmdserial .type = type; // for now this param is overwritten in TL_BLE_SendCmd
536
549
memcpy ((void *) &bleCmdBuf->cmdserial .cmd , pData, len);
537
- #if (PRINT_HCI_DATA == 1)
538
550
/* We're tracing here the command, after copy in shared mem but before
539
551
* * M0 trigger. */
540
- tr_debug (" TX>> BLE CMD: " );
552
+ tr_info (" TX>> BLE CMD" );
541
553
/* 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)
546
558
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));
548
560
}
549
- tr_debug (" \r\n " );
550
561
#endif
551
562
TL_BLE_SendCmd (NULL , 0 ); // unused parameters for now
552
563
break ;
553
564
case 2 :// ACL DATA
554
565
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" );
558
567
/* return number of bytes sent, 0 in this error case */
559
568
return 0 ;
560
569
}
561
570
TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(aclDataBuffer + sizeof (TL_PacketHeader_t));
562
571
aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd
563
572
memcpy (aclDataBuffer + + sizeof (TL_PacketHeader_t) + sizeof (type), pData, len);
564
573
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)
568
576
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));
570
578
}
571
- tr_debug (" \r\n " );
572
579
#endif
573
580
break ;
574
581
}
@@ -712,7 +719,7 @@ static void evt_received(TL_EvtPacket_t *hcievt)
712
719
break ;
713
720
default :
714
721
// 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 );
716
723
break ;
717
724
}
718
725
@@ -795,7 +802,7 @@ static bool sysevt_check(void)
795
802
796
803
static void syscmd_status_not (SHCI_TL_CmdStatus_t status)
797
804
{
798
- tr_debug (" syscmd_status_not, status:%d\r\n " , status);
805
+ tr_debug (" syscmd_status_not, status:%d" , status);
799
806
return ;
800
807
}
801
808
@@ -816,7 +823,7 @@ void shci_cmd_resp_wait(uint32_t timeout)
816
823
{
817
824
/* TO DO: manage timeouts if we can return an error */
818
825
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" );
820
827
}
821
828
}
822
829
@@ -832,9 +839,9 @@ void shci_register_io_bus(tSHciIO *fops)
832
839
*/
833
840
static void init_debug (void )
834
841
{
835
- tr_debug (" WB init_debug: " );
836
842
/* In case of MBED debug profile, configure debugger support */
837
843
#if (defined(MBED_DEBUG) || (CFG_DEBUGGER_SUPPORTED == 1))
844
+ tr_info (" init_debug ENABLED" );
838
845
/* *
839
846
* Keep debugger enabled while in any low power mode
840
847
*/
@@ -847,7 +854,7 @@ static void init_debug(void)
847
854
LL_C2_EXTI_EnableIT_32_63 (LL_EXTI_LINE_48);
848
855
849
856
#else
850
- tr_debug ( " DISABLED\r\n " );
857
+ tr_info ( " init_debug DISABLED" );
851
858
852
859
GPIO_InitTypeDef gpio_config = {0 };
853
860
@@ -883,7 +890,7 @@ bool get_bd_address(uint8_t *bd_addr)
883
890
udn = LL_FLASH_GetUDN ();
884
891
885
892
if (udn != 0xFFFFFFFF ) {
886
- tr_debug (" Found UDN: 0x%8lX \r\n " , udn);
893
+ tr_info (" Found Unique Device Number: %#06x " , udn);
887
894
888
895
company_id = LL_FLASH_GetSTCompanyID ();
889
896
device_id = LL_FLASH_GetDeviceID ();
@@ -902,7 +909,7 @@ bool get_bd_address(uint8_t *bd_addr)
902
909
memcpy (bd_addr, ((OTP_ID0_t *)otp_addr)->bd_address , CONFIG_DATA_PUBADDR_LEN);
903
910
bd_found = false ;
904
911
} 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" );
906
913
bd_found = true ;
907
914
}
908
915
}
0 commit comments