https://github.com/ghostiam/ch32v003_zig
ch32v003 from scratch in Zig. Just using `zig build`!
https://github.com/ghostiam/ch32v003_zig
ch32v ch32v003 embedded embedded-zig wch zig ziglang
Last synced: 8 months ago
JSON representation
ch32v003 from scratch in Zig. Just using `zig build`!
- Host: GitHub
- URL: https://github.com/ghostiam/ch32v003_zig
- Owner: ghostiam
- License: mit
- Created: 2025-02-24T22:49:14.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-02-25T01:31:29.000Z (8 months ago)
- Last Synced: 2025-02-25T02:29:48.413Z (8 months ago)
- Topics: ch32v, ch32v003, embedded, embedded-zig, wch, zig, ziglang
- Language: Zig
- Homepage:
- Size: 3.44 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ch32v003 from scratch in Zig
Examples range from simple to complex. Everything is compiled with a simple `zig build`. \
The [minichlink](tools/minichlink) flasher is also included and can be
compiled using `zig build` as well.## Getting Started
> [!NOTE]
> If you are using `nix`, you can simply run `nix develop` in the root of the project, and it will automatically install
> `zig`, `zigscient`, and `minichlink` in your environment.
> And you can skip to the [Build and upload the example](#build-and-upload-the-example) section.### Install Zig
Currently, the examples are tested with `0.14.0-dev.3328`.\
You can download the latest version from:
https://ziglang.org/download/### Build the flasher
```shell
cd tools/minichlink
zig build --release=safe# Add the `minichlink` to your `PATH`:
export PATH=$PATH:$(pwd)/zig-out/bin
```### Build and upload the example
```shell
cd 001_blink_minimal
zig build
minichlink -w zig-out/firmware/ch32v003_blink.bin flash -b
```## Useful Notes
### Flashing
```shell
# Write and reboot.
minichlink -w zig-out/firmware/ch32v003_blink.bin flash -b
```### Debugging
```shell
# Run GDB server.
minichlink -G
# Reboot into halt and run GDB server
# (firmware will be halted until GDB is connected).
minichlink -a -G
```In `CLion`: add a new `Remote Debug` configuration.

### Show firmware info
```shell
# Size (clang)
size zig-out/firmware/ch32v003_blink.elf
# Sections info (clang)
objdump -h zig-out/firmware/ch32v003_blink.elf
bloaty zig-out/firmware/ch32v003_blink.elf
````### Dump memory
```shell
minichlink -r memory.bin 0x20000000 2048
```### UART
```shell
screen /dev/tty.usbmodem* 115200
````Ctrl + A`, `Ctrl + \` - Exit screen and terminate all programs in this screen. \
`Ctrl + D`, `D` or `Ctrl + A`, `Ctrl + D` - "minimize" screen and `screen -r` to restore it.