rp2: Allow disabling USB via MICROPY_HW_ENABLE_USBDEV config.

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 <damien@micropython.org>
This commit is contained in:
robert-hh 2023-03-18 09:08:08 +01:00 committed by Damien George
parent a2b31f968d
commit be686e634e
7 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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"
@ -42,3 +46,5 @@ void mp_usbd_port_get_serial_number(char *serial_buf) {
}
serial_buf[hexlen] = 0;
}
#endif

View File

@ -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

View File

@ -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"

View File

@ -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"
@ -35,3 +39,5 @@
void usbd_task(void) {
tud_task_ext(0, false);
}
#endif

View File

@ -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"
@ -126,3 +129,5 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
(void)index;
return mp_usbd_desc_cfg_static;
}
#endif