From fc1328783795c83cbcac30bf80bb2cc68b3dd272 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Dec 2018 23:27:29 +0700 Subject: [PATCH 1/2] clean up --- .../components/libraries/bootloader_dfu/dfu_transport_ble.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index c88a24c..665193e 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -741,7 +741,6 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) case BLE_GAP_EVT_CONNECTED: m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; m_is_advertising = false; - led_state(STATE_BLE_CONNECTED); break; case BLE_GAP_EVT_DISCONNECTED: @@ -751,8 +750,6 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) m_direct_adv_cnt = APP_DIRECTED_ADV_TIMEOUT; - led_state(STATE_BLE_DISCONNECTED); - err_code = sd_ble_gatts_sys_attr_get(m_conn_handle, sys_attr, &sys_attr_len, From 5c38bc89576d8943fb3b6a5f2354643794873700 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 20 Dec 2018 00:50:14 +0700 Subject: [PATCH 2/2] fix issue nrf52840 not reset properly when upgrading bootloader+sd combo - root cause tusb_task()/cdc task is called when usb is not inited (in case of sd upgrade) --- Makefile | 2 +- .../components/libraries/bootloader_dfu/bootloader.c | 5 +++-- src/usb/usb.c | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index dc5a0e5..1f2cdc3 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION) -RELEASE_DIR = bin/$(BOARD)/$(SD_VERSION) +RELEASE_DIR = bin/$(BOARD) MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION)" diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 72d8d1b..cf9072e 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -128,8 +128,9 @@ static void wait_for_events(void) app_sched_execute(); #ifdef NRF52840_XXAA - // usb is not enabled in OTA - if ( !is_ota() ) + // skip if usb is not inited ( e.g OTA / finializing sd/bootloader ) + extern bool usb_inited(void); + if ( usb_inited() ) { tusb_task(); tud_cdc_write_flush(); diff --git a/src/usb/usb.c b/src/usb/usb.c index f49e6c0..aaebdf4 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -65,8 +65,20 @@ extern void tusb_hal_nrf_power_event(uint32_t event); //------------- IMPLEMENTATION -------------// +static bool _inited = false; + +bool usb_inited(void) +{ + return _inited; +} + void usb_init(bool cdc_only) { + // skipped if already inited + if ( _inited ) return; + + _inited = true; + // USB power may already be ready at this time -> no event generated // We need to invoke the handler based on the status initially uint32_t usb_reg;