Repository navigation
Description
Summary
Bring up FastLED on the WCH CH32V003 (RV32EC @ 48 MHz, 16 KB flash / 2 KB SRAM). Hardware is on the bench.
Today FastLED has zero WCH code. The only artifact in the tree is ci/boards/package_ch32v_index.json — a snapshot of WCH's Arduino board-manager index added in 5cf16c9157 (2025-10-24), file only, never wired to anything. Someone started this and stopped.
Build/flash tooling is already done on the fbuild side and is being validated against real silicon in FastLED/fbuild#1208 — that issue is a prerequisite for Phase 2 here. This issue covers only src/platforms/wch/.
Why this part is harder than a normal port
Three constraints that no currently-supported FastLED platform has all of:
- No hardware multiply. RV32EC is the E base + C only — no M extension. Every
*,/,%becomes a libgcc call.scale8,blend8,nscale8x3, and the HSV→RGB paths are all multiply-heavy. This needs measuring before anything else. - 2 KB SRAM / 16 KB flash. Below every supported part. The
tinymemory class inci/boards.py:255-300is documented as<=1KB SRAMand holds the ATtinys; 16 KB flash is smaller than anything in the tree.FL_PLATFORM_HAS_TINY_MEMORYinsrc/fl/system/sketch_macros.h:55-76is currently set only byFL_IS_AVR_ATTINY_TINY_MEMORYand will need extending. - 16 registers, not 32 (
ilp32eABI). Register pressure in the timing-critical inner loop is real.
There is also a latent __riscv hazard: FastLED already treats RISC-V as a sub-branch of ESP (src/platforms/esp/32/core/delaycycles_riscv.h, interrupts/riscv.hpp, simd_riscv.hpp), reached via #elif defined(ESP32C3) || defined(ESP32C6) in src/platforms/delay.h:33 and src/platforms/delaycycles.h:26. This bit us once already — #2576/#2577 had to re-gate fast_isr.S on __riscv_atomic instead of bare __riscv because ESP32-C3 lacks the A extension. RV32EC lacks A and M. Every bare __riscv gate must be audited.
Template
The reference is the initial LPC845 port, commit ebd8791748 ("feat(platform): add LPC845 bit-bang clockless driver (#2836) (#2837)") — 9 files, 353 lines. src/platforms/arm/lpc/ has since grown to ~26 files, but that first commit is the minimal viable shape.
Required new files under src/platforms/wch/:
| File | Must define |
|---|---|
is_ch32.h |
FL_IS_WCH, FL_IS_WCH_CH32V00X, FL_IS_WCH_CH32V003. Per #2999 every detection macro is FL_IS_-prefixed and rolls up to a family. |
int.h |
integer typedefs |
led_sysdefs_wch_ch32.h |
F_CPU, FASTLED_ALLOW_INTERRUPTS, FASTLED_USE_PROGMEM 0, FASTLED_NO_PINMAP, RoReg/RwReg, cli()/sei(), vendor header include |
fastpin_wch_ch32.h |
_FL_DEFPIN table, HAS_HARDWARE_PIN_SUPPORT 1, port_ptr_t/port_t |
clockless_wch_ch32.h |
FL_CLOCKLESS_CONTROLLER_DEFINED 1 + ClocklessController |
fastled_wch_ch32.h |
aggregator |
README.md |
required by hook |
Existing files needing a new branch — all of these, because CH32V003 is a new architecture, not a new ARM chip:
src/platforms.h—⚠️ the final#elseis AVR, so an unhandled chip silently compiles against AVR headers rather than erroringsrc/led_sysdefs.h— final#elseis a hard#errorsrc/platforms/is_platform.h(include block, ~lines 141-156)src/platforms/fastpin.h,src/platforms/int.hsrc/platforms/delay.h,src/platforms/delaycycles.h— else falls todelaycycles_generic.h:16-22, a naivewhile(cycles--) nop;src/platforms/clockless.hsrc/platforms/ldf_headers.h,src/platforms/compile_test.cpp.hppsrc/platforms/_build.cpp.hpp
Detection macros available: the OpenWCH Arduino core / PlatformIO board record defines -DCH32V003 -DCH32V003F4 -DCH32V00X -DCH32V00x. Compiler-intrinsic: __riscv, __riscv_xlen == 32, __riscv_32e, __riscv_abi_rve, and the absence of __riscv_mul / __riscv_atomic.
Clockless output strategy
The community-proven WS2812 path on this part is SPI + DMA, not bit-bang — at 48 MHz with no multiplier the bit window is tight. Prior art:
cnlohr/ch32fun→extralibs/ws2812b_dma_spi_led_driver.h— SPI+DMA on MOSI (PC6), chunked center-interrupt double-buffering so only a few LEDs are resident in RAM at a time (critical at 2 KB), ~6% CPU while streaming. Alsoextralibs/ws2812b_simple.hfor blocking bit-bang.- https://github.com/fabian-bxr/CH32V003-WS2812 — DMA
- https://github.com/wagiminator/CH32V003-NeoPixel-Pendant — bit-bang, 16 px
- https://github.com/shippoiincho/ch32v003examples — SPI @ 6 MHz, one byte per WS2812 bit
If bit-bang is attempted first, the model is src/platforms/arm/common/m0clockless_c.h, whose header comment (lines 143-155) explains why it uses compile-time NOP-counted delays rather than a cycle counter. Note its FL_ARM_M0_DELAY_LOOP variant exists precisely because ~48 unrolled delay sites cost too much SRAM on the 16 KB-SRAM LPC845 — on a 2 KB part the counted-loop variant is mandatory, not optional. CH32V003 does have a free-running 32-bit SysTick (STK_CNTL), unlike Cortex-M0's 24-bit down-counter, so a counter-based approach is worth measuring.
ChannelEngine handling both clockless and SPI modes — Capabilities(true, true), routing in show() on data->isSpi() vs data->isClockless(). Do not add a Bus::X_SPI enum value or a separate ChannelEngineXxxSPI. See src/fl/channels/README.md.
Step-by-step
Phase 0 — Feasibility spike (do this before writing a platform)
- Compile a trivial sketch for
genericCH32V003F4P6and measure the flash cost ofscale8/nscale8x3/hsv2rgb_rainbowwith no hardware multiply. If the softmul calls blow the 16 KB budget, the port needs multiply-free variants and that changes the whole plan. - Measure baseline flash/RAM for FastLED core minus drivers. Establish how many LEDs actually fit in 2 KB.
- Decide bit-bang vs SPI+DMA on measured numbers, not preference.
- Audit every bare
__riscv/__riscv_xlengate insrc/for ESP-IDF assumptions.
Exit criteria: a written go/no-go with real byte counts.
Phase 1 — Platform skeleton (compile-only, no hardware)
-
src/platforms/wch/is_ch32.h+ wire intois_platform.h. -
led_sysdefs_wch_ch32.h,int.h,fastpin_wch_ch32.h,fastled_wch_ch32.h. - Add branches to
platforms.handled_sysdefs.h. Verify the AVR#elsefallthrough is not being hit — assert on a WCH-only define incompile_test. -
src/platforms/wch/README.md. - Extend
sketch_macros.hmemory tiering; add WCH to theFL_PLATFORM_HAS_LARGE_MEMORY 0list (lines 88-103, already containsFL_IS_ARM_LPC). -
FastPintoggles a pin. No LED driver yet.
Exit criteria: clean compile, and a scope-verified GPIO toggle at a known rate confirming F_CPU is right.
Phase 2 — Clockless driver (needs hardware + fbuild#1208)
- Implement
clockless_wch_ch32.hper the Phase 0 decision. - Validate WS2812 timing on a scope: T0H/T1H/reset within spec across the full byte range.
- Confirm behaviour with interrupts enabled and disabled.
- Run a real strip; check for the classic first-pixel-green / phantom-pixel timing artifacts.
Exit criteria: a stable multi-pixel rainbow on physical WS2812s.
Phase 3 — Integrate
-
ci/boards.py: add aBoardentry. Model on the LPC precedent (lines 1205-1260) —platform="https://github.com/Community-PIO-CH32V/platform-ch32v.git",platform_needs_install=True,framework="arduino". Setmemory_classper Phase 1. -
.github/workflows/build_ch32v003.ymlfrom the template. Noteci/boards/package_ch32v_index.jsonalready exists and is consumed bybuild_template_custom_board.yml:41-44. -
platformio.ini,ci/ci-compile.py. - Add a WCH entry to the
ci/bloat.pychip map (it already has"esp32c3": ("riscv", "esp32c3")). -
compile_test.hpp,_build.cpp.hpp. - Decide whether to add
channel_drivers_wch.impl.hpp. Not required — the#elseinchannel_drivers.impl.cpp.hpproutes toshared/channel_drivers_null.impl.hpp(a no-op) and the classicClocklessControllerpath works fine. The cheap win if wanted isBusTraits<Bus::BIT_BANG>fromsrc/platforms/shared/bitbang/bus_traits.h; model onsrc/platforms/arm/lpc/channel_drivers_lpc.impl.hpp(39 lines).
Open question — toolchain
The OpenWCH Arduino core ships GCC 8.2.0 (riscv-none-embed-gcc) because it uses WCH's proprietary xw compressed-instruction extension (-march=rv32ecxw), which upstream GCC cannot consume. GCC 8.2.0 is a serious liability for a modern C++ library, and there is no arm64 macOS build.
fbuild instead ships xPack riscv-none-elf-gcc 14.2.0-3 with -march=rv32ec_zicsr -mabi=ilp32e — no xw, matching what ch32fun does. That is the path fbuild#1208 validates and the recommended default here.
_zicsr is mandatory from GCC 12 — GCC ≤11 folded CSR ops into the base ISA, so a bare -march=rv32ec on a modern toolchain silently loses csrr/csrw. This is the single most common CH32V003 build failure. Also verify the chosen xPack build actually ships an rv32ec/ilp32e libgcc multilib.
Tension to resolve: ci/boards.py assumes framework="arduino", which via PlatformIO pulls GCC 8.2.0 and rv32ecxw. Either accept GCC 8.2.0 for the PIO CI path, or override the toolchain in the board definition.
References
- fbuild bring-up: CH32V003 hardware bring-up: validate the existing CH32V pipeline on real silicon fbuild#1208
- ch32fun — https://github.com/cnlohr/ch32fun (most active; 1.5k★, WS2812 SPI+DMA driver, minichlink)
- OpenWCH Arduino core — https://github.com/openwch/arduino_core_ch32 (tag 1.0.4, 2023-12-18)
- Community PlatformIO platform — https://github.com/Community-PIO-CH32V/platform-ch32v
- xPack riscv-none-elf-gcc — https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases
- RISC-V precedents in-tree: esp32c3: fast_isr.S uses RISC-V atomic ops (lr.w/sc.w) but C3 lacks the A extension #2576/fix(esp32c3): gate fast_isr.S on __riscv_atomic, not bare __riscv #2577 (
__riscv_atomicgating), fix(build): add fast_isr.S to library.json srcFilter so ESP32 RISC-V PIO builds link #2502, feat(esp32-p4): add PIE (xesppie) SIMD backend to fl::simd #2536/feat(esp32-p4): PIE (xesppie) SIMD backend Tier-1 ops (#2536) #2538, fix: make fbuild own ESP RISC-V toolchain resolution without local path overrides #2700/chore(deps): bump fbuild 2.2.16 -> 2.2.17 (refs #2700) #2712 - LPC port template:
ebd8791748 PORTING.md(thin, but the official entry point)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Jul 28, 2026
Tracked by meta issue FastLED/fbuild#1209 (CH32V003 bring-up: this + FastLED/fbuild#1208).
Note on sequencing: Phase 0 (the multiply-free feasibility spike) is not blocked — it needs no hardware and no fbuild work. It should start in parallel with fbuild#1208 Phase 0/1, since a bad result there changes the shape of this whole port. Only Phase 2 (clockless driver) depends on fbuild#1208 reaching a verified flash.
zackees commentedon Jul 29, 2026
Data point from the fbuild side (FastLED/fbuild#1208 Phase 1, now verified on a real toolchain install):
A bare blink built with the OpenWCH Arduino core for
genericCH32V003F4P6costs:Toolchain confirmed as genuine RV32EC — the ELF reports
Flags: 0x9, RVC, RVE, soft-float ABI, so-march=rv32ec_zicsr -mabi=ilp32ereally is resolving the E-base multilib rather than silently falling back torv32i.This tightens Phase 0's feasibility question considerably. The Arduino core alone leaves roughly 7.5 KB flash and 868 bytes SRAM for FastLED plus the sketch. Phase 0 should measure against that headroom, not against the raw 16 KB / 2 KB figures in the issue body.
868 bytes of SRAM also constrains the driver choice directly: at 3 bytes per pixel a full framebuffer is ~100 px before anything else is allocated, which is an independent argument for the chunked / double-buffered streaming approach
ch32fun'sws2812b_dma_spi_led_driver.huses rather than a resident buffer.zackees commentedon Aug 20, 2026
Burn-down disposition: DEFERRED ? platform port and required probe are both absent
Current
masterstill has nosrc/platforms/wch/, no CH32V003Boardentry, no detection/dispatch branch, and no clockless or unified SPI-DMA engine. The only in-tree artifact remainsci/boards/package_ch32v_index.json.The fbuild prerequisite made useful progress in FastLED/fbuild#1208:
But the hardware prerequisite remains unmet. Fresh
fbuild port scanhas no1A86:8010/8012WCH-LinkE. The fbuild investigation established that the CH32V003 board's USB connector is power-only and no WCH programmer has ever been attached to this host; direct USB cannot flash this MCU.Remaining work is the complete Phase 0?3 program: measure FastLED math/code-size feasibility under the 868-byte headroom, audit RISC-V ISA gates, create the WCH platform skeleton, choose and implement a bit-bang or streaming SPI-DMA driver, then scope and strip-validate it on silicon before adding CI.
Resume when a WCH-LinkE is connected and wired to 3V3/GND/SWIO, with a CH32V003 target and scope/strip available. Run fbuild#1208's readback/core/blink sequence first; only then make the feasibility go/no-go and start the FastLED port. This is not safely reducible to one source-only PR in the current bench state.
dfleck commentedon Nov 3, 2026
I'm looking forward to FastLED support for CH32 chips. BTW the CH32V002 chip is almost as inexpensive, has twice the SRAM, and the _zmmul multiply instructions (but no divide).