Vlad Tomoiagă Puts Linux on the $0.15 WCH CH32V003 RISC-V Microcontroller

Using Charles Lohr's 400-line RISC-V emulator, the low-cost CH32V003 is able to run code designed for considerably costlier parts.

Gareth Halfacree
8 months agoHW101

Electronics engineering student and self-described "microcontroller enjoyer" Vlad Tomoiagă has given the Linux kernel a new platform on which to stretch its wings — by successfully running it on the ultra-low-cost $0.15-a-chip WCH Electronics CH32V003 RISC-V microcontroller.

"This project enables the CH32V003 microcontroller to run Linux," Tomoiagă explains of the linux-ch32v003 project, brought to our attention by Adafruit. "It achieves this by using an 8 megabyte SPI PSRAM [Pseudo-Static RAM] chip and a RISC-V emulator. The emulation is needed because the PSRAM cannot be mapped into the address space of the microcontroller. The Linux kernel and rootfs is loaded into PSRAM at boot from an SD Card. FAT filesystem access is provided by the Petit FatFS library."

The secret to the project's success: an ultra-compact RISC-V emulator written by Charles Lohr in just 400 lines of code. While it may seem strange to emulate RISC-V on a chip which is already RISC-V, it's necessary for Linux compatibility: the CH32V003, like most RISC-V microcontrollers, lacks the required memory management capabilities to run Linux — something that can be emulated in software, albeit with a clear impact on performance.

Tomoiagă isn't the only one to have used Lohr's emulator to get Linux running on unlikely platforms: back in October last year Giang Vinh Loc showed off a minimal Linux installation running on the eight-bit Microchip ATmega328P at the heart of an Arduino UNO — booting in a mere 15 hours and 44 minutes. A pseudonymous developer going by the name "bilman66" may have that beaten, though, by porting Lohr's emulator — and Linux — to the Scratch visual programming language.

As for the performance of Tomoiagă's port? "Boot time is around five minutes," he writes. The source code is available on GitHub under the permissive MIT license, for anyone who wants to try it for themselves.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles