Skip to content

Zephyr - #2389

Draft
petermm wants to merge 77 commits into
atomvm:release-0.7from
petermm:pr/958-rebased
Draft

Zephyr#2389
petermm wants to merge 77 commits into
atomvm:release-0.7from
petermm:pr/958-rebased

Conversation

@petermm

@petermm petermm commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Based on #958

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

UncleGrumpy and others added 27 commits November 4, 2026 17:06
Setup a freestanding `west` application project for `Zephyr SDK`.

Signed-off-by: Winford <winford@object.stream>
Prototype ESP32, ESP32-S3, and Raspberry Pi Pico
targets on the Zephyr port, including early Wi-Fi bring-up.

Signed-off-by: Peter M <petermm@gmail.com>
Enable SMP for qemu_x86_64 so scheduler tests can run
on the Zephyr simulator.

Signed-off-by: Peter M <petermm@gmail.com>
Implement a Zephyr UART NIF collection with resource lifecycle handling, devicetree-backed UART lookup, runtime serial configuration, and read/write/state/error operations.

Keep synchronous polling bounded so long or infinite UART waits do not stall the AtomVM scheduler indefinitely, and preserve partial read data on timeout or device error.

Compile the driver when CONFIG_SERIAL is enabled.

Signed-off-by: Peter M <petermm@gmail.com>
Add a Zephyr-backed i2c resource NIF collection, enable CONFIG_I2C in the Zephyr port, and wire the driver into the platform library build.

Introduce avm_zephyr with an i2c_hal implementation and atomvmlib-zephyr packaging so I2C examples can dialyze against the Zephyr API.

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Add a native_sim Twister scenario that embeds a small Erlang test AVM and registers a Zephyr I2C emulator target to exercise the AtomVM Zephyr I2C NIF path.

Teach the Zephyr test app how to boot an embedded test AVM and exit for simulator harnesses, and install the Erlang/rebar tooling needed to build test BEAMs in the Docker image.

Verified with:
- ./docker-test.sh -b native_sim
- ./docker-test.sh -b qemu_x86_64
- ./docker-test.sh -b esp32_devkitc/esp32/procpu
- git diff --check

Signed-off-by: Peter M <petermm@gmail.com>
Wire ASan/UBSan, Wokwi, and the Zephyr GitHub workflow
so the new port is built and simulated in CI.

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Port three high-priority tests from the ESP32 platform runner to Zephyr:

- test_md5: verifies erlang:md5/1 NIF (direct copy, no platform deps)
- test_crypto: verifies crypto:hash/2 and crypto:crypto_one_time/4,5
  (adapted to remove esp32_chip_info call, uses non-AES-192 cipher set)
- test_file: verifies POSIX file I/O and FD garbage collection
  (adapted to use Zephyr RAM FAT FS via zephyr:mkfs/mount/umount)

Enable mbedTLS in the test Kconfig via Zephyr PSA Crypto symbols
(MBEDTLS_HASH_ALL_ENABLED, MBEDTLS_CIPHER_ALL_ENABLED, etc.).

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
The Erlang TLS client was already packaged but commented out.
Run it as its own ZTEST on Wi-Fi boards, share the github.com
cipher/PSA settings with ESP32-C3 and ESP32-S3, and give Wokwi
180s so handshake plus the later Wi-Fi cases still fit.

Also drop leftover otp_ssl tracing from the WIP enablement.

Signed-off-by: Peter M <petermm@gmail.com>
A delayed connect-result after sta_got_ip was overwriting
connected with associated. test_ssl leaves the radio up, so
test_wifi_managed then failed on sta_status().

Signed-off-by: Peter M <petermm@gmail.com>
Ship the platform NIF wrappers with atomvmlib-zephyr so
applications can call mount, socketpair, PM, and the task
watchdog without a test-only module.

Signed-off-by: Peter M <petermm@gmail.com>
Expose the portable sys_reboot, hwinfo reset-cause, net_if
link address, and uptime-microsecond APIs through zephyr.erl
so applications have the same platform hooks they use on ESP32.

Signed-off-by: Peter M <petermm@gmail.com>
Store binary values under Namespace/Key via Zephyr Settings
and NVS. ESP32 boards use the existing storage partition,
Pico W carves 24 KiB from flash, and native_sim uses the
simulated-flash storage partition.

Signed-off-by: Peter M <petermm@gmail.com>
GitHub resets the TCP connection mid-handshake after about
75s on C3. Classic ESP32 still runs the TLS client case.

Signed-off-by: Peter M <petermm@gmail.com>
Expose deep_sleep, GPIO wakeup, and wakeup cause through
zephyr.erl. ESP32 uses sys_poweroff plus the Espressif
timer and GPIO wakeup sources.

Signed-off-by: Peter M <petermm@gmail.com>
Sleep on first boot and continue the suite when
sleep_get_wakeup_cause returns timer. Ignore the
ESP UNDEFINED bit so a cold boot is not unknown.

Signed-off-by: Peter M <petermm@gmail.com>
network:start([{ap, ...}]) enables Zephyr AP mode and waits
for ap_started. ESP32 boards add a second wifi_ap iface so
STA and AP can run together. The AP is given 192.168.4.1 and
CONFIG_NET_DHCPV4_SERVER leases from 192.168.4.2, emitting
sta_ip_assigned. Raise poll/eventfd limits so the DHCP
server does not starve STA DNS.

Signed-off-by: Peter M <petermm@gmail.com>
Keep the module name so ESP32 boot images stay unchanged.
Persist settings through zephyr:settings_* on Zephyr and
esp:nvs_* on ESP32. Default gen_tcp/gen_udp to the otp_socket
backend on Zephyr, which has no legacy socket port driver.
Fold start_network into the existing ESP32 Wokwi suite as
test_wifi_z_devmode so leftover AP sockets cannot starve STA.

Signed-off-by: Peter M <petermm@gmail.com>
Expose open/write/close through dac.erl. Controllers are
selected by atomvm,dac, index, or device name. native_sim
uses zephyr,dac-emul; classic ESP32 enables the on-chip
DAC on GPIO25. ESP32-C3 and ESP32-S3 have no DAC.

Signed-off-by: Peter M <petermm@gmail.com>
Use GPIO10 on C3 instead of GPIO0. Stop wokwi-cli as soon as
the suite prints PROJECT EXECUTION FAILED instead of waiting
the full 180s for SUCCESSFUL.

Signed-off-by: Peter M <petermm@gmail.com>
C3 reports riscv64-espressif-zephyr, not esp32c3, so the
previous match kept using GPIO0. Match the architecture
tuple instead.

Signed-off-by: Peter M <petermm@gmail.com>
Handshake returns {error,-2} after about 7s. Classic ESP32
still runs the TLS client case.

Signed-off-by: Peter M <petermm@gmail.com>
Force PLATFORM_VENDOR esp for the Espressif SoC family so
C3 reports riscv64-esp-zephyr and Xtensa reports
xtensa-esp-zephyr, matching the xtensa-esp-esp_idf shape.
Update tests that matched espressif in the vendor field.

Signed-off-by: Peter M <petermm@gmail.com>
Return the same model/cores/features/revision map as ESP-IDF
for Espressif SoC series. Model comes from CONFIG_SOC_SERIES_*;
cores and features use the typical values for that series.
native_sim still returns undefined.

Signed-off-by: Peter M <petermm@gmail.com>
Zephyr RISC-V compiler dumpmachine is always
riscv64-zephyr-elf. Override PLATFORM_ARCH using
CONFIG_RISCV and CONFIG_64BIT so ESP32-C3 reports
riscv32-esp-zephyr, matching riscv32-esp-esp_idf.

Signed-off-by: Peter M <petermm@gmail.com>
Expose flash_list, flash_read, flash_write, and flash_erase
through zephyr.erl. Areas are selected by id or partition
label. On Espressif chips, flash_mmap maps flash via
spi_flash_mmap. native_sim and ESP32-C3 cover list/read
and scratch erase/write; mmap is asserted on C3.

Signed-off-by: Peter M <petermm@gmail.com>
Return sys_clock_hw_cycles_per_sec() as the hardware
cycle-counter frequency in Hz. test_platform checks a
positive integer on native_sim.

Signed-off-by: Peter M <petermm@gmail.com>
settings_erase_all/1 and settings_reformat/0 delete keys
through the Settings API so NVS metadata stays consistent.
Erase captures one name, then deletes it, and repeats.
test_settings covers a three-key namespace wipe and
reformat followed immediately by put.

Signed-off-by: Peter M <petermm@gmail.com>
Implement i2c:target_transmit/3 and target_receive/3 with
Zephyr I2C target callbacks when CONFIG_I2C_TARGET is set
and init is given {own_address, Addr}. native_sim loopback
covers both. Also compile-define the I2C emulator test.

Signed-off-by: Peter M <petermm@gmail.com>
Move the port and CI to Zephyr 4.5.0 and its matching
ghcr.io/zephyrproject-rtos/ci:v0.29.4 image. Zephyr SDK stays at
1.0.1, which is what the new image bundles.

Zephyr 4.5 requires explicit TLS 1.3 key exchange modes for Mbed
TLS 4.1, moved autoconf.h under the zephyr/ include prefix, and
requires zephyr,mapped-partition for the RP2040 code partition.
The deprecated fixed-partitions layout made 4.5 compute an absolute
FLASH_LOAD_OFFSET, which failed the link with overlapping sections.
The RP2350 cpucluster qualifiers are now m33_0 and hazard3_0, so the
Pico 2 W board fragment and the CI targets follow.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Call stop_network() when the network port is destroyed so a VM that exits without network:stop() still disconnects the station and disables the AP. This matches the ESP32 port teardown path.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Run the S3 Wi-Fi tests again now that the S3 test image is IPv4-only.
Wokwi and esp-emu crash on S3 IPv6 traffic, including with MLD, DAD,
connection-manager, or A-MPDU RX disabled; C3 and classic ESP32 retain
IPv6 coverage.

Do not run the devmode test on the classic ESP32 Wokwi image: Mbed TLS
4.1 leaves too little heap for the development-mode HTTP server after
the TLS test in the same boot. The ESP32-C3 and ESP32-S3 images cover
dev mode.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Record the S3 Wi-Fi failures, the IPv6 configurations that do not help, the local Zephyr source locations, and candidate fixes. The S3 test image is IPv4-only until the Zephyr Wi-Fi RX/IPv6 path is fixed.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Add the non-wireless Raspberry Pi Pico to the Wokwi test matrix. Use
the ELF firmware and a checked-in Pico diagram, and reuse that diagram
in the local helper so local and CI runs stage the same files.

Raise the Pico ztest thread stack so AtomVM and Mbed TLS do not corrupt
adjacent kernel state, move the GPIO test to GP15 so it does not drive
the console TX pin, and omit Settings/NVS because Wokwi's RP2040 SSI
model cannot program flash.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Add the Cortex-M33 Raspberry Pi Pico 2 to the Wokwi build and runtime
matrix. Supply a Pico 2 diagram and teach the local helper about the
board.

Raise the Pico 2 ztest stack and disable kernel assertions for the
Wokwi image: Zephyr 4.5's generic timer assertion fires on the first
timeout even though the kernel holds the timeout lock. Omit PM because
the Pico 2 devicetree has no CPU power states for the deep-sleep test;
ESP32 retains PM coverage.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants