Fix upload over USB CDC (USB serial must be set to 0)

This commit is contained in:
me-no-dev 2021-04-05 20:24:46 +03:00
parent aeb4a13aad
commit 425619dfea
3 changed files with 34 additions and 12 deletions

View File

@ -25,6 +25,8 @@ esp32s2.upload.tool=esptool_py
esp32s2.upload.maximum_size=1310720
esp32s2.upload.maximum_data_size=327680
esp32s2.upload.flags=
esp32s2.upload.use_1200bps_touch=true
esp32s2.upload.wait_for_upload_port=true
esp32s2.serial.disableDTR=false
esp32s2.serial.disableRTS=false
@ -684,6 +686,8 @@ feathers2.upload.tool=esptool_py
feathers2.upload.maximum_size=1310720
feathers2.upload.maximum_data_size=327680
feathers2.upload.flags=
feathers2.upload.use_1200bps_touch=true
feathers2.upload.wait_for_upload_port=true
feathers2.serial.disableDTR=false
feathers2.serial.disableRTS=false
@ -805,6 +809,8 @@ pros2.upload.tool=esptool_py
pros2.upload.maximum_size=1310720
pros2.upload.maximum_data_size=327680
pros2.upload.flags=
pros2.upload.use_1200bps_touch=true
pros2.upload.wait_for_upload_port=true
pros2.serial.disableDTR=false
pros2.serial.disableRTS=false
@ -982,6 +988,8 @@ micros2.upload.tool=esptool_py
micros2.upload.maximum_size=1310720
micros2.upload.maximum_data_size=327680
micros2.upload.flags=
micros2.upload.use_1200bps_touch=true
micros2.upload.wait_for_upload_port=true
micros2.serial.disableDTR=false
micros2.serial.disableRTS=false
@ -1797,6 +1805,8 @@ sparkfun_esp32s2_thing_plus.upload.tool=esptool_py
sparkfun_esp32s2_thing_plus.upload.maximum_size=1310720
sparkfun_esp32s2_thing_plus.upload.maximum_data_size=327680
sparkfun_esp32s2_thing_plus.upload.flags=
sparkfun_esp32s2_thing_plus.upload.use_1200bps_touch=true
sparkfun_esp32s2_thing_plus.upload.wait_for_upload_port=true
sparkfun_esp32s2_thing_plus.serial.disableDTR=false
sparkfun_esp32s2_thing_plus.serial.disableRTS=false
@ -3020,6 +3030,8 @@ adafruit_metro_esp32s2.upload.tool=esptool_py
adafruit_metro_esp32s2.upload.maximum_size=1310720
adafruit_metro_esp32s2.upload.maximum_data_size=327680
adafruit_metro_esp32s2.upload.flags=
adafruit_metro_esp32s2.upload.use_1200bps_touch=true
adafruit_metro_esp32s2.upload.wait_for_upload_port=true
adafruit_metro_esp32s2.serial.disableDTR=false
adafruit_metro_esp32s2.serial.disableRTS=false
@ -3167,6 +3179,8 @@ adafruit_magtag29_esp32s2.upload.tool=esptool_py
adafruit_magtag29_esp32s2.upload.maximum_size=1310720
adafruit_magtag29_esp32s2.upload.maximum_data_size=327680
adafruit_magtag29_esp32s2.upload.flags=
adafruit_magtag29_esp32s2.upload.use_1200bps_touch=true
adafruit_magtag29_esp32s2.upload.wait_for_upload_port=true
adafruit_magtag29_esp32s2.serial.disableDTR=false
adafruit_magtag29_esp32s2.serial.disableRTS=false

View File

@ -198,16 +198,20 @@ void USBCDC::_onLineState(bool _dtr, bool _rts){
void USBCDC::_onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _parity, uint8_t _data_bits){
if(bit_rate != _bit_rate || data_bits != _data_bits || stop_bits != _stop_bits || parity != _parity){
bit_rate = _bit_rate;
data_bits = _data_bits;
stop_bits = _stop_bits;
parity = _parity;
arduino_usb_cdc_event_data_t p = {0};
p.line_coding.bit_rate = bit_rate;
p.line_coding.data_bits = data_bits;
p.line_coding.stop_bits = stop_bits;
p.line_coding.parity = parity;
arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_LINE_CODING_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY);
if(bit_rate == 9600 && _bit_rate == 1200){
usb_persist_restart(RESTART_BOOTLOADER);
} else {
bit_rate = _bit_rate;
data_bits = _data_bits;
stop_bits = _stop_bits;
parity = _parity;
arduino_usb_cdc_event_data_t p = {0};
p.line_coding.bit_rate = bit_rate;
p.line_coding.data_bits = data_bits;
p.line_coding.stop_bits = stop_bits;
p.line_coding.parity = parity;
arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_LINE_CODING_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY);
}
}
}

View File

@ -533,6 +533,9 @@ static void IRAM_ATTR usb_persist_shutdown_handler(void)
//USB CDC Download
if (usb_persist_enabled) {
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
} else {
periph_module_reset(PERIPH_USB_MODULE);
periph_module_enable(PERIPH_USB_MODULE);
}
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
} else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) {
@ -586,11 +589,12 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
bool usb_did_persist = (USB_WRAP.date.val == USBDC_PERSIST_ENA);
if(usb_did_persist && usb_persist_enabled){
//if(usb_did_persist && usb_persist_enabled){
// Enable USB/IO_MUX peripheral reset, if coming from persistent reboot
REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_IO_MUX_RESET_DISABLE);
REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_RESET_DISABLE);
} else {
//} else
if(!usb_did_persist || !usb_persist_enabled){
// Reset USB module
periph_module_reset(PERIPH_USB_MODULE);
periph_module_enable(PERIPH_USB_MODULE);