β οΈ DEPRECATED: This repository is being archived and replaced by V4-runtime.V4-runtime provides a unified runtime environment with better FreeRTOS integration and improved architecture. Please migrate to V4-runtime for new projects.
Hardware Abstraction Layer (HAL) implementations for V4 VM across various microcontrollers and SoCs.
V4-ports provides platform-specific HAL implementations that enable V4 VM to run on embedded hardware. Each port implements the HAL API defined in V4.
V4-ports (HAL implementation, MCU-specific) β This repository
β depends on
V4 (VM core, ISA, HAL API contract)
β depends on
V4-front (Forth β Bytecode compiler)
V4-repl (Interactive loop, optional)
| Platform | Status | MCU/SoC | Architecture | Notes |
|---|---|---|---|---|
| ESP32-C6 | β Stable | ESP32-C6 | RISC-V 32-bit | NanoC6 reference |
| CH32V | π§ Planned | CH32V003/307 | RISC-V 32-bit | Coming soon |
| RP2350 | π§ Planned | RP2350 | ARM Cortex-M33 + RISC-V | Coming soon |
- Board: ESP32-C6 DevKit or NanoC6
- CPU: RISC-V 32-bit @ 160MHz
- RAM: 512KB SRAM
- Flash: 4MB (external)
- Connectivity: USB-CDC (UART0)
- ESP-IDF: v5.3 or later
- CMake: 3.16 or later
- Python: 3.8 or later
- Toolchain: RISC-V GCC (included in ESP-IDF)
# Clone repository
git clone https://github.com/kirisaki/v4-ports.git
cd v4-ports
# Clone dependencies (v4 and v4-front)
git clone https://github.com/kirisaki/v4.git
git clone https://github.com/kirisaki/v4-front.git
# Start Docker container
docker compose run --rm esp-idf
# Inside container: Build v4-blink example
cd esp32c6/examples/v4-blink
idf.py build
# Flash to device (connect USB cable)
idf.py flash monitor# Install ESP-IDF (if not already installed)
# See: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c6/get-started/
# Clone repository and dependencies
git clone https://github.com/kirisaki/v4-ports.git
cd v4-ports
git clone https://github.com/kirisaki/v4.git
git clone https://github.com/kirisaki/v4-front.git
# Setup ESP-IDF environment
. $IDF_PATH/export.sh
# Build v4-blink example
cd esp32c6/examples/v4-blink
idf.py build
# Flash and monitor
idf.py flash monitorSimple LED blink example to verify GPIO and Timer HAL.
cd esp32c6/examples/v4-blink
idf.py build flash monitorFeatures:
- Toggles LED at 1Hz
- Prints status to serial console
- Demonstrates GPIO output and timer functions
Hardware Setup:
- Uses on-board LED on GPIO7 (standard LED)
- Note: GPIO8 is WS2812 RGB LED (requires special driver)
- No external components required
- See
esp32c6/examples/v4-blink/README.mdfor details
Interactive Forth REPL over UART.
cd esp32c6/examples/v4-repl-demo
idf.py build flash monitorFeatures:
- Interactive Forth shell
- UART-based command input
- Compile and execute Forth code on-the-fly
- Stack inspection
Example session:
v4> 2 3 +
=> 5 (0x00000005)
v4> : SQUARE DUP * ;
ok
v4> 7 SQUARE
=> 49 (0x00000031)
v4>
Bytecode transfer via V4-link protocol over USB Serial/JTAG.
cd esp32c6/examples/v4-link-demo
idf.py build flash monitorFeatures:
- Frame-based bytecode transfer protocol
- CRC-8 error detection
- Commands: EXEC, PING, RESET
- Non-blocking UART communication
- 512B bytecode buffer, 4KB VM memory
Protocol:
Frame: [STX(0xA5)][LEN_L][LEN_H][CMD][DATA...][CRC8]
Usage:
- Send compiled bytecode from host PC
- Executes bytecode on V4 VM
- Suitable for remote code deployment
- See
esp32c6/examples/v4-link-demo/README.mdfor Python host script example
The ESP32-C6 port implements the following V4 HAL APIs:
v4_hal_gpio_init()- Initialize GPIO pin with mode (input/output/pullup/pulldown)v4_hal_gpio_write()- Write digital output (HIGH/LOW)v4_hal_gpio_read()- Read digital input state
v4_hal_uart_init()- Initialize UART peripheral with baud ratev4_hal_uart_putc()- Send a single characterv4_hal_uart_getc()- Receive a single character (non-blocking)v4_hal_uart_write()- Write data buffer to UARTv4_hal_uart_read()- Read data from UART (non-blocking)
v4_hal_delay_ms()- Blocking delay in millisecondsv4_hal_delay_us()- Blocking delay in microsecondsv4_hal_millis()- Get milliseconds since bootv4_hal_micros()- Get microseconds since boot
v4_hal_system_reset()- Reset the systemv4_hal_system_info()- Get system information string
v4-ports/
βββ esp32c6/ # ESP32-C6 port
β βββ components/
β β βββ v4_hal_esp32c6/ # HAL implementation
β β β βββ CMakeLists.txt
β β β βββ include/
β β β β βββ v4_hal_esp32c6.h
β β β βββ src/
β β β βββ hal_gpio.c
β β β βββ hal_uart.c
β β β βββ hal_timer.c
β β β βββ hal_system.c
β β βββ v4_link/ # V4-link bytecode transfer
β β βββ CMakeLists.txt
β β βββ idf_component.yml
β β βββ v4_link_port.hpp
β β βββ v4_link_port.cpp
β βββ examples/
β βββ v4-blink/ # LED blink example
β βββ v4-repl-demo/ # REPL example
β βββ v4-link-demo/ # Bytecode transfer example
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI
βββ docker-compose.yml # Docker development environment
βββ README.md
# Start container
docker compose run --rm esp-idf
# Build specific example
cd esp32c6/examples/v4-blink
idf.py build
# Clean build
idf.py fullcleanBefore committing, format your code:
# Format all C/C++ and CMake files
make format
# Check formatting (without modifying files)
make format-checkRequirements:
clang-format- C/C++ code formattingcmake-format- CMake files formatting
Install tools:
# Ubuntu/Debian
sudo apt-get install clang-format
pip install cmake-format
# macOS
brew install clang-format
pip install cmake-format
# Docker (ESP-IDF container)
pip install cmake-format
# clang-format is already included- Define the function in
v4/include/v4/v4_hal.h - Implement it in
esp32c6/components/v4_hal_esp32c6/src/hal_*.c - Update tests and examples
- Run formatting and CI checks
This repository uses GitHub Actions for continuous integration:
- Build Check: Builds all examples for ESP32-C6
- Format Check: Verifies code formatting with clang-format
- Artifact Upload: Stores compiled binaries
See .github/workflows/ci.yml for details.
Problem: idf.py: command not found
- Solution: Run
. $IDF_PATH/export.shto setup ESP-IDF environment
Problem: v4/v4_hal.h: No such file or directory
- Solution: Ensure v4 is cloned in the parent directory or set
V4_PATH
Problem: UART not working on ESP32-C6
- Solution: ESP32-C6 uses USB-CDC for UART0. Connect via USB and use the CDC serial port.
Problem: Build fails with memory errors
- Solution: Increase
CONFIG_ESP_MAIN_TASK_STACK_SIZEinsdkconfig.defaults
- ESP-IDF Documentation: https://docs.espressif.com/projects/esp-idf/
- ESP32-C6 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf
- V4 Project Issues: https://github.com/kirisaki/v4-ports/issues
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Format code with
make format - Verify formatting with
make format-check - Submit a pull request
- Follow ESP-IDF coding style
- Use C language for HAL implementations
- Add comments for complex logic
- Update documentation as needed
This project is dual-licensed under:
- Apache License 2.0 (
LICENSE-APACHE) - MIT License (
LICENSE-MIT)
You may choose either license for your use.
- V4 - VM core implementation
- V4-front - Forth compiler frontend
- V4-repl - Interactive REPL
- V4-link - Bytecode transfer protocol
Status: Active Development | Version: 0.1.0 | Last Updated: 2025