This is an example / test for https://github.com/SFrijters/nix-qemu-espressif; it is kept out of that repository to keep it as lean as possible.
As an example we compile a simple 'blinking LED' Rust code based on an example in esp-hal for an ESP32C3 chip and run it on QEMU:
nix flake check -L
This command is also run in the GitHub action.
This flake also provides the following apps:
nix run .#emulate
(default app) to run the emulation test script directly.nix run .#flash
to flash the compiled code to a physical device.
And a development shell via:
nix develop
Inside the development shell, we can also use cargo
directly to build the binary:
$ nix develop
$ cd blinky && cargo build --release
Finally, there are three package outputs:
nix build .#elf-binary
builds only the ELF binary file.nix build .#emulate-script
(default package) builds a script to run the emulation test.nix build .#flash-script
builds a wrapper script to flash the binary to a physical device usingespflash
.
The code has been tested on a Seeed Studio XIAO ESP32C3. The GPIO10 pin corresponds to the D10 pin as marked on the board.
This example code works around a linker issue in nixpkgs in blinky/.cargo/config.toml. Please refer to the linked issue for details and please suggest a better/permanent fix if you know of one!