summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/zephyr/prj_base.conf6
-rw-r--r--ports/zephyr/prj_qemu_cortex_m3.conf4
-rw-r--r--ports/zephyr/prj_qemu_x86.conf4
-rw-r--r--ports/zephyr/src/zephyr_start.c5
-rw-r--r--ports/zephyr/uart_core.c14
5 files changed, 33 insertions, 0 deletions
diff --git a/ports/zephyr/prj_base.conf b/ports/zephyr/prj_base.conf
index a4cc14513..fbcedf260 100644
--- a/ports/zephyr/prj_base.conf
+++ b/ports/zephyr/prj_base.conf
@@ -4,6 +4,12 @@ CONFIG_REBOOT=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_CONSOLE_HANDLER=y
CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS=y
+
+CONFIG_CONSOLE_PULL=y
+CONFIG_CONSOLE_GETCHAR=y
+CONFIG_CONSOLE_GETCHAR_BUFSIZE=128
+CONFIG_CONSOLE_PUTCHAR_BUFSIZE=128
+
CONFIG_NEWLIB_LIBC=y
CONFIG_FLOAT=y
CONFIG_MAIN_STACK_SIZE=4096
diff --git a/ports/zephyr/prj_qemu_cortex_m3.conf b/ports/zephyr/prj_qemu_cortex_m3.conf
index 09614c362..1ade981e2 100644
--- a/ports/zephyr/prj_qemu_cortex_m3.conf
+++ b/ports/zephyr/prj_qemu_cortex_m3.conf
@@ -1,3 +1,7 @@
+# Interrupt-driven UART console has emulation artifacts under QEMU,
+# disable it
+CONFIG_CONSOLE_PULL=n
+
# Networking drivers
# SLIP driver for QEMU
CONFIG_NET_SLIP_TAP=y
diff --git a/ports/zephyr/prj_qemu_x86.conf b/ports/zephyr/prj_qemu_x86.conf
index ef60cfec9..9bc81259a 100644
--- a/ports/zephyr/prj_qemu_x86.conf
+++ b/ports/zephyr/prj_qemu_x86.conf
@@ -1,3 +1,7 @@
+# Interrupt-driven UART console has emulation artifacts under QEMU,
+# disable it
+CONFIG_CONSOLE_PULL=n
+
# Networking drivers
# SLIP driver for QEMU
CONFIG_NET_SLIP_TAP=y
diff --git a/ports/zephyr/src/zephyr_start.c b/ports/zephyr/src/zephyr_start.c
index 9e8a90beb..452e304ca 100644
--- a/ports/zephyr/src/zephyr_start.c
+++ b/ports/zephyr/src/zephyr_start.c
@@ -24,11 +24,16 @@
* THE SOFTWARE.
*/
#include <zephyr.h>
+#include <console.h>
#include "zephyr_getchar.h"
int real_main(void);
void main(void) {
+#ifdef CONFIG_CONSOLE_PULL
+ console_init();
+#else
zephyr_getchar_init();
+#endif
real_main();
}
diff --git a/ports/zephyr/uart_core.c b/ports/zephyr/uart_core.c
index 1e85053cd..e41fb9acc 100644
--- a/ports/zephyr/uart_core.c
+++ b/ports/zephyr/uart_core.c
@@ -28,6 +28,7 @@
#include "src/zephyr_getchar.h"
// Zephyr headers
#include <uart.h>
+#include <console.h>
/*
* Core UART functions to implement for a port
@@ -35,11 +36,23 @@
// Receive single character
int mp_hal_stdin_rx_chr(void) {
+#ifdef CONFIG_CONSOLE_PULL
+ return console_getchar();
+#else
return zephyr_getchar();
+#endif
}
// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+#ifdef CONFIG_CONSOLE_PULL
+ while (len--) {
+ char c = *str++;
+ while (console_putchar(c) == -1) {
+ k_sleep(1);
+ }
+ }
+#else
static struct device *uart_console_dev;
if (uart_console_dev == NULL) {
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) {
while (len--) {
uart_poll_out(uart_console_dev, *str++);
}
+#endif
}