8000 Esp8266 uart fixes by svily0 · Pull Request #2990 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Esp8266 uart fixes #2990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions esp8266/esp_mphal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include "lib/utils/interrupt_char.h"
#include "xtirq.h"

void mp_keyboard_interrupt(void);

struct _mp_print_t;
// Structure for UART-only output via mp_printf()
extern const struct _mp_print_t mp_debug_print;
Expand Down
1 change: 1 addition & 0 deletions esp8266/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void init_done(void) {
#endif
}

// Seems unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change.

Also, "seems" sounds dangerous. This patch also "seems" to work, right?

void user_init(void) {
system_init_done_cb(init_done);
}
Expand Down
11 changes: 11 additions & 0 deletions esp8266/modesp.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ STATIC mp_obj_t esp_osdebug(mp_obj_t val) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_osdebug_obj, esp_osdebug);

STATIC mp_obj_t esp_replinput(mp_obj_t val) {
if (val == mp_const_none) {
uart_os_input(-1);
} else {
uart_os_input(mp_obj_get_int(val));
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_replinput_obj, esp_replinput);

STATIC mp_obj_t esp_sleep_type(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return mp_obj_new_int(wifi_get_sleep_type());
Expand Down Expand Up @@ -353,6 +363,7 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_esp) },

{ MP_OBJ_NEW_QSTR(MP_QSTR_osdebug), (mp_obj_t)&esp_osdebug_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_replinput), (mp_obj_t)&esp_replinput_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_id), (mp_obj_t)&esp_flash_id_obj },
Expand Down
23 changes: 21 additions & 2 deletions esp8266/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern UartDevice UartDev;

// the uart to which OS messages go; -1 to disable
static int uart_os = UART_OS;
static int uart_os_stdin = UART_OS;

#if MICROPY_REPL_EVENT_DRIVEN
static os_event_t uart_evt_queue[16];
Expand Down Expand Up @@ -116,7 +117,7 @@ void uart_flush(uint8 uart) {
}

/******************************************************************************
* FunctionName : uart1_write_char
* FunctionName : uart_os_write_char
* Description : Internal used function
* Do some special deal while tx char is '\r' or '\n'
* Parameters : char c - character to tx
Expand All @@ -141,6 +142,11 @@ uart_os_config(int uart) {
uart_os = uart;
}

void ICACHE_FLASH_ATTR
uart_os_input(int uart) {
uart_os_stdin = uart;
}

/******************************************************************************
* FunctionName : uart0_rx_intr_handler
* Description : Internal used function
Expand All @@ -165,22 +171,29 @@ static void uart0_rx_intr_handler(void *para) {
// fifo full
goto read_chars;
} else if (UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST)) {
// rx timeout
read_chars:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rx timeout what?

ETS_UART_INTR_DISABLE();

while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) {
uint8 RcvChar = READ_PERI_REG(UART_FIFO(uart_no)) & 0xff;
// Raw data processing.
if (uart_os_stdin == -1) {
// Disable repl's stdin interpretation
goto put_char;
}
if (RcvChar == mp_interrupt_char) {
mp_keyboard_interrupt();
} else {
put_char:
ringbuf_put(&input_buf, RcvChar);
}
}

mp_hal_signal_input();

// Clear pending FIFO interrupts
WRITE_PERI_REG(UART_INT_CLR(UART_REPL), UART_RXFIFO_TOUT_INT_CLR | UART_RXFIFO_FULL_INT_ST);
WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_RXFIFO_TOUT_INT_CLR | UART_RXFIFO_FULL_INT_ST);
ETS_UART_INTR_ENABLE();
}
}
Expand Down Expand Up @@ -263,6 +276,11 @@ void ICACHE_FLASH_ATTR uart_setup(uint8 uart) {

#if MICROPY_REPL_EVENT_DRIVEN
void uart_task_handler(os_event_t *evt) {
if (uart_os_stdin == -1) {
// Disable repl's stdin interpretation
return;
}

if (pyexec_repl_active) {
// TODO: Just returning here isn't exactly right.
// What really should be done is something like
Expand All @@ -274,6 +292,7 @@ void uart_task_handler(os_event_t *evt) {
return;
}

// Buffered data processing and interpretation
int c, ret = 0;
while ((c = ringbuf_get(&input_buf)) >= 0) {
if (c == interrupt_char) {
Expand Down
4 changes: 2 additions & 2 deletions esp8266/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct {
UartBautRate baut_rate;
UartBitsNum4Char data_bits;
UartExistParity exist_parity;
UartParityMode parity; // chip size in byte
UartParityMode parity; // even/odd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very related change, should be submitted separately.

UartStopBitsNum stop_bits;
UartFlowCtrl flow_ctrl;
RcvMsgBuff rcv_buff;
Expand All @@ -92,12 +92,12 @@ typedef struct {
} UartDevice;

void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
int uart0_rx(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change.

bool uart_rx_wait(uint32_t timeout_us);
int uart_rx_char(void);
void uart_tx_one_char(uint8 uart, uint8 TxChar);
void uart_flush(uint8 uart);
void uart_os_config(int uart);
void uart_os_input(int uart);
void uart_setup(uint8 uart);
// check status of rx/tx
int uart_rx_any(uint8 uart);
Expand Down
0