Skip to content

Commit 96eca22

Browse files
dpgeorgepfalcon
authored andcommitted
esp8266: Make destination for vendor OS debug output soft-configurable.
Use esp.osdebug(None) to disable, or esp.osdebug(uart_id) to send output to a UART.
1 parent e6a4d4e commit 96eca22

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

esp8266/modesp.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "py/runtime.h"
3636
#include "netutils.h"
3737
#include "queue.h"
38+
#include "ets_sys.h"
39+
#include "uart.h"
3840
#include "user_interface.h"
3941
#include "espconn.h"
4042
#include "spi_flash.h"
@@ -514,6 +516,16 @@ void error_check(bool status, const char *msg) {
514516
}
515517
}
516518

519+
STATIC mp_obj_t esp_osdebug(mp_obj_t val) {
520+
if (val == mp_const_none) {
521+
uart_os_config(-1);
522+
} else {
523+
uart_os_config(mp_obj_get_int(val));
524+
}
525+
return mp_const_none;
526+
}
527+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_osdebug_obj, esp_osdebug);
528+
517529
STATIC mp_obj_t esp_sleep_type(mp_uint_t n_args, const mp_obj_t *args) {
518530
if (n_args == 0) {
519531
return mp_obj_new_int(wifi_get_sleep_type());
@@ -608,6 +620,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
608620
STATIC const mp_map_elem_t esp_module_globals_table[] = {
609621
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_esp) },
610622

623+
{ MP_OBJ_NEW_QSTR(MP_QSTR_osdebug), (mp_obj_t)&esp_osdebug_obj },
611624
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj },
612625
{ MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj },
613626
{ MP_OBJ_NEW_QSTR(MP_QSTR_flash_id), (mp_obj_t)&esp_flash_id_obj },

esp8266/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Q(connect)
5858
Q(disconnect)
5959
Q(wifi_mode)
6060
Q(phy_mode)
61+
Q(osdebug)
6162
Q(sleep_type)
6263
Q(deepsleep)
6364
Q(adc)

esp8266/uart.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
// UartDev is defined and initialized in rom code.
2525
extern UartDevice UartDev;
2626

27+
// the uart to which OS messages go; -1 to disable
28+
static int uart_os = UART_OS;
29+
2730
/* unused
2831
// circular buffer for RX buffering
2932
#define RX_BUF_SIZE (256)
@@ -134,15 +137,23 @@ void uart_flush(uint8 uart) {
134137
*******************************************************************************/
135138
static void ICACHE_FLASH_ATTR
136139
uart_os_write_char(char c) {
140+
if (uart_os == -1) {
141+
return;
142+
}
137143
if (c == '\n') {
138-
uart_tx_one_char(UART_OS, '\r');
139-
uart_tx_one_char(UART_OS, '\n');
144+
uart_tx_one_char(uart_os, '\r');
145+
uart_tx_one_char(uart_os, '\n');
140146
} else if (c == '\r') {
141147
} else {
142-
uart_tx_one_char(UART_OS, c);
148+
uart_tx_one_char(uart_os, c);
143149
}
144150
}
145151

152+
void ICACHE_FLASH_ATTR
153+
uart_os_config(int uart) {
154+
uart_os = uart;
155+
}
156+
146157
/******************************************************************************
147158
* FunctionName : uart0_rx_intr_handler
148159
* Description : Internal used function

esp8266/uart.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@ void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
9393
int uart0_rx(void);
9494
void uart_tx_one_char(uint8 uart, uint8 TxChar);
9595
void uart_flush(uint8 uart);
96+
void uart_os_config(int uart);
9697

9798
#endif // _INCLUDED_UART_H_

0 commit comments

Comments
 (0)