Skip to content

Commit

Permalink
rp2: Allow disabling USB via MICROPY_HW_ENABLE_USBDEV config.
Browse files Browse the repository at this point in the history
Previously, setting MICROPY_HW_ENABLE_USBDEV to 0 caused build errors.  The
change affects the nrf and samd ports as well, so MICROPY_HW_ENABLE_USBDEV
had to be explicitly enabled there.

The configuration options MICROPY_HW_ENABLE_USBDEV and
MICROPY_HW_ENABLE_UART_REPL are independent, and can be enabled or disabled
by a board.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
robert-hh authored and dpgeorge committed Mar 20, 2023
1 parent a2b31f9 commit be686e6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions ports/nrf/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#if MICROPY_HW_USB_CDC_1200BPS_TOUCH
#define MICROPY_HW_ENABLE_USBDEV (1)
#define MICROPY_ENABLE_SCHEDULER (1)
#define MICROPY_SCHEDULER_STATIC_NODES (1)
#endif
Expand Down
4 changes: 4 additions & 0 deletions ports/rp2/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@

// Board and hardware specific configuration
#define MICROPY_HW_MCU_NAME "RP2040"
#ifndef MICROPY_HW_ENABLE_UART_REPL
#define MICROPY_HW_ENABLE_UART_REPL (0) // useful if there is no USB
#endif
#ifndef MICROPY_HW_ENABLE_USBDEV
#define MICROPY_HW_ENABLE_USBDEV (1)
#endif

#if MICROPY_HW_ENABLE_USBDEV
// Enable USB-CDC serial port
Expand Down
6 changes: 6 additions & 0 deletions ports/rp2/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* THE SOFTWARE.
*/

#include "py/mpconfig.h"

#if MICROPY_HW_ENABLE_USBDEV

#include "mp_usbd.h"
#include "string.h"
#include "tusb.h"
Expand All @@ -42,3 +46,5 @@ void mp_usbd_port_get_serial_number(char *serial_buf) {
}
serial_buf[hexlen] = 0;
}

#endif
1 change: 1 addition & 0 deletions ports/samd/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#define MICROPY_ENABLE_SCHEDULER (1)
#define MICROPY_SCHEDULER_STATIC_NODES (1)
#define MICROPY_MODULE_WEAK_LINKS (1)
#define MICROPY_HW_ENABLE_USBDEV (1)
#define MICROPY_HW_USB_CDC_1200BPS_TOUCH (1)

// Control over Python builtins
Expand Down
2 changes: 1 addition & 1 deletion shared/tinyusb/mp_cdc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "py/mphal.h"
#include "modmachine.h"

#if MICROPY_HW_USB_CDC_1200BPS_TOUCH
#if MICROPY_HW_USB_CDC_1200BPS_TOUCH && MICROPY_HW_ENABLE_USBDEV

#include "tusb.h"

Expand Down
6 changes: 6 additions & 0 deletions shared/tinyusb/mp_usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#include <stdlib.h>

#include "py/mpconfig.h"

#if MICROPY_HW_ENABLE_USBDEV

#ifndef NO_QSTR
#include "tusb.h" // TinyUSB is not avaiable when running the string preprocessor
#include "device/usbd.h"
Expand All @@ -35,3 +39,5 @@
void usbd_task(void) {
tud_task_ext(0, false);
}

#endif
7 changes: 6 additions & 1 deletion shared/tinyusb/mp_usbd_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
* THE SOFTWARE.
*/

#include "mpconfigport.h"
#include "py/mpconfig.h"

#if MICROPY_HW_ENABLE_USBDEV

#include "tusb.h"
#include "mp_usbd.h"
#include "mp_usbd_internal.h"
Expand Down Expand Up @@ -126,3 +129,5 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
(void)index;
return mp_usbd_desc_cfg_static;
}

#endif

0 comments on commit be686e6

Please sign in to comment.