Skip to content

Commit e6cecda

Browse files
LMESTM0xc0170
authored andcommitted
STM32WB: Handle re-init case of transport layer
Issue was seen when running BLE_GAP example from mbed-os-example-ble. In STM32WB, the M0 core cannot be reset except if the whole target is reset. So in case of re-initialization of the BLE stack, the transport layer should not be initialized again. The HCI reset command will do the job.
1 parent d50f6e2 commit e6cecda

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

features/FEATURE_BLE/targets/TARGET_STM/TARGET_NUCLEO_WB55RG/stm32wb_HCIDriver.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
/* activate to add debug traces */
6565
#define PRINT_HCI_DATA 1
6666

67-
6867
/******************************************************************************
6968
* BLE config parameters
7069
******************************************************************************/
@@ -76,6 +75,7 @@ static bool acl_data_wait(void);
7675
static void init_debug( void );
7776
static bool get_bd_address( uint8_t* bd_addr );
7877
static bool sysevt_wait( void);
78+
static bool sysevt_check( void);
7979

8080

8181
namespace ble {
@@ -439,9 +439,14 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
439439
* @see CordioHCITransportDriver::initialize
440440
*/
441441
virtual void initialize() {
442-
init_debug();
443-
stm32wb_reset();
444-
transport_init();
442+
/* Check whether M0 sub-system was started already by
443+
* checking if the system event was already received
444+
* before. If it was not, then go thru all init. */
445+
if(!sysevt_check()) {
446+
init_debug();
447+
stm32wb_reset();
448+
transport_init();
449+
}
445450
}
446451

447452
/**
@@ -750,9 +755,24 @@ static void sysevt_received( void* pdata) {
750755
static bool sysevt_wait( void) {
751756
/* Wait for 10sec max - if not return an error */
752757
if(sys_event_sem.wait(10000) < 1) {
753-
return false;
758+
return false;
759+
} else {
760+
/* release immmediately, now that M0 runs */
761+
sys_event_sem.release();
762+
return true;
763+
}
764+
}
765+
766+
/* returns true if ssyevt was already received, which means M0 core is
767+
* already up and running */
768+
static bool sysevt_check( void) {
769+
/* Check if system is UP and runing already */
770+
if(sys_event_sem.wait(10) < 1) {
771+
return false;
754772
} else {
755-
return true;
773+
/* release immmediately as M0 already runs */
774+
sys_event_sem.release();
775+
return true;
756776
}
757777
}
758778

0 commit comments

Comments
 (0)