Update to latest Zephyr and their Docker repo

This commit is contained in:
Sergio R. Caprile 2022-09-30 19:30:26 -03:00
parent 0b3f6d6aab
commit 1ef0aa14c0
11 changed files with 8885 additions and 14 deletions

24
examples/zephyr/README.md Normal file
View File

@ -0,0 +1,24 @@
# Zephyr Project examples
## Building
- Run `make zephyr`, this will clone the Zephyr Project repo or update it if you've already done it before
- Now you can build the project, follow one of this options:
### Trying on a simulated board
The default board is an x86 machine that can be simulated with QEMU, and runs inside a _Docker_ container, you only need to have _Docker_ installed. Its Ethernet is also simulated and uses the TUN/TAP interface.
You'll need a TUN/TAP interface (default name is _tap0_) on your host machine; follow the instructions [here](https://github.com/cesanta/mongoose/tree/master/examples/mip-tap#linux-setup) to configure your network to provide a suitable networking environment.
- Run `make build`. The interface configuration on the simulated machine side is in the file _overlay-e1000.conf_, and defaults to _tap0_. You can change this overlay file adding an `OVERLAY` argument (e.g.: *make build OVERLAY="-DOVERLAY_CONFIG=something"*).
- Once the build succeeds, run `make run` to run the target. The default _Docker_ configuration is to share _/dev/net/tun_; if this does not work for you, pass the necessary _Docker_ parameters inside `SHARETUN` (e.g.: *make run SHARETUN=something*).
### Using a real board
- Run `make build BOARD=yourboardname` (e.g.: *make build BOARD=nucleo_f746zg*)
- Once the build succeeds, run `make flash`. The Makefile shares the USB bus with the _Docker_ container, this works well with ST-Link and J-Link devices. If this does not work for you, pass the necessary _Docker_ parameters inside `SHAREUSB` (e.g.: *make flash SHAREUSB=something*)
- The generated ELF file is at _build/zephyr_
## Cleaning up
- You can run `make clean` to clean up the build files but keep the configuration files, which speeds the next build
- If you do major changes (like compiling for a different board...), run `make pristine` to clean up everything under the _build_ directory.

View File

@ -1,17 +1,52 @@
PROJECT_DIR ?= /mnt PROJECT_DIR ?= /workdir
ZEPHYR_DIR ?= /zephyrproject ZEPHYR_DIR ?= zephyrproject
BOARD ?= nucleo_f746zg BOARD ?= qemu_x86
DOCKER ?= docker run -v $(realpath $(CURDIR)):/mnt mdashnet/zephyr
ifeq "$(BOARD)" "qemu_x86"
OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf
else
OVERLAY ?=
endif
SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb
SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host
DOCKER ?= docker run --rm -v $(realpath $(CURDIR)):$(PROJECT_DIR)
REPO ?= zephyrprojectrtos/ci
example: example:
true true
build: build:
cp ../../../mongoose.c ../../../mongoose.h src/ cp ../../../mongoose.[c,h] src/
$(DOCKER) /bin/sh -c 'cd $(ZEPHYR_DIR) && west build -b $(BOARD) -p auto $(PROJECT_DIR)' $(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR)/zephyr && \
west build -b $(BOARD) -p auto $(PROJECT_DIR) $(OVERLAY) --build-dir $(PROJECT_DIR)/build'
flash: run:
cd $(ZEPHYR_DIR) && west flash $(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west build -t run --build-dir $(PROJECT_DIR)/build'
clean: clean:
rm -rf */*/mongoose.* $(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west build -t clean --build-dir $(PROJECT_DIR)/build'
pristine:
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west build -t pristine --build-dir $(PROJECT_DIR)/build'
flash:
$(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west flash --build-dir $(PROJECT_DIR)/build'
debug:
$(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west debug --build-dir $(PROJECT_DIR)/build'
.PHONY: build flash zephyr clean pristine run
zephyr:
ifeq ($(wildcard $(ZEPHYR_DIR)/.*),)
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR) && west init ./$(ZEPHYR_DIR)'
endif
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && west update'

View File

@ -0,0 +1 @@
../README.md

View File

@ -8,6 +8,7 @@ CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POLL_MAX=32 CONFIG_NET_SOCKETS_POLL_MAX=32
CONFIG_POSIX_MAX_FDS=32 CONFIG_POSIX_MAX_FDS=32
CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_LOG=y CONFIG_NET_LOG=y
CONFIG_LOG=y CONFIG_LOG=y

View File

@ -39,7 +39,7 @@ static void wcb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
mg_http_serve_dir(c, hm, &opts); // static files mg_http_serve_dir(c, hm, &opts); // static files
} }
} else if (ev == MG_EV_OPEN) { } else if (ev == MG_EV_OPEN) {
c->is_hexdumping = 1; // c->is_hexdumping = 1;
} }
} }
@ -68,7 +68,23 @@ static void timer_fn(void *arg) {
if (s_boot_timestamp < 9999) mg_sntp_request(s_sntp_conn); if (s_boot_timestamp < 9999) mg_sntp_request(s_sntp_conn);
} }
// Zephyr: Define a semaphore and network management callback to be able to wait
// until our IP address is ready. The main function will start and block on this
// semaphore until this event handler releases it when the network is ready
K_SEM_DEFINE(run, 0, 1);
static void zeh(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
struct net_if *iface) {
if (mgmt_event == NET_EVENT_L4_CONNECTED) k_sem_give(&run);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Zephyr: Register the network management callback and block on the semaphore
struct net_mgmt_event_callback ncb;
net_mgmt_init_event_callback(&ncb, zeh, NET_EVENT_L4_CONNECTED);
net_mgmt_add_event_callback(&ncb);
k_sem_take(&run, K_FOREVER);
struct mg_mgr mgr; struct mg_mgr mgr;
mg_log_set(MG_LL_DEBUG); mg_log_set(MG_LL_DEBUG);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5585,6 +5585,8 @@ uint64_t mg_millis(void) {
return xTaskGetTickCount() * portTICK_PERIOD_MS; return xTaskGetTickCount() * portTICK_PERIOD_MS;
#elif MG_ARCH == MG_ARCH_AZURERTOS #elif MG_ARCH == MG_ARCH_AZURERTOS
return tx_time_get() * (1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND); return tx_time_get() * (1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND);
#elif MG_ARCH == MG_ARCH_ZEPHYR
return (uint64_t) k_uptime_get();
#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__) #elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
// Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux // Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
// Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux // Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux

View File

@ -575,12 +575,12 @@ typedef int socklen_t;
#if MG_ARCH == MG_ARCH_ZEPHYR #if MG_ARCH == MG_ARCH_ZEPHYR
#include <zephyr.h> #include <zephyr/kernel.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <net/socket.h> #include <zephyr/net/socket.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -591,6 +591,9 @@ typedef int socklen_t;
#include <time.h> #include <time.h>
#define MG_PUTCHAR(x) printk("%c", x) #define MG_PUTCHAR(x) printk("%c", x)
#ifndef strdup
#define strdup(s) ((char *) mg_strdup(mg_str(s)).ptr)
#endif
#define strerror(x) zsock_gai_strerror(x) #define strerror(x) zsock_gai_strerror(x)
#define FD_CLOEXEC 0 #define FD_CLOEXEC 0
#define F_SETFD 0 #define F_SETFD 0

View File

@ -2,12 +2,12 @@
#if MG_ARCH == MG_ARCH_ZEPHYR #if MG_ARCH == MG_ARCH_ZEPHYR
#include <zephyr.h> #include <zephyr/kernel.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <net/socket.h> #include <zephyr/net/socket.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -18,6 +18,9 @@
#include <time.h> #include <time.h>
#define MG_PUTCHAR(x) printk("%c", x) #define MG_PUTCHAR(x) printk("%c", x)
#ifndef strdup
#define strdup(s) ((char *) mg_strdup(mg_str(s)).ptr)
#endif
#define strerror(x) zsock_gai_strerror(x) #define strerror(x) zsock_gai_strerror(x)
#define FD_CLOEXEC 0 #define FD_CLOEXEC 0
#define F_SETFD 0 #define F_SETFD 0

View File

@ -102,6 +102,8 @@ uint64_t mg_millis(void) {
return xTaskGetTickCount() * portTICK_PERIOD_MS; return xTaskGetTickCount() * portTICK_PERIOD_MS;
#elif MG_ARCH == MG_ARCH_AZURERTOS #elif MG_ARCH == MG_ARCH_AZURERTOS
return tx_time_get() * (1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND); return tx_time_get() * (1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND);
#elif MG_ARCH == MG_ARCH_ZEPHYR
return (uint64_t) k_uptime_get();
#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__) #elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
// Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux // Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
// Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux // Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux
@ -128,3 +130,4 @@ uint64_t mg_millis(void) {
#endif #endif
} }
#endif #endif