summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/rp2/boards/PICO/mpconfigboard.h3
-rw-r--r--ports/rp2/main.c2
-rw-r--r--ports/rp2/mpconfigport.h15
-rw-r--r--ports/rp2/mphalport.c12
-rw-r--r--shared/tinyusb/mp_usbd_descriptor.c4
-rw-r--r--shared/tinyusb/tusb_config.h58
6 files changed, 66 insertions, 28 deletions
diff --git a/ports/rp2/boards/PICO/mpconfigboard.h b/ports/rp2/boards/PICO/mpconfigboard.h
index fb7f8054a..c39bc4d48 100644
--- a/ports/rp2/boards/PICO/mpconfigboard.h
+++ b/ports/rp2/boards/PICO/mpconfigboard.h
@@ -1,6 +1,3 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico"
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
-
-// Enable USB Mass Storage with FatFS filesystem.
-// #define MICROPY_HW_USB_MSC (1)
diff --git a/ports/rp2/main.c b/ports/rp2/main.c
index 8983f0781..fdcdd90d4 100644
--- a/ports/rp2/main.c
+++ b/ports/rp2/main.c
@@ -86,7 +86,9 @@ int main(int argc, char **argv) {
#endif
#if MICROPY_HW_ENABLE_USBDEV
+ #if MICROPY_HW_USB_CDC
bi_decl(bi_program_feature("USB REPL"))
+ #endif
tusb_init();
#endif
diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h
index b58d7bed0..d5e4de7b5 100644
--- a/ports/rp2/mpconfigport.h
+++ b/ports/rp2/mpconfigport.h
@@ -27,20 +27,29 @@
// Options controlling how MicroPython is built, overriding defaults in py/mpconfig.h
#include <stdint.h>
+#include "hardware/flash.h"
#include "hardware/spi.h"
#include "hardware/sync.h"
#include "pico/binary_info.h"
#include "pico/multicore.h"
#include "mpconfigboard.h"
-#if MICROPY_HW_USB_MSC
-#include "hardware/flash.h"
-#endif
// Board and hardware specific configuration
#define MICROPY_HW_MCU_NAME "RP2040"
#define MICROPY_HW_ENABLE_UART_REPL (0) // useful if there is no USB
#define MICROPY_HW_ENABLE_USBDEV (1)
+#if MICROPY_HW_ENABLE_USBDEV
+// Enable USB-CDC serial port
+#ifndef MICROPY_HW_USB_CDC
+#define MICROPY_HW_USB_CDC (1)
+#endif
+// Enable USB Mass Storage with FatFS filesystem.
+#ifndef MICROPY_HW_USB_MSC
+#define MICROPY_HW_USB_MSC (0)
+#endif
+#endif
+
#ifndef MICROPY_CONFIG_ROM_LEVEL
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES)
#endif
diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c
index 6ba234c66..510d486d9 100644
--- a/ports/rp2/mphalport.c
+++ b/ports/rp2/mphalport.c
@@ -39,7 +39,7 @@
#include "lib/cyw43-driver/src/cyw43.h"
#endif
-#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_ENABLE_USBDEV
+#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC
#ifndef MICROPY_HW_STDIN_BUFFER_LEN
#define MICROPY_HW_STDIN_BUFFER_LEN 512
@@ -50,7 +50,7 @@ ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) };
#endif
-#if MICROPY_HW_ENABLE_USBDEV
+#if MICROPY_HW_USB_CDC
uint8_t cdc_itf_pending; // keep track of cdc interfaces which need attention to poll
@@ -91,10 +91,10 @@ void tud_cdc_rx_cb(uint8_t itf) {
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
uintptr_t ret = 0;
- #if MICROPY_HW_ENABLE_USBDEV
+ #if MICROPY_HW_USB_CDC
poll_cdc_interfaces();
#endif
- #if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_ENABLE_USBDEV
+ #if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC
if ((poll_flags & MP_STREAM_POLL_RD) && ringbuf_peek(&stdin_ringbuf) != -1) {
ret |= MP_STREAM_POLL_RD;
}
@@ -108,7 +108,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
// Receive single character
int mp_hal_stdin_rx_chr(void) {
for (;;) {
- #if MICROPY_HW_ENABLE_USBDEV
+ #if MICROPY_HW_USB_CDC
poll_cdc_interfaces();
#endif
@@ -132,7 +132,7 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
mp_uart_write_strn(str, len);
#endif
- #if MICROPY_HW_ENABLE_USBDEV
+ #if MICROPY_HW_USB_CDC
if (tud_cdc_connected()) {
for (size_t i = 0; i < len;) {
uint32_t n = len - i;
diff --git a/shared/tinyusb/mp_usbd_descriptor.c b/shared/tinyusb/mp_usbd_descriptor.c
index 1e9cc9876..3a21baf5b 100644
--- a/shared/tinyusb/mp_usbd_descriptor.c
+++ b/shared/tinyusb/mp_usbd_descriptor.c
@@ -54,8 +54,10 @@ const uint8_t mp_usbd_desc_cfg_static[USBD_STATIC_DESC_LEN] = {
TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_STATIC_MAX, USBD_STR_0, USBD_STATIC_DESC_LEN,
0, USBD_MAX_POWER_MA),
+ #if CFG_TUD_CDC
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD,
USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),
+ #endif
#if CFG_TUD_MSC
TUD_MSC_DESCRIPTOR(USBD_ITF_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
#endif
@@ -83,9 +85,11 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
case USBD_STR_PRODUCT:
desc_str = MICROPY_HW_USB_PRODUCT_FS_STRING;
break;
+ #if CFG_TUD_CDC
case USBD_STR_CDC:
desc_str = MICROPY_HW_USB_CDC_INTERFACE_STRING;
break;
+ #endif
#if CFG_TUD_MSC
case USBD_STR_MSC:
desc_str = MICROPY_HW_USB_MSC_INTERFACE_STRING;
diff --git a/shared/tinyusb/tusb_config.h b/shared/tinyusb/tusb_config.h
index 15e5acf55..71769b67c 100644
--- a/shared/tinyusb/tusb_config.h
+++ b/shared/tinyusb/tusb_config.h
@@ -46,28 +46,40 @@
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE)
+#if MICROPY_HW_USB_CDC
#define CFG_TUD_CDC (1)
+#else
+#define CFG_TUD_CDC (0)
+#endif
+
+#if MICROPY_HW_USB_MSC
+#define CFG_TUD_MSC (1)
+#else
+#define CFG_TUD_MSC (0)
+#endif
+
+// CDC Configuration
+#if CFG_TUD_CDC
#define CFG_TUD_CDC_EP_BUFSIZE (256)
#define CFG_TUD_CDC_RX_BUFSIZE (256)
#define CFG_TUD_CDC_TX_BUFSIZE (256)
+#endif
// MSC Configuration
#if CFG_TUD_MSC
#ifndef MICROPY_HW_USB_MSC_INTERFACE_STRING
#define MICROPY_HW_USB_MSC_INTERFACE_STRING "Board MSC"
#endif
-#define CFG_TUD_MSC (1)
// Set MSC EP buffer size to FatFS block size to avoid partial read/writes (offset arg).
-#define CFG_TUD_MSC_BUFSIZE (MICROPY_FATFS_MAX_SS)
+#define CFG_TUD_MSC_BUFSIZE (MICROPY_FATFS_MAX_SS)
#endif
// Define static descriptor size and interface count based on the above config
-#if CFG_TUD_MSC
-#define USBD_STATIC_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN)
-#else
-#define USBD_STATIC_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
-#endif
+#define USBD_STATIC_DESC_LEN (TUD_CONFIG_DESC_LEN + \
+ (CFG_TUD_CDC ? (TUD_CDC_DESC_LEN) : 0) + \
+ (CFG_TUD_MSC ? (TUD_MSC_DESC_LEN) : 0) \
+ )
#define USBD_STR_0 (0x00)
#define USBD_STR_MANUF (0x01)
@@ -80,27 +92,41 @@
#define USBD_DESC_STR_MAX (20)
+#if CFG_TUD_CDC
#define USBD_ITF_CDC (0) // needs 2 interfaces
-
#define USBD_CDC_EP_CMD (0x81)
#define USBD_CDC_EP_OUT (0x02)
#define USBD_CDC_EP_IN (0x82)
+#endif // CFG_TUD_CDC
#if CFG_TUD_MSC
+// Interface & Endpoint numbers for MSC come after CDC, if it is enabled
+#if CFG_TUD_CDC
#define USBD_ITF_MSC (2)
-#define EPNUM_MSC_OUT (0x03)
-#define EPNUM_MSC_IN (0x83)
-#endif
+#define EPNUM_MSC_OUT (0x03)
+#define EPNUM_MSC_IN (0x83)
+#else
+#define USBD_ITF_MSC (0)
+#define EPNUM_MSC_OUT (0x01)
+#define EPNUM_MSC_IN (0x81)
+#endif // CFG_TUD_CDC
+#endif // CFG_TUD_MSC
/* Limits of statically defined USB interfaces, endpoints, strings */
#if CFG_TUD_MSC
-#define USBD_ITF_STATIC_MAX (3)
+#define USBD_ITF_STATIC_MAX (USBD_ITF_MSC + 1)
#define USBD_STR_STATIC_MAX (USBD_STR_MSC + 1)
-#define USBD_EP_STATIC_MAX (0x04) // ignoring the IN EP flag 0x80
-#else
-#define USBD_ITF_STATIC_MAX (2)
+#define USBD_EP_STATIC_MAX (EPNUM_MSC_OUT + 1)
+#elif CFG_TUD_CDC
+#define USBD_ITF_STATIC_MAX (USBD_ITF_CDC + 1)
#define USBD_STR_STATIC_MAX (USBD_STR_CDC + 1)
-#define USBD_EP_STATIC_MAX (0x03) // ignoring the IN EP flag 0x80
+#define USBD_EP_STATIC_MAX (((EPNUM_CDC_EP_IN)&~TUSB_DIR_IN_MASK) + 1)
+#else // !CFG_TUD_MSC && !CFG_TUD_CDC
+#define USBD_ITF_STATIC_MAX (0)
+#define USBD_STR_STATIC_MAX (0)
+#define USBD_EP_STATIC_MAX (0)
#endif
+#endif // MICROPY_HW_ENABLE_USBDEV
+
#endif // MICROPY_INCLUDED_SHARED_TINYUSB_TUSB_CONFIG_H