{"id":15417125,"url":"https://github.com/mabezdev/esp32s2-wasm-demo","last_synced_at":"2026-05-06T12:50:16.325Z","repository":{"id":140619184,"uuid":"426952107","full_name":"MabezDev/esp32s2-wasm-demo","owner":"MabezDev","description":null,"archived":false,"fork":false,"pushed_at":"2021-11-11T10:02:47.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-13T12:50:24.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MabezDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-11T10:02:46.000Z","updated_at":"2021-11-12T07:09:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"858a2473-1d50-41ce-8579-c014d3a0c97c","html_url":"https://github.com/MabezDev/esp32s2-wasm-demo","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"d987c13068f0116241176a7e337856960ccaf4e1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"igrr/esp32s2-wasm-demo","purl":"pkg:github/MabezDev/esp32s2-wasm-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MabezDev%2Fesp32s2-wasm-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MabezDev%2Fesp32s2-wasm-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MabezDev%2Fesp32s2-wasm-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MabezDev%2Fesp32s2-wasm-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MabezDev","download_url":"https://codeload.github.com/MabezDev/esp32s2-wasm-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MabezDev%2Fesp32s2-wasm-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32694980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T08:33:17.875Z","status":"ssl_error","status_checked_at":"2026-05-06T08:33:17.221Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T17:14:41.549Z","updated_at":"2026-05-06T12:50:16.311Z","avatar_url":"https://github.com/MabezDev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ESP32-S2 WebAssembly Demo\n\nThis project will demonstrate WebAssembly code running on ESP32-S2. There are two parts in this project:\n\n* ESP-IDF application for the ESP32-S2, inside [firmware](firmware/) directory.\n\n  It contains [WASM3](https://github.com/wasm3/wasm3) WebAssembly interpreter, mass storage device emulation and some glue code to make everything work.\n\n* C application inside [wasm](wasm/) directory, which is compiled to WebAssembly using [Emscripten](https://emscripten.org/docs/introducing_emscripten/about_emscripten.html) compiler.\n\n## Demo overview\n\nThe demo has the following steps:\n\n1. Set up ESP32-S2 hardware.\n2. Build the firmware for the ESP32-S2 and flash it to the board.\n3. A USB drive (mass storage device) emulated by ESP32-S2 will appear in the system.\n4. Build the WebAssembly application.\n5. Copy the WebAssembly application to USB drive.\n6. Eject the USB drive.\n7. The firmware will load and execute WebAssembly module, then go back to step 3.\n\n## Getting started with Gitpod workspace\n\nTo get started, create a project from this template by clicking \"Use this template\" on Github.\n\nSign into [gitpod.io](https://gitpod.io/) and create a new workspace based on the project you have created.\n\nThe workspace contains the project itself, ESP-IDF and Emscripten SDK.\n\nInside the workspace, three _tasks_ are defined:\n\n* Build (firmware) — builds firmware (application for ESP32-S2)\n* Build (wasm) — builds WebAssmebly module\n* Clean (wasm) — cleans WebAssembly module output\n\n## Step by step\n\n### Step 1: set up hardware\n\n1. Connect a USB cable to an ESP32-S2 development board: GPIO19: white, GPIO20: green, GND: black. Note: you need an ESP32-S2 development board with PSRAM!\n2. Plug USB cable into the PC, while holding \"BOOT\" button.\n3. Check Device Manager (Windows), lsusb (Linux), System Information (macOS) and verify that an ESP32-S2 device is in the list.\n\n### Step 2: build and flash the firmware\n\n1. Press F1, select \"Tasks: Run task\", choose \"Build (firmware)\" task. This will build the application for ESP32-S2.\n2. DFU binary will be located in [firmware/build/dfu.bin](firmware/build/dfu.bin). Right-click this file and choose \"Download\". Save it somewhere on your computer.\n3. Install dfu-util if you don't have it yet. On Linux and macOS it can be installed using the package managers. On Windows it is installed together with IDF.\n4. Reboot the development board into download mode: press and hold Boot button, click Reset button, release Boot.\n5. Flash the board with dfu-util: `dfu-util -D dfu.bin`.\n6. Reset the board by pressing Reset button.\n\n### Step 3: ESP32-S2 USB drive will appear in the system\n\nThis USB mass storage device is emulated by the application flashed in the previous step. The volume name should be `NO NAME`.\n\nAt the same time, LED on the ESP32-S2 board will turn blue.\n\n### Step 4: build WebAssembly module\n\nPress F1, select \"Tasks: Run task\", choose \"Build (wasm)\" task. This will build the webassembly module.\n\n### Step 5: copy WebAssembly module to ESP32-S2 USB drive\n\nLocate [wasm/hello.wasm](wasm/hello.wasm), right-click, choose \"Download\", select location in the root directory of the USB drive.\n\n### Step 6: eject the USB drive\n\nEject the USB device from the computer (using Explorer, Finder, etc.)\n\n### Step 7: the firmware will execute the WebAssembly module\n\nThe firmware will select the latest wasm file and try to run it.\n\nThe LED will turn green when the execution starts.\n\nOutput from WebAssembly module will go to UART console of the ESP32-S2. Use some serial monitor to see the output, for example `python3 -m serial.tools.miniterm /dev/ttyUSB0 115200`. The example program [wasm/hello.c](wasm/hello.c) will print \"Hello world\" to the console.\n\nWhen the module finishes executing, the USB mass storage device will appear in the system again, going back to step 3.\n\nNote, if the WebAssembly interpreter crashes and the chip resets, it will go into USB disk mode and let you upload a new program.\n\n## Next steps\n\nWebassmebly module is located in [wasm/hello.c](wasm/hello.c). It can call functions exported from C by the firmware. The exported functions are defined in [firmware/main/wasm.cpp](firmware/main/wasm.cpp). See `delay_ms` function definition and `mod.link_optional` calls for an example.\n\nThere are also _a few_ WASI functions defined in [m3_api_esp_wasi.c](firmware/components/wasm3/wasm3/platforms/embedded/esp32-idf-wasi/main/m3_api_esp_wasi.c).\n\nThe development board features an LED. Can you make the LED blink or change colors from WebAssembly?\n\nThere is a `void status_rgb(int r, int g, int b)` function that you can use, arguments `r`, `g`, `b` can be in [0, 255] range.\n\nYou can also look at the list of WASI functions implemented in [m3_api_esp_wasi.c](firmware/components/wasm3/wasm3/platforms/embedded/esp32-idf-wasi/main/m3_api_esp_wasi.c) and try to implement some more. For example, can you make your WebAssembly module write to a file? On the ESP32-S2, the filesystem is mounted to the `/data` directory.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmabezdev%2Fesp32s2-wasm-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmabezdev%2Fesp32s2-wasm-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmabezdev%2Fesp32s2-wasm-demo/lists"}