diff options
author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2024-05-23 22:08:12 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-10-07 11:06:57 +1100 |
commit | 5ae622ef7b31881cb38b56baa66d8aec3d132cf9 (patch) | |
tree | 3f1db2da07a00a10e7d1c54b4054bfdd5c25b2f7 /shared | |
parent | 641f60045f8014ad480e4297b982753edcb5b5c6 (diff) | |
download | micropython-5ae622ef7b31881cb38b56baa66d8aec3d132cf9.tar.gz micropython-5ae622ef7b31881cb38b56baa66d8aec3d132cf9.zip |
esp32: Add automatic bootloader handling for S2 and S3.
Enables support for the ESP standard DTR/RTS based reboot to bootloader.
Switches from OTG to Serial/Jtag mode to workaround issue discussed
in: https://github.com/espressif/arduino-esp32/issues/6762
Signed-off-by: Andrew Leech <andrew@alelec.net>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/tinyusb/mp_usbd_cdc.c | 23 | ||||
-rw-r--r-- | shared/tinyusb/mp_usbd_cdc.h | 6 |
2 files changed, 27 insertions, 2 deletions
diff --git a/shared/tinyusb/mp_usbd_cdc.c b/shared/tinyusb/mp_usbd_cdc.c index 0fbecb0a86..b4151f685c 100644 --- a/shared/tinyusb/mp_usbd_cdc.c +++ b/shared/tinyusb/mp_usbd_cdc.c @@ -138,9 +138,12 @@ void tud_sof_cb(uint32_t frame_count) { #endif -#if MICROPY_HW_ENABLE_USBDEV && (MICROPY_HW_USB_CDC_1200BPS_TOUCH || MICROPY_HW_USB_CDC) +#if MICROPY_HW_ENABLE_USBDEV && ( \ + MICROPY_HW_USB_CDC_1200BPS_TOUCH || \ + MICROPY_HW_USB_CDC || \ + MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER) -#if MICROPY_HW_USB_CDC_1200BPS_TOUCH +#if MICROPY_HW_USB_CDC_1200BPS_TOUCH || MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER static mp_sched_node_t mp_bootloader_sched_node; static void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) { @@ -149,6 +152,13 @@ static void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) { } #endif +#if MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER +static struct { + bool dtr : 1; + bool rts : 1; +} prev_line_state = {0}; +#endif + void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { #if MICROPY_HW_USB_CDC && !MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC if (dtr) { @@ -159,6 +169,15 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { tud_sof_cb_enable(true); } #endif + #if MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER + if (dtr && !rts) { + if (prev_line_state.rts && !prev_line_state.dtr) { + mp_sched_schedule_node(&mp_bootloader_sched_node, usbd_cdc_run_bootloader_task); + } + } + prev_line_state.rts = rts; + prev_line_state.dtr = dtr; + #endif #if MICROPY_HW_USB_CDC_1200BPS_TOUCH if (dtr == false && rts == false) { // Device is disconnected. diff --git a/shared/tinyusb/mp_usbd_cdc.h b/shared/tinyusb/mp_usbd_cdc.h index 648cf12881..8d37a77315 100644 --- a/shared/tinyusb/mp_usbd_cdc.h +++ b/shared/tinyusb/mp_usbd_cdc.h @@ -31,6 +31,12 @@ #define MICROPY_HW_USB_CDC_TX_TIMEOUT (500) #endif +// This is typically only enabled on esp32 +// parts which have an internal usb peripheral. +#ifndef MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER +#define MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER (0) +#endif + uintptr_t mp_usbd_cdc_poll_interfaces(uintptr_t poll_flags); void tud_cdc_rx_cb(uint8_t itf); mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len); |