Skip to content

Commit 4514f07

Browse files
committed
zephyr: Switch to interrupt-driven pull-style console.
While this console API improves handling on real hardware boards (e.g. clipboard paste is much more reliable, as well as programmatic communication), it vice-versa poses problems under QEMU, apparently because it doesn't emulate UART interrupt handling faithfully. That leads to inability to run the testsuite on QEMU at all. To work that around, we have to suuport both old and new console routines, and use the old ones under QEMU.
1 parent 71c1a05 commit 4514f07

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

ports/zephyr/prj_base.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ CONFIG_REBOOT=y
44
CONFIG_STDOUT_CONSOLE=y
55
CONFIG_CONSOLE_HANDLER=y
66
CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS=y
7+
8+
CONFIG_CONSOLE_PULL=y
9+
CONFIG_CONSOLE_GETCHAR=y
10+
CONFIG_CONSOLE_GETCHAR_BUFSIZE=128
11+
CONFIG_CONSOLE_PUTCHAR_BUFSIZE=128
12+
713
CONFIG_NEWLIB_LIBC=y
814
CONFIG_FLOAT=y
915
CONFIG_MAIN_STACK_SIZE=4096

ports/zephyr/prj_qemu_cortex_m3.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Interrupt-driven UART console has emulation artifacts under QEMU,
2+
# disable it
3+
CONFIG_CONSOLE_PULL=n
4+
15
# Networking drivers
26
# SLIP driver for QEMU
37
CONFIG_NET_SLIP_TAP=y

ports/zephyr/prj_qemu_x86.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Interrupt-driven UART console has emulation artifacts under QEMU,
2+
# disable it
3+
CONFIG_CONSOLE_PULL=n
4+
15
# Networking drivers
26
# SLIP driver for QEMU
37
CONFIG_NET_SLIP_TAP=y

ports/zephyr/src/zephyr_start.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
* THE SOFTWARE.
2525
*/
2626
#include <zephyr.h>
27+
#include <console.h>
2728
#include "zephyr_getchar.h"
2829

2930
int real_main(void);
3031

3132
void main(void) {
33+
#ifdef CONFIG_CONSOLE_PULL
34+
console_init();
35+
#else
3236
zephyr_getchar_init();
37+
#endif
3338
real_main();
3439
}

ports/zephyr/uart_core.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,31 @@
2828
#include "src/zephyr_getchar.h"
2929
// Zephyr headers
3030
#include <uart.h>
31+
#include <console.h>
3132

3233
/*
3334
* Core UART functions to implement for a port
3435
*/
3536

3637
// Receive single character
3738
int mp_hal_stdin_rx_chr(void) {
39+
#ifdef CONFIG_CONSOLE_PULL
40+
return console_getchar();
41+
#else
3842
return zephyr_getchar();
43+
#endif
3944
}
4045

4146
// Send string of given length
4247
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
48+
#ifdef CONFIG_CONSOLE_PULL
49+
while (len--) {
50+
char c = *str++;
51+
while (console_putchar(c) == -1) {
52+
k_sleep(1);
53+
}
54+
}
55+
#else
4356
static struct device *uart_console_dev;
4457
if (uart_console_dev == NULL) {
4558
uart_console_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME);
@@ -48,4 +61,5 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
4861
while (len--) {
4962
uart_poll_out(uart_console_dev, *str++);
5063
}
64+
#endif
5165
}

0 commit comments

Comments
 (0)