Update to latest Zephyr and their Docker repo

This commit is contained in:
Sergio R. Caprile committed 2022-10-04 17:24:13 -03:00
1 parent 0b3f6d6aab
commit 1ef0aa14c0
11 files changed
+8885 -14

No files matched your search

+24
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.
+44 -9
View File
@@ -1,17 +1,52 @@
PROJECT_DIR ?= /mnt
ZEPHYR_DIR ?= /zephyrproject
BOARD ?= nucleo_f746zg
DOCKER ?= docker run -v $(realpath $(CURDIR)):/mnt mdashnet/zephyr
PROJECT_DIR ?= /workdir
ZEPHYR_DIR ?= zephyrproject
BOARD ?= qemu_x86
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:
true
build:
cp ../../../mongoose.c ../../../mongoose.h src/
$(DOCKER) /bin/sh -c 'cd $(ZEPHYR_DIR) && west build -b $(BOARD) -p auto $(PROJECT_DIR)'
cp ../../../mongoose.[c,h] src/
$(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:
cd $(ZEPHYR_DIR) && west flash
run:
$(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west build -t run --build-dir $(PROJECT_DIR)/build'
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'
+1
View File
@@ -0,0 +1 @@
../README.md
+1
View File
@@ -8,6 +8,7 @@ CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POLL_MAX=32
CONFIG_POSIX_MAX_FDS=32
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_LOG=y
CONFIG_LOG=y
+17 -1
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
}
} 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);
}
// 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[]) {
// 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;
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