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");
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"
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/* *****************************************************************************
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 }
@@ -500,7 +506,7 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
500506 /* At this stage, we'll need to wait for ready event,
501507 * passed thru TL_SYS_EvtReceived */
502508 if (!sysevt_wait ()) {
503- tr_debug (" ERROR booting WB controler\r\n " );
509+ tr_info (" ERROR booting WB controler" );
504510 return ;
505511 }
506512
@@ -526,49 +532,41 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
526532 // type 02 ACL DATA
527533 // type 03 SCO Voice (not supported)
528534 // 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
535+ tr_debug (" mbox_write type:%d, len:%d" , type, len);
532536 /* TO DO : MANAGE ACL DATA CASE in separate buffer */
533537 switch (type) {
534538 case 1 :// BLE command
535539 bleCmdBuf->cmdserial .type = type; // for now this param is overwritten in TL_BLE_SendCmd
536540 memcpy ((void *) &bleCmdBuf->cmdserial .cmd , pData, len);
537- #if (PRINT_HCI_DATA == 1)
538541 /* We're tracing here the command, after copy in shared mem but before
539542 * * M0 trigger. */
540- tr_debug (" TX>> BLE CMD: " );
543+ tr_info (" TX>> BLE CMD" );
541544 /* 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 " );
545+ tr_debug (" Type %#x " , bleCmdBuf->cmdserial .type );
546+ tr_debug (" Cmd %#x " , bleCmdBuf->cmdserial .cmd .cmdcode );
547+ tr_debug (" Len %#x " , bleCmdBuf->cmdserial .cmd .plen );
548+ # if (PRINT_HCI_DATA)
546549 for (uint8_t i = 0 ; i < bleCmdBuf->cmdserial .cmd .plen ; i++) {
547- tr_debug (" %2X " , *(((uint8_t *)&bleCmdBuf->cmdserial .cmd .payload ) + i));
550+ tr_debug (" %02X " , *(((uint8_t *)&bleCmdBuf->cmdserial .cmd .payload ) + i));
548551 }
549- tr_debug (" \r\n " );
550552#endif
551553 TL_BLE_SendCmd (NULL , 0 ); // unused parameters for now
552554 break ;
553555 case 2 :// ACL DATA
554556 if (!acl_data_wait ()) {
555- #if (PRINT_HCI_DATA == 1)
556- tr_debug (" ERROR: previous ACL message not ACK'd\r\n " );
557- #endif
557+ tr_info (" ERROR: previous ACL message not ACK'd" );
558558 /* return number of bytes sent, 0 in this error case */
559559 return 0 ;
560560 }
561561 TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(aclDataBuffer + sizeof (TL_PacketHeader_t));
562562 aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd
563563 memcpy (aclDataBuffer + + sizeof (TL_PacketHeader_t) + sizeof (type), pData, len);
564564 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 */
565+ tr_info (" TX>> BLE ACL" );
566+ #if (PRINT_HCI_DATA)
568567 for (uint8_t i = 0 ; i < len + 1 + 8 ; i++) {
569- tr_debug (" %2X " , *(((uint8_t *) aclDataBuffer) + i));
568+ tr_debug (" %02x " , *(((uint8_t *) aclDataBuffer) + i));
570569 }
571- tr_debug (" \r\n " );
572570#endif
573571 break ;
574572 }
@@ -712,7 +710,7 @@ static void evt_received(TL_EvtPacket_t *hcievt)
712710 break ;
713711 default :
714712 // should not happen - let's block to check
715- tr_error (" BLE TL evt_received, wrong type:%d \r\n " );
713+ tr_error (" BLE TL evt_received, wrong type:%d" , hcievt-> evtserial . type );
716714 break ;
717715 }
718716
@@ -795,7 +793,7 @@ static bool sysevt_check(void)
795793
796794static void syscmd_status_not (SHCI_TL_CmdStatus_t status)
797795{
798- tr_debug (" syscmd_status_not, status:%d\r\n " , status);
796+ tr_debug (" syscmd_status_not, status:%d" , status);
799797 return ;
800798}
801799
@@ -816,7 +814,7 @@ void shci_cmd_resp_wait(uint32_t timeout)
816814{
817815 /* TO DO: manage timeouts if we can return an error */
818816 if (sys_resp_sem.wait (timeout) < 1 ) {
819- tr_error (" shci_cmd_resp_wait timed out\r\n " );
817+ tr_error (" shci_cmd_resp_wait timed out" );
820818 }
821819}
822820
@@ -832,9 +830,9 @@ void shci_register_io_bus(tSHciIO *fops)
832830 */
833831static void init_debug (void )
834832{
835- tr_debug (" WB init_debug: " );
836833 /* In case of MBED debug profile, configure debugger support */
837834#if (defined(MBED_DEBUG) || (CFG_DEBUGGER_SUPPORTED == 1))
835+ tr_info (" init_debug ENABLED" );
838836 /* *
839837 * Keep debugger enabled while in any low power mode
840838 */
@@ -847,7 +845,7 @@ static void init_debug(void)
847845 LL_C2_EXTI_EnableIT_32_63 (LL_EXTI_LINE_48);
848846
849847#else
850- tr_debug ( " DISABLED\r\n " );
848+ tr_info ( " init_debug DISABLED" );
851849
852850 GPIO_InitTypeDef gpio_config = {0 };
853851
@@ -883,7 +881,7 @@ bool get_bd_address(uint8_t *bd_addr)
883881 udn = LL_FLASH_GetUDN ();
884882
885883 if (udn != 0xFFFFFFFF ) {
886- tr_debug (" Found UDN: 0x%8lX \r\n " , udn);
884+ tr_info (" Found Unique Device Number: %#06x " , udn);
887885
888886 company_id = LL_FLASH_GetSTCompanyID ();
889887 device_id = LL_FLASH_GetDeviceID ();
@@ -902,7 +900,7 @@ bool get_bd_address(uint8_t *bd_addr)
902900 memcpy (bd_addr, ((OTP_ID0_t *)otp_addr)->bd_address , CONFIG_DATA_PUBADDR_LEN);
903901 bd_found = false ;
904902 } else {
905- tr_debug (" Cannot find BD ADDRESS to program - will leave hw default\r\n " );
903+ tr_debug (" Cannot find Bluetooth Device ADDRESS to program - will leave hw default" );
906904 bd_found = true ;
907905 }
908906 }
0 commit comments