Repository navigation
Platform Raspberry Pi Pico
Backend for the Pico SDK: RP2040 (Pico, Pico W) and RP2350. Supports GPIO, PWM, ADC, UART, I2C, SPI, pin interrupt counters, watchdog, random and console. The deep_sleep import returns unsupported.
cmake_minimum_required(VERSION 3.13)
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
project(app C CXX ASM)
pico_sdk_init()
add_executable(app main.c eccles-wasm/src/eccles_wasm.c)
target_include_directories(app PRIVATE eccles-wasm/src .)
target_link_libraries(app pico_stdlib hardware_gpio hardware_adc hardware_pwm
hardware_i2c hardware_spi hardware_uart hardware_watchdog pico_rand)
pico_enable_stdio_usb(app 1)
pico_add_extra_outputs(app)/* Raspberry Pi Pico SDK. CMake: target_link_libraries(app pico_stdlib hardware_gpio hardware_adc
* hardware_pwm hardware_i2c hardware_spi hardware_uart hardware_watchdog pico_rand) + add eccles_wasm.c.
* For a file instead of an array, add a FatFs port (e.g. no-OS-FatFS-SD-SDIO-SPI-RPi-Pico): ff.h on the
* include path switches eccles_wasm_load("0:/app.wasm") on automatically. */
#include "pico/stdlib.h"
#include "eccles_wasm.h"
#include "blink_wasm.h"
int main(void) {
stdio_init_all();
eccles_wasm_set_hal_privilege(ECCLES_WASM_ALLOW_PIN_ALL | ECCLES_WASM_ALLOW_SAFE); /* v2: grant what the module may use */
if (eccles_wasm_load_buffer(blink_wasm, sizeof blink_wasm) != ECCLES_WASM_SUCCESSFUL) return 1;
eccles_wasm_run("setup"); /* guest LED = GP2 (use 25 for the on-board LED: edit the guest) */
for (;;) eccles_wasm_run("loop");
}(file: examples/pico/main.c)
Make blink_wasm.h from examples/blink_wasm.h or tools/wasm2c.py. The example blink guest uses GP2; to use the on-board LED edit the guest's pin to 25 (Pico) or the correct GPIO for your board (Pico W uses the radio chip for its LED: use an external LED on a GP pin).
- Pin = GP number (0 to 29 on RP2040).
- ADC: GP26 to GP29 only.
- UART 0, 1; I2C 0, 1; SPI 0, 1.
-
pwmandanalogare on slices: two pins on the same slice share a frequency.
The arena is a static array by default, 96 KB. RP2040 has 264 KB of RAM, so a stock module fits. To squeeze more room set -DECCLES_WASM_ARENA_SIZE=... and -DECCLES_WASM_MEM_LIMIT_BYTES=... with target_compile_definitions(app PRIVATE ...).
Add a FatFs SD library for the Pico: when ff.h is on the include path, eccles_wasm_load("0:/app.wasm") works automatically. For other storage see Custom Filesystems.
ECCLES_WASM_EXEC_IRAM=1 puts the loop in .time_critical (RAM). Combined with ECCLES_WASM_FUEL=0 that is the fastest configuration. See Speed Tuning.
The Pico has two cores. Use FreeRTOS SMP or the Pico multicore API in your spawner: Threads and the Spawner.
| Symptom | Fix |
|---|---|
| no output on the USB serial |
pico_enable_stdio_usb(app 1) and wait for the host to open the port; grant ECCLES_WASM_PERM_LOG
|
adc returns failed |
pin is not 26 to 29 |
link error for pwm_*, adc_*
|
add hardware_pwm, hardware_adc to target_link_libraries
|
ECCLES_WASM_ARENA_SIZE too big: region RAM overflowed
|
lower the arena |
More: Troubleshooting.
Eccles WASM 2.0.0 · MIT · Repository · Report a problem · Support ♥
Start here
Platforms
Use it
- Writing Guests
- Guest Import Reference
- Loading Modules
- Custom Filesystems
- Host Functions
- Permissions
- Instances
- Threads and Spawner
- Atomics
- Safety, Fuel and Traps
Reference
Proof
More