Skip to content

Commit

Permalink
fix issue nrf52840 not reset properly when upgrading bootloader+sd combo
Browse files Browse the repository at this point in the history
- root cause tusb_task()/cdc task is called when usb is not inited (in
case of sd upgrade)
  • Loading branch information
hathach committed Dec 19, 2018
1 parent fc13287 commit 5c38bc8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
5 changes: 3 additions & 2 deletions lib/sdk11/components/libraries/bootloader_dfu/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions src/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5c38bc8

Please sign in to comment.