42 lines
1.2 KiB
Bash
Executable File
42 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build the Panagotchi firmware and flash it to the CH32V003 over single-wire
|
|
# debug (WCH-LinkE on DIO/PD1).
|
|
set -e
|
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$DIR"
|
|
|
|
TARGET=tama
|
|
|
|
# Regenerate sprites.h from the editable art generator (if python3 is present).
|
|
if command -v python3 >/dev/null 2>&1; then
|
|
echo ">> Generating sprites.h..."
|
|
python3 sprites_gen.py > sprites.h
|
|
fi
|
|
|
|
# --- Toolchain (xpack riscv-none-elf-gcc, bundles a ch32fun-compatible newlib) ---
|
|
XROOT="/home/superminaren/CH32V003/xpack-riscv-none-elf-gcc-14.2.0-3"
|
|
export PATH="$XROOT/bin:$PATH"
|
|
MAKEFLAGS_TC=(PREFIX=riscv-none-elf NEWLIB="$XROOT/riscv-none-elf/include")
|
|
|
|
MINICHLINK="$DIR/../ch32v003fun/minichlink/minichlink"
|
|
|
|
echo ">> Building..."
|
|
make clean >/dev/null 2>&1 || true
|
|
make "$TARGET.bin" "${MAKEFLAGS_TC[@]}"
|
|
|
|
echo ">> Flashing $TARGET.bin to CH32V003..."
|
|
# minichlink auto-switches the WCH-LinkE from ARM to RISC-V mode on first run;
|
|
# if that happens it asks for a re-attempt, so retry a few times.
|
|
for i in 1 2 3; do
|
|
if "$MINICHLINK" -w "$TARGET.bin" flash -b; then
|
|
echo ">> Done. The Panagotchi should now be running on the OLED."
|
|
exit 0
|
|
fi
|
|
echo ">> retry $i..."
|
|
sleep 1
|
|
done
|
|
|
|
echo ">> Flash failed after retries." >&2
|
|
exit 1
|