/ports/esp32/usb_serial_jtag.c usb_serial_jtag_isr_handler bug
`static void usb_serial_jtag_isr_handler(void *arg) {
uint32_t flags = usb_serial_jtag_ll_get_intsts_mask();
if (flags & USB_SERIAL_JTAG_INTR_SOF) {
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF);
}
if (flags & USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT) {
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
/*
The commented part has bugs.
Assume the PC sends data very fast, such as 500 bytes (can be simulated by pasting),
After multiple interrupts, stdin_ringbuf will be full, that is, req_len = 0 below.
Since the interrupt has been cleared, the USB buffer cannot be read out,
interrupts will never happen again, causing the USB to fail and the link to eventually break.
Simply changing to
usb_serial_jtag_ll_read_rxfifo(rx_buf, USB_SERIAL_JTAG_BUF_SIZE)
can ensure normal operation. Of course, poll and other methods can also be used to fix this bug.
*/
//size_t req_len = ringbuf_free(&stdin_ringbuf);
//if (req_len > USB_SERIAL_JTAG_BUF_SIZE) {
// req_len = USB_SERIAL_JTAG_BUF_SIZE;
//}
//size_t len = usb_serial_jtag_ll_read_rxfifo(rx_buf, req_len);
size_t len = usb_serial_jtag_ll_read_rxfifo(rx_buf, USB_SERIAL_JTAG_BUF_SIZE);
for (size_t i = 0; i < len; ++i) {
if (rx_buf[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt();
} else {
ringbuf_put(&stdin_ringbuf, rx_buf[i]);
}
}
mp_hal_wake_main_task_from_isr();
}
}
`
Unable to Flash MicroPython on ESP32-C3
Hello,
I have built firmware.bin using the following commands with a small modification, at the last step while executing "make" command, it fails while compiling "usb_serial_jtag.c" because at the line it is expecting the value "USB_SERIAL_JTAG_INTR_SOF" instead of "ETS_USB_SERIAL_JTAG_INTR_SOURCE":
#!/bin/bash
export BUILD_DIR=$(pwd)
echo "--- CLONING MICROPYTHON ---"
git clone --depth 1 https://github.com/micropython/micropython.git
echo "--- CLONING ESP-IDF ---"
cd $BUILD_DIR/micropython/
git clone -b v4.3.2 --recursive https://github.com/espressif/esp-idf.git
echo "--- INSTALL ESP-IDF ---"
cd $BUILD_DIR/micropython/esp-idf
./install.sh
. ./export.sh
echo "--- MPY-CROSS ---"
cd $BUILD_DIR/micropython/mpy-cross
make
echo "--- ESP32 SUBMODULES ---"
cd $BUILD_DIR/micropython/ports/esp32
make submodules
echo "--- PATCH MAKEFILE ---"
cp $BUILD_DIR/micropython/ports/esp32/Makefile $BUILD_DIR/micropython/ports/esp32/MakefileOld
echo "BOARD = GENERIC_C3_USB" > $BUILD_DIR/micropython/ports/esp32/Makefile
cat $BUILD_DIR/micropython/ports/esp32/MakefileOld >> $BUILD_DIR/micropython/ports/esp32/Makefile
echo "--- MAKE ---"
make
The binary file "firmware.bin" is generated and it is written to ESP32-C3 successfully. However, while flashing it gives following error:
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x1 (POWERON),boot:0xe (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0xf18
load:0x403ce000,len:0x6cc
load:0x403d0000,len:0x292c
entry 0x403ce000
And, if I try to write & flash binary from micropython site(https://micropython.org/download/esp32c3-usb/) it works without any issue. Please advise, what is wrong above?