{"id":13710696,"url":"https://github.com/nmeum/zig-riscv-embedded","last_synced_at":"2025-04-08T00:31:58.045Z","repository":{"id":74907425,"uuid":"254956570","full_name":"nmeum/zig-riscv-embedded","owner":"nmeum","description":"Experimental Zig-based CoAP node for the HiFive1 RISC-V board","archived":false,"fork":false,"pushed_at":"2023-11-23T23:00:58.000Z","size":255,"stargazers_count":33,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T03:31:55.476Z","etag":null,"topics":["bare-metal","coap","coap-server","embedded","hifive1","risc-v","riscv","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nmeum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-04-11T21:14:10.000Z","updated_at":"2024-09-12T03:08:13.000Z","dependencies_parsed_at":"2023-11-24T00:20:44.001Z","dependency_job_id":"e2985478-5145-4ea3-abf9-96c28aa99800","html_url":"https://github.com/nmeum/zig-riscv-embedded","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmeum%2Fzig-riscv-embedded","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmeum%2Fzig-riscv-embedded/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmeum%2Fzig-riscv-embedded/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmeum%2Fzig-riscv-embedded/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmeum","download_url":"https://codeload.github.com/nmeum/zig-riscv-embedded/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755409,"owners_count":20990617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["bare-metal","coap","coap-server","embedded","hifive1","risc-v","riscv","zig"],"created_at":"2024-08-02T23:00:59.947Z","updated_at":"2025-04-08T00:31:57.599Z","avatar_url":"https://github.com/nmeum.png","language":"Zig","funding_links":[],"categories":["Systems Programming"],"sub_categories":["Embedded Development"],"readme":"# zig-riscv-embedded\n\nExperimental [Zig][zig website]-based [CoAP][rfc7252] node for the [HiFive1][hifive1 website] RISC-V board.\n\n![World's first IoT-enabled Zig-based constrained node](https://gist.github.com/nmeum/9c921cac9e28e722a8415af3ff213e8c/raw/b936f1f05d5eda07a91a87efdaf5cb1552795ad1/output-2fps-960px.gif)\n\n## Status\n\nThis repository is intended to provide a simple sample application for\nexperimenting with the Zig programming language on freestanding RISC-V.\nThe application targets the [SiFive FE310-G000][fe310 manual] or more\nspecifically the [HiFive 1][hifive1 website]. While possible to run the\napplication on \"real hardware\", it can also be run using QEMU. In both\ncases it is possible to toggle an LED using [CoAP][rfc7252] over\n[SLIP][rfc1055].\n\n## CoAP over SLIP\n\nTo experiment with external dependencies in Zig, this application\nprovides a very bare bone implementation of [CoAP][rfc7252] using\n[zoap][zoap github]. Since implementing an entire UDP/IP stack from\nscratch is out-of-scope, this repository transports CoAP packets\ndirectly over [SLIP][rfc1055].\n\nUnfortunately, the QFN48 package of the FE310-G000 (as used by the\nHiFive1) does not support the UART1. For this reason, the application\nmultiplexes diagnostic messages and CoAP frames over the same UART\n(UART0) using [Slipmux][slipmux]. For this purpose, a Go-based\nmultiplexer for the development system is available in the `./slipmux`\nsubdirectory.\n\n## Dependencies\n\nFor building the software and the associated Slipmux tooling, the\nfollowing software is required:\n\n* Zig `0.9.1`\n* [Go][golang web] for compiling the `./slipmux` tool\n* A CoAP client, e.g. `coap-client(1)` from [libcoap][libcoap github]\n* QEMU (`qemu-system-riscv32`) for emulating a HiFive1 (optional)\n\nFor flashing to real hardware, the following software is required:\n\n* [riscv-openocd][riscv-openocd]\n* [GDB][gdb web] with 32-bit RISC-V support\n\n## Building\n\nThe Zig build system is used for building the application, the\nconfiguration is available in `build.zig`. To build the application run:\n\n\t$ zig build\n\nThis will create a freestanding RISC-V ELF binary `zig-out/bin/main`.\nIf the image should be booted on real hardware, building in the\n`ReleaseSmall` [build mode][zig build modes] may be desirable:\n\n\t$ zig build -Drelease-small\n\nFurthermore, the Slipmux multiplexer needs to be compiled using the\nfollowing commands in order to receive diagnostic messages from the\ndevice and send CoAP messages to the device:\n\n\t$ cd slipmux \u0026\u0026 go build -trimpath\n\n## Booting in QEMU\n\nIn order to simulate a serial device, which can be used with the\n`./slipmux` tool, QEMU must be started as follows:\n\n\t$ qemu-system-riscv32 -M sifive_e -nographic -kernel zig-out/bin/main -serial pty\n\nQEMU will print the allocated PTY path to standard output. In a separate\nterminal the `./slipmux` tool can then be started as follows:\n\n\t$ ./slipmux/slipmux :2342 \u003cPTY allocated by QEMU\u003e\n\nThis will create a UDP Socket on `localhost:2342`, CoAP packets send to\nthis socket are converted into Slipmux CoAP frames and forwarded to the\nemulated HiFive1 over the allocated PTY. CoAP packets can be send using\nany CoAP client, e.g. using `coap-client(1)` from [libcoap][libcoap github]:\n\n\t$ coap-client -N -m put coap://[::1]:2342/on\n\t$ coap-client -N -m put coap://[::1]:2342/off\n\nIn QEMU, this will cause debug messages to appear in the terminal window\nwere `./slipmux` is running. On real hardware, it will also cause the\nred LED to be toggled.\n\n## Booting on real hardware\n\nThe binary can be flashed to real hardware using OpenOCD and gdb. For\nthis purpose, a shell script is provided. In order to flash a compiled\nbinary run the following command:\n\n\t$ ./flash\n\nAfter flashing the device, interactions through CoAP are possible using\nthe instructions given for QEMU above. However, with real hardware\n`./slipmux` needs to be passed the TTY device for the HiFive1 (i.e.\n`/dev/ttyUSB0`).\n\nTo debug errors on real hardware start OpenOCD using `openocd -f\nopenocd.cfg`. In a separate terminal start a gdb version with RISC-V\nsupport (e.g. [gdb-multiarch][gdb-multiarch alpine]) as follows:\n\n\t$ gdb-multiarch -ex 'target extended-remote :3333' zig-out/bin/main\n\n## Development\n\nA pre-commit git hook for checking if files are properly formated is\nprovided in `.githooks`. It can be activated using:\n\n\t$ git config --local core.hooksPath .githooks\n\n## License\n\nThe application uses slightly modified linker scripts and assembler\nstartup code copied from the [RIOT][riot fe310] operating system. Unless\notherwise noted code written by myself is licensed under\n`AGPL-3.0-or-later`. Refer to the license headers of the different files\nfor more information.\n\n[zig website]: https://ziglang.org/\n[zig build modes]: https://ziglang.org/documentation/master/#Build-Mode\n[qemu website]: https://www.qemu.org/\n[fe310 manual]: https://static.dev.sifive.com/FE310-G000.pdf\n[hifive1 website]: https://www.sifive.com/boards/hifive1\n[riot fe310]: https://github.com/RIOT-OS/RIOT/tree/master/cpu/fe310\n[slipmux]: https://datatracker.ietf.org/doc/html/draft-bormann-t2trg-slipmux-03\n[rfc7252]: https://datatracker.ietf.org/doc/html/rfc7252\n[rfc1055]: https://datatracker.ietf.org/doc/html/rfc1055\n[libcoap github]: https://github.com/obgm/libcoap\n[golang web]: https://golang.org\n[zoap github]: https://github.com/nmeum/zoap\n[riscv-openocd]: https://github.com/riscv/riscv-openocd\n[gdb web]: https://www.gnu.org/software/gdb/\n[gdb-multiarch alpine]: https://pkgs.alpinelinux.org/package/edge/main/x86_64/gdb-multiarch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmeum%2Fzig-riscv-embedded","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmeum%2Fzig-riscv-embedded","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmeum%2Fzig-riscv-embedded/lists"}