I've built a version of my C firmware that runs in the browser. I stubbed the hardware peripherals using JavaScript, I can run, test, and validate high-level logic directly in the browser without needing to flash the real device.

This approach has several benefits:
- I can simulate soil humidity changes and similar inputs, making firmware validation much easier.
- It allows for logging directly from the firmware (which the hardware build can't do, since the PIC10F202 lacks a UART peripheral).
- Additionally, I have coded a small logic analyzer that displays the state of all the microcontroller's GPIOs and allows me to set input pins, simulating data from push buttons and soil sensors.
The simulation setup includes:
- High-level firmware code: this does not communicate with hardware directly, but instead uses a Hardware Abstraction Layer (HAL).
- Tiny HAL in firmware: when built for hardware, use real peripherals; when built for emulation, use JavaScript hooks.
- WASM Compilation: the firmware is compiled from C to WebAssembly using Emscripten, which also generates the necessary JavaScript glue code. The build process uses Meson (I wanted to try something new, could be cmmake instead), and for easy launching, I use the just tool - it’s excellent for automating one-liners, and I’ll definitely be using it more often!!
- TypeScript application: this orchestrates the firmware via the aforementioned hooks and handles the web page display.
- HTML and CSS: The frontend structure for the web interface.
You can check the source code on project's GitHub.
Ultimately, WASM is quite an interesting technology!
Robert Gawron
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.