提交 44b70745 编写于 作者: H HonestQiao 提交者: skylarCai

handle specific calls for ESP32-C3

上级 2a587382
......@@ -261,7 +261,7 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
#if CONFIG_IDF_TARGET_ESP32C3
if (self->id == 18 || self->id == 19) {
CLEAR_PERI_REG_MASK(USB_DEVICE_CONF0_REG, USB_DEVICE_USB_PAD_ENABLE);
// CLEAR_PERI_REG_MASK(USB_DEVICE_CONF0_REG, USB_DEVICE_USB_PAD_ENABLE);
}
#endif
......
......@@ -34,24 +34,76 @@
#include "py/runtime.h"
#include "py/mphal.h"
#ifdef CONFIG_IDF_TARGET_ESP32C3
#include "uart.h"
#endif
STATIC void uart_irq_handler(void *arg);
void uart_init(void) {
#ifdef CONFIG_IDF_TARGET_ESP32C3
uart_config_t uartcfg = {
.baud_rate = MICROPY_HW_UART_REPL_BAUD,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 0
};
uart_param_config(MICROPY_HW_UART_REPL, &uartcfg);
const uint32_t rxbuf = 129; // IDF requires > 128 min
const uint32_t txbuf = 0;
uart_driver_install(MICROPY_HW_UART_REPL, rxbuf, txbuf, 0, NULL, 0);
#endif
uart_isr_handle_t handle;
#ifdef CONFIG_IDF_TARGET_ESP32C3
uart_isr_free(MICROPY_HW_UART_REPL);
uart_isr_register(MICROPY_HW_UART_REPL, uart_irq_handler, NULL, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM, &handle);
uart_enable_rx_intr(MICROPY_HW_UART_REPL);
#else
uart_isr_register(UART_NUM_0, uart_irq_handler, NULL, ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM, &handle);
uart_enable_rx_intr(UART_NUM_0);
#endif
}
#ifdef CONFIG_IDF_TARGET_ESP32C3
int uart_stdout_tx_strn(const char *str, size_t len) {
size_t remaining = len;
// TODO add a timeout
for (;;) {
int ret = uart_tx_chars(MICROPY_HW_UART_REPL, str, remaining);
if (ret == -1) {
return -1;
}
remaining -= ret;
if (remaining <= 0) {
break;
}
str += ret;
ulTaskNotifyTake(pdFALSE, 1);
}
return len - remaining;
}
#endif
// all code executed in ISR must be in IRAM, and any const data must be in DRAM
STATIC void IRAM_ATTR uart_irq_handler(void *arg) {
volatile uart_dev_t *uart = &UART0;
#if CONFIG_IDF_TARGET_ESP32S3
uart->int_clr.rxfifo_full_int_clr = 1;
uart->int_clr.rxfifo_tout_int_clr = 1;
#else
uart->int_clr.rxfifo_full = 1;
uart->int_clr.frm_err = 1;
uart->int_clr.frm_err = 1;
uart->int_clr.rxfifo_tout = 1;
#endif
while (uart->status.rxfifo_cnt) {
#if CONFIG_IDF_TARGET_ESP32
uint8_t c = uart->fifo.rw_byte;
#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
uint8_t c = READ_PERI_REG(UART_FIFO_AHB_REG(0)); // UART0
#endif
if (c == mp_interrupt_char) {
......@@ -61,4 +113,4 @@ STATIC void IRAM_ATTR uart_irq_handler(void *arg) {
ringbuf_put(&stdin_ringbuf, c);
}
}
}
}
\ No newline at end of file
......@@ -28,6 +28,18 @@
#ifndef MICROPY_INCLUDED_ESP32_UART_H
#define MICROPY_INCLUDED_ESP32_UART_H
#ifdef CONFIG_IDF_TARGET_ESP32C3
#ifndef MICROPY_HW_UART_REPL
#define MICROPY_HW_UART_REPL (UART_NUM_0)
#endif
#ifndef MICROPY_HW_UART_REPL_BAUD
#define MICROPY_HW_UART_REPL_BAUD (115200)
#endif
int uart_stdout_tx_strn(const char *str, size_t len);
#endif
void uart_init(void);
#endif // MICROPY_INCLUDED_ESP32_UART_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册