Browse Source
Add a new board type for ESP32-C3 revision 3 and up that implement the USB serial/JTAG port on pin 18 and 19. This variant uses the USB serial for programming and console, leaving the UART free. - Pins 18 and 19 are correctly reserved for this variant. Also pins 14-17 are reserved for flash for any ESP32-C3 so they can't be reconfigured anymore to crash the system. - Added usb_serial_jtag.c and .h to implement this interface. - Interface was tested to work correctly together with webrepl. - Interface was tested to work correctly when sending and receiving large files with ampy. - Disconnecting terminal or USB will not hang the system when it's trying to print.pull/7710/head
Patrick Van Oosterwijck
3 years ago
committed by
Damien George
9 changed files with 174 additions and 4 deletions
@ -0,0 +1,11 @@ |
|||
set(IDF_TARGET esp32c3) |
|||
|
|||
set(SDKCONFIG_DEFAULTS |
|||
boards/sdkconfig.base |
|||
boards/sdkconfig.ble |
|||
boards/GENERIC_C3_USB/sdkconfig.board |
|||
) |
|||
|
|||
if(NOT MICROPY_FROZEN_MANIFEST) |
|||
set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py) |
|||
endif() |
@ -0,0 +1,8 @@ |
|||
// This configuration is for a generic ESP32C3 board with 4MiB (or more) of flash.
|
|||
|
|||
#define MICROPY_HW_BOARD_NAME "ESP32C3 module" |
|||
#define MICROPY_HW_MCU_NAME "ESP32C3" |
|||
|
|||
#define MICROPY_HW_ENABLE_SDCARD (0) |
|||
#define MICROPY_PY_MACHINE_DAC (0) |
|||
#define MICROPY_PY_MACHINE_I2S (0) |
@ -0,0 +1,9 @@ |
|||
CONFIG_ESP32C3_REV_MIN_3=y |
|||
CONFIG_ESP32C3_REV_MIN=3 |
|||
CONFIG_ESP32C3_BROWNOUT_DET=y |
|||
CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_7= |
|||
CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_4=y |
|||
CONFIG_ESP32C3_BROWNOUT_DET_LVL=4 |
|||
CONFIG_ESP_CONSOLE_UART_DEFAULT= |
|||
CONFIG_ESP_CONSOLE_USB_CDC= |
|||
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y |
@ -0,0 +1,98 @@ |
|||
/*
|
|||
* This file is part of the MicroPython project, http://micropython.org/
|
|||
* |
|||
* The MIT License (MIT) |
|||
* |
|||
* Copyright (c) 2021 Patrick Van Oosterwijck |
|||
* |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to deal |
|||
* in the Software without restriction, including without limitation the rights |
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
* copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
* THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "py/runtime.h" |
|||
#include "py/mphal.h" |
|||
#include "usb_serial_jtag.h" |
|||
|
|||
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG |
|||
|
|||
#include "hal/usb_serial_jtag_ll.h" |
|||
#include "esp_intr_alloc.h" |
|||
#include "soc/periph_defs.h" |
|||
|
|||
#define USB_SERIAL_JTAG_BUF_SIZE (64) |
|||
|
|||
static uint8_t rx_buf[USB_SERIAL_JTAG_BUF_SIZE]; |
|||
static volatile bool terminal_connected = false; |
|||
|
|||
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); |
|||
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); |
|||
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(); |
|||
} |
|||
} |
|||
|
|||
void usb_serial_jtag_init(void) { |
|||
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | |
|||
USB_SERIAL_JTAG_INTR_SOF); |
|||
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | |
|||
USB_SERIAL_JTAG_INTR_SOF); |
|||
ESP_ERROR_CHECK(esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, ESP_INTR_FLAG_LEVEL1, |
|||
usb_serial_jtag_isr_handler, NULL, NULL)); |
|||
} |
|||
|
|||
void usb_serial_jtag_tx_strn(const char *str, size_t len) { |
|||
while (len) { |
|||
size_t l = len; |
|||
if (l > USB_SERIAL_JTAG_PACKET_SZ_BYTES) { |
|||
l = USB_SERIAL_JTAG_PACKET_SZ_BYTES; |
|||
} |
|||
portTickType start_tick = xTaskGetTickCount(); |
|||
while (!usb_serial_jtag_ll_txfifo_writable()) { |
|||
portTickType now_tick = xTaskGetTickCount(); |
|||
if (!terminal_connected || now_tick > (start_tick + pdMS_TO_TICKS(200))) { |
|||
terminal_connected = false; |
|||
return; |
|||
} |
|||
} |
|||
terminal_connected = true; |
|||
l = usb_serial_jtag_ll_write_txfifo((const uint8_t *)str, l); |
|||
usb_serial_jtag_ll_txfifo_flush(); |
|||
str += l; |
|||
len -= l; |
|||
} |
|||
} |
|||
|
|||
#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
@ -0,0 +1,32 @@ |
|||
/*
|
|||
* This file is part of the MicroPython project, http://micropython.org/
|
|||
* |
|||
* The MIT License (MIT) |
|||
* |
|||
* Copyright (c) 2021 Patrick Van Oosterwijck |
|||
* |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to deal |
|||
* in the Software without restriction, including without limitation the rights |
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
* copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
* THE SOFTWARE. |
|||
*/ |
|||
#ifndef MICROPY_INCLUDED_ESP32_USB_SERIAL_JTAG_H |
|||
#define MICROPY_INCLUDED_ESP32_USB_SERIAL_JTAG_H |
|||
|
|||
void usb_serial_jtag_init(void); |
|||
void usb_serial_jtag_tx_strn(const char *str, size_t len); |
|||
|
|||
#endif // MICROPY_INCLUDED_ESP32_USB_SERIAL_JTAG_H
|
Loading…
Reference in new issue