Skip to content

Commit d1fb384

Browse files
committed
update tinyusb, work better with sd
1 parent 765d877 commit d1fb384

5 files changed

Lines changed: 26 additions & 6 deletions

File tree

lib/tinyusb

Submodule tinyusb updated 34 files

ports/nrf/bluetooth/ble_drv.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "ble_drv.h"
3333
#include "nrf_nvic.h"
3434
#include "nrf_sdm.h"
35+
#include "nrf_soc.h"
36+
#include "nrfx_power.h"
3537
#include "py/misc.h"
3638

3739
nrf_nvic_state_t nrf_nvic_state = { 0 };
@@ -89,6 +91,23 @@ void SD_EVT_IRQHandler(void) {
8991
uint32_t evt_id;
9092
while (sd_evt_get(&evt_id) != NRF_ERROR_NOT_FOUND) {
9193
// sd_evt_handler(evt_id);
94+
95+
switch (evt_id) {
96+
// usb power event
97+
case NRF_EVT_POWER_USB_DETECTED:
98+
case NRF_EVT_POWER_USB_POWER_READY:
99+
case NRF_EVT_POWER_USB_REMOVED: {
100+
int32_t usbevt = (evt_id == NRF_EVT_POWER_USB_DETECTED ) ? NRFX_POWER_USB_EVT_DETECTED:
101+
(evt_id == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY :
102+
(evt_id == NRF_EVT_POWER_USB_REMOVED ) ? NRFX_POWER_USB_EVT_REMOVED : -1;
103+
104+
extern void tusb_hal_nrf_power_event (uint32_t event);
105+
tusb_hal_nrf_power_event(usbevt);
106+
}
107+
break;
108+
109+
default: break;
110+
}
92111
}
93112

94113
while (1) {

ports/nrf/bluetooth/bluetooth_common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ $(error Incorrect softdevice set flag)
66
endif
77

88
CFLAGS += -DBLUETOOTH_SD_DEBUG=1
9+
CFLAGS += -DSOFTDEVICE_PRESENT
910

1011
INC += -Ibluetooth/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include
1112
INC += -Ibluetooth/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include/$(MCU_VARIANT)

ports/nrf/supervisor/usb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ extern void tusb_hal_nrf_power_event(uint32_t event);
4343

4444
void init_usb_hardware(void) {
4545

46+
// 2 is max priority (0, 1 are reserved for SD)
47+
NVIC_SetPriority(USBD_IRQn, 2);
48+
4649
// USB power may already be ready at this time -> no event generated
4750
// We need to invoke the handler based on the status initially
4851
uint32_t usb_reg;

supervisor/shared/usb/usb.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,15 @@ void load_serial_number(void) {
5454
}
5555
}
5656

57-
bool _usb_enabled = false;
58-
5957
bool usb_enabled(void) {
60-
return _usb_enabled;
58+
return tusb_inited();
6159
}
6260

6361
void usb_init(void) {
6462
init_usb_hardware();
6563
load_serial_number();
6664

6765
tusb_init();
68-
_usb_enabled = true;
6966

7067
#if MICROPY_KBD_EXCEPTION
7168
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received
@@ -77,7 +74,7 @@ void usb_init(void) {
7774
}
7875

7976
void usb_background(void) {
80-
if (usb_enabled()) {
77+
if (tusb_inited()) {
8178
tud_task();
8279
tud_cdc_write_flush();
8380
}

0 commit comments

Comments
 (0)