From 5298472fee1a83878e4670c1f8c885aefc087765 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 21 Jan 2017 17:16:35 +0300 Subject: [PATCH] zephyr: Enable SLIP networking for the default build. This makes MicroPython app running in QEMU be pingable from the host (by following QEMU networking setup instructions, https://www.zephyrproject.org/doc/samples/net/qemu_setup.html). --- zephyr/main.c | 16 ++++++++++++++++ zephyr/prj.conf | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/zephyr/main.c b/zephyr/main.c index d812f96092..6d7fca8024 100644 --- a/zephyr/main.c +++ b/zephyr/main.c @@ -28,6 +28,12 @@ #include #include +#include +#ifdef CONFIG_NETWORKING +#include +#include +#endif + #include "py/nlr.h" #include "py/compile.h" #include "py/runtime.h" @@ -60,6 +66,14 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) { static char *stack_top; static char heap[MICROPY_HEAP_SIZE]; +void init_zephyr(void) { + #ifdef CONFIG_NET_IPV4 + // TODO: Make address configurable + static struct in_addr in4addr_my = { { { 192, 0, 2, 1 } } }; + net_if_ipv4_addr_add(net_if_get_default(), &in4addr_my, NET_ADDR_MANUAL, 0); + #endif +} + int real_main(void) { int stack_dummy; stack_top = (char*)&stack_dummy; @@ -67,6 +81,8 @@ int real_main(void) { // Make MicroPython's stack limit somewhat smaller than full stack available mp_stack_set_limit(CONFIG_MAIN_STACK_SIZE - 512); + init_zephyr(); + soft_reset: #if MICROPY_ENABLE_GC gc_init(heap, heap + sizeof(heap)); diff --git a/zephyr/prj.conf b/zephyr/prj.conf index 5d6b353ba3..a2fcb64d95 100644 --- a/zephyr/prj.conf +++ b/zephyr/prj.conf @@ -4,3 +4,16 @@ CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS=y CONFIG_NEWLIB_LIBC=y CONFIG_FLOAT=y CONFIG_MAIN_STACK_SIZE=4096 + +# Networking config +CONFIG_NETWORKING=y +CONFIG_NET_IPV4=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_NET_NBUF_RX_COUNT=4 + +# Networking drivers +# SLIP driver for QEMU +CONFIG_NET_SLIP_TAP=y + +# BOARD-specific config (qemu_x86) +CONFIG_RAM_SIZE=256