Zephyr - #2389
Draft
petermm wants to merge 74 commits into
Draft
Conversation
Setup a freestanding `west` application project for `Zephyr SDK`. Signed-off-by: Winford <winford@object.stream>
Add board fragments for Pico RP2040, Pico W, and Pico 2 RP2350A M33/Hazard3 variants, including the qualified Zephyr target names. Fetch the Infineon blobs/modules needed for CYW43439 Wi-Fi and add CI builds for the new Pico targets. Avoid the WHD resources.h include collision and provide a no-op listener destroy for non-network Pico builds. Signed-off-by: Peter M <petermm@gmail.com>
Add an opt-in Zephyr SMP path that enables AtomVM schedulers to run on Zephyr kernel threads and provides the platform SMP locks, condition variables, reader-writer locks, and atomic helpers needed by the runtime. Use qemu_x86_64 as the CI exercise target with a boot-test mode that verifies two schedulers come online, and update the Docker build helper so extra west build arguments can be passed through for local SMP builds. 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>
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>
- Add `atomvm.zephyr.i2c_native_sim.asan_ubsan` to `testcase.yaml` to compile and execute native simulator tests with CONFIG_ASAN=y and CONFIG_UBSAN=y. - Update `.github/workflows/zephyr-build.yaml` to run `twister` on both `qemu_x86_64` and `native_sim/native/64`. - Create `.agents/AGENTS.md` to define workspace rules and constraints for coding agents working on the Zephyr port. Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Add an Erlang ADC module backed by Zephyr's devicetree ADC API, including averaged raw and millivolt readings. Configure potentiometer channels for the ESP32 Wokwi targets, exercise the API from the Zephyr test suite, and force pristine local Wokwi builds so embedded Erlang modules cannot become stale. Signed-off-by: Peter M <petermm@gmail.com>
Wrap the existing Zephyr UART resource NIFs with the common uart_hal API. Use bounded native operations and Erlang-side polling so reads remain scheduler-safe while supporting application timeouts.\n\nPackage the module in avm_zephyr and add low- and high-level smoke coverage for serial-enabled test boards. Signed-off-by: Peter M <petermm@gmail.com>
Implement the common gpio_hal API on top of Zephyr GPIO controllers, with default and controller-qualified pin selection. Support pin configuration, pulls, digital I/O, and process-style compatibility calls.\n\nDeliver GPIO interrupts through deferred Zephyr work so Erlang messages are allocated outside ISR context. Track and clean subscriptions on removal, driver close, and VM teardown, and add simulator smoke coverage. Signed-off-by: Peter M <petermm@gmail.com>
Implement spi_hal using a Zephyr SPI resource NIF with devicetree controller selection, configurable frequency and mode, and full-duplex transfers. Keep bus pin routing in devicetree and support optional software chip selects through the GPIO API.\n\nPackage the module in avm_zephyr, select SPI controllers for native_sim and ESP32, and add lifecycle and transaction-validation smoke coverage. Signed-off-by: Peter M <petermm@gmail.com>
Expose Zephyr's retention subsystem through an Erlang API for sizing, validity checks, bounded reads and writes, and clearing retained storage. Package the module in avm_zephyr and translate subsystem failures into Erlang errors.\n\nReserve checksummed 256-byte retention areas for ESP32, ESP32-C3, ESP32-S3, QEMU x86_64, and RP2040. Keep normal and test board fragments aligned, add focused QEMU and RP2040 scenarios, and cover retention operations in Wokwi. Signed-off-by: Peter M <petermm@gmail.com>
Enable ADC, SPI, power management, and task watchdog support in the standard platform configuration so test builds inherit the same public feature set. Keep application-specific bus wiring and pin assignments in devicetree overlays, and require an explicit default SPI choice instead of falling back to SPI0. Move the custom idle power policy into the platform library and document the configuration boundary. Signed-off-by: Peter M <petermm@gmail.com>
Expose Zephyr's PWM subsystem through a portable Erlang pwm module and resource NIFs (set in nanoseconds, set_cycles, get_cycles_per_sec), with controller selection via atomvm,pwm, index, or device name. Enable PWM on standard and test board fragments, and cover the API on native_sim with Zephyr's fake PWM driver. Also apply the test app.overlay for the shared ramdisk, split the I2C emulator overlay so it is only used by the I2C suite, and provide FFF globals required by the fake PWM driver. Signed-off-by: Peter M <petermm@gmail.com>
Remove the qemu_x86_64 retained-memory configuration and runtime scenario because its reserved physical tail is not writable through Zephyr's runtime MMU mapping. Avoid substituting a simulator-only mock that would test different behavior from the hardware retention backend. Keep retention runtime coverage on supported ESP targets and RP2040 build verification. Signed-off-by: Peter M <petermm@gmail.com>
The shared test app.overlay was applied to every board, so ESP32 Wokwi images paid for a 64 KiB RAM disk they never use (file tests use SPI microSD). That alone overflowed dram0_0_seg on ESP32, C3, and S3. Limit the ramdisk overlay to QEMU, native_sim, and RP2040, and shrink it to 16 KiB for the short-file mount tests those hosts still need. Signed-off-by: Peter M <petermm@gmail.com>
Shrinking the shared test ramdisk to 16 KiB made fs_mkfs fail with -EIO on hosts that still use it (test_mount). Keep the previous 64 KiB volume size; ESP test images continue to skip this overlay entirely. Signed-off-by: Peter M <petermm@gmail.com>
The shared test defaults (~124 KiB heap pool + ~124 KiB libc arena) are sized for QEMU/native_sim and overflow dram0_0_seg once Wi-Fi and the portable peripheral stack are linked. Size each ESP test board from remaining DRAM and max it out: classic ESP32 (~253 KiB free after dropping the unused RAM disk) gets 128+124.7 KiB; C3 (~190 KiB free) gets 128+62 KiB; S3 (~222 KiB free) gets 160+61.5 KiB. Signed-off-by: Peter M <petermm@gmail.com>
Replace the fixed ~124 KiB dual-heap test defaults (and the per-board ESP/Pico overrides they forced) with CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=-1 so libc malloc claims leftover SRAM after BSS/stacks/drivers. AtomVM already allocates via malloc, so a second large static HEAP_MEM_POOL was mostly waste on embedded targets. Leave the system heap at the Kconfig default (0) unless a board needs k_malloc; QEMU keeps a modest pool for DYNAMIC_THREAD_ALLOC. ESP32 Wokwi still uses a smaller main stack so more of the auto arena is available to mbedTLS. 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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