RP2040 (Raspberry Pi Pico) firmware that programs a Wildbits/Foenix FPGA from an SD card, with an optional fallback to preloaded LZ4 images stored in flash.
- Reads a 2-bit context DIP switch to select one of four FPGA slots.
- Attempts SD card programming first (LZ4 blocks, gzip, then raw .bin).
- Falls back to LZ4 images stored in fixed flash slots if SD is unavailable.
- Prints the chosen method and timing over USB stdio if enabled.
The loader looks for these base paths (it tries .lz4, then .gz, then raw):
CNTX1/CFP95600C.binCNTX2/CFP95616E.binCNTX3/f256k2t9.binCNTX4/foenix138.bin
The .lz4 format is a simple block format generated by tools/mk_lz4_blocks.c
(not the LZ4 frame format).
LZ4 blobs can be built into flash at fixed addresses (2 MiB each):
- Slot 0:
0x10800000 - Slot 1:
0x10A00000 - Slot 2:
0x10C00000 - Slot 3:
0x10E00000
CMakeLists.txt reserves the top 8 MiB for these blobs.
Prereqs:
- Raspberry Pi Pico SDK
- CMake + a build tool (Ninja or Make)
- Python 3 (for UF2 concatenation)
picotool(optional, for combined UF2 with FPGA blobs)
Example build:
mkdir -p build
cd build
cmake ..
cmake --build .Artifacts (in build/):
fpga_mgr.uf2(main firmware)fpga_mgr.elf/fpga_mgr.binfpga_mgr_with_fpga.uf2(ifpicotool+ Python are found)
If picotool and Python 3 are available, CMake exposes a target that bundles
the firmware UF2 with the LZ4 images from fpga/ into one UF2:
cmake --build . --target fpga_mgr_with_fpga_uf2tools/mk_lz4_blocks.c: converts a raw.binto the block-based.lz4format the loader expects.tools/concat_uf2.py: concatenates UF2 files to form a single image.