mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
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>
This commit is contained in:
committed by
Damien George
parent
641f60045f
commit
5ae622ef7b
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user