Skip to content

Commit 402a743

Browse files
committed
esp8266/esp_mphal: Add support for debug UART-only output.
Helpful when debugging dupterm support (because otherwise all output is spooled to dupterm too). To use: mp_printf(&mp_debug_print, "...");
1 parent 8fc5e56 commit 402a743

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

esp8266/esp_mphal.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ extern void ets_wdt_disable(void);
3939
extern void wdt_feed(void);
4040
extern void ets_delay_us();
4141

42+
void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len);
43+
const mp_print_t mp_debug_print = {NULL, mp_hal_debug_tx_strn_cooked};
44+
4245
void mp_hal_init(void) {
4346
ets_wdt_disable(); // it's a pain while developing
4447
mp_hal_rtc_init();
@@ -74,6 +77,15 @@ void mp_hal_stdout_tx_char(char c) {
7477
mp_uos_dupterm_tx_strn(&c, 1);
7578
}
7679

80+
#if 0
81+
void mp_hal_debug_str(const char *str) {
82+
while (*str) {
83+
uart_tx_one_char(UART0, *str++);
84+
}
85+
uart_flush(UART0);
86+
}
87+
#endif
88+
7789
void mp_hal_stdout_tx_str(const char *str) {
7890
while (*str) {
7991
mp_hal_stdout_tx_char(*str++);
@@ -95,6 +107,16 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) {
95107
}
96108
}
97109

110+
void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len) {
111+
(void)env;
112+
while (len--) {
113+
if (*str == '\n') {
114+
uart_tx_one_char(UART0, '\r');
115+
}
116+
uart_tx_one_char(UART0, *str++);
117+
}
118+
}
119+
98120
uint32_t mp_hal_ticks_ms(void) {
99121
return system_get_time() / 1000;
100122
}

esp8266/esp_mphal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#ifndef _INCLUDED_MPHAL_H_
2828
#define _INCLUDED_MPHAL_H_
2929

30+
struct _mp_print_t;
31+
// Structure for UART-only output via mp_printf()
32+
extern const struct _mp_print_t mp_debug_print;
33+
3034
void mp_hal_init(void);
3135
void mp_hal_rtc_init(void);
3236
void mp_hal_feed_watchdog(void);

0 commit comments

Comments
 (0)