Skip to content

Commit

Permalink
ports/nrf: Update tinyusb integration.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl committed Apr 19, 2024
1 parent 864ac8f commit f62fa46
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
22 changes: 22 additions & 0 deletions ports/nrf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ INC += -I./modules/ble
INC += -I./modules/board
INC += -I./modules/nrf
INC += -I../../shared/readline
INC += -I../../shared/tinyusb
INC += -I./drivers/bluetooth
INC += -I./drivers
INC += -I../../lib/nrfx/
Expand Down Expand Up @@ -186,6 +187,7 @@ SRC_SHARED_C += $(addprefix shared/,\
runtime/sys_stdio_mphal.c \
runtime/interrupt_char.c \
tinyusb/mp_cdc_common.c \
tinyusb/mp_usbd.c \
timeutils/timeutils.c \
)

Expand Down Expand Up @@ -259,6 +261,26 @@ SRC_C += $(addprefix lib/tinyusb/src/,\
portable/nordic/nrf5x/dcd_nrf5x.c \
)

# Log level is mapped to TUSB DEBUG option
ifneq ($(TUSB_DEBUG_LOG),)
#CMAKE_DEFSYM += -DLOG=$(LOG)
CFLAGS += -DCFG_TUSB_DEBUG=$(TUSB_DEBUG_LOG)
endif

# Logger: default is uart, can be set to rtt or swo
# ifneq ($(TUSB_DEBUG_LOGGER),)
# CMAKE_DEFSYM += -DLOGGER=$(TUSB_DEBUG_LOGGER)
# endif

ifeq ($(TUSB_DEBUG_LOGGER),rtt)
CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
RTT_SRC = lib/tinyusb/lib/SEGGER_RTT
INC += -I$(TOP)/$(RTT_SRC)/RTT
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
else ifeq ($(TUSB_DEBUG_LOGGER),swo)
CFLAGS += -DLOGGER_SWO
endif

endif

DRIVERS_SRC_C += $(addprefix modules/,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@
#define CFG_TUD_CDC_RX_BUFSIZE (64)
#define CFG_TUD_CDC_TX_BUFSIZE (64)


#define CFG_TUSB_DEBUG 3
//extern int CFG_TUSB_DEBUG_PRINTF(const char *format, ...);

// extern void debugger_write(void * fhdl, const char *buf, size_t count);
// static const mp_print_t debugger_print = {NULL, debugger_write};
// #define CFG_TUSB_DEBUG_PRINTF(...) // mp_printf(&debugger_print, __VA_ARGS__)


#endif // MICROPY_INCLUDED_NRF_TUSB_CONFIG_H
11 changes: 9 additions & 2 deletions ports/nrf/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,15 @@ long unsigned int rng_generate_random_word(void);
#ifndef MICROPY_HW_USB_CDC_TX_TIMEOUT
#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500)
#endif
#include "device/usbd.h"
#define MICROPY_HW_USBDEV_TASK_HOOK extern void tud_task(void); tud_task();
// Device configuration

#define CFG_TUSB_MCU OPT_MCU_NRF5X
#define CFG_TUSB_MEM_SECTION
#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
#define CFG_TUD_ENDOINT0_SIZE (64)

// #include "device/usbd.h"
#define MICROPY_HW_USBDEV_TASK_HOOK extern void mp_usbd_task(void); mp_usbd_task();
#else
#define MICROPY_HW_USBDEV_TASK_HOOK ;
#endif
Expand Down

0 comments on commit f62fa46

Please sign in to comment.