Skip to content

ZanzyTHEbar/riscv-dev

Repository files navigation

RISC-V Development Environment

Build Status License: MIT Go Version

A comprehensive development environment for RISC-V embedded systems featuring Go programming, Buildroot integration, and practical examples demonstrating real-world RISC-V development workflows.

🚀 Ready-to-use examples | 🧪 Tested with QEMU | 📦 Buildroot integration | 🐳 Dev container support

Overview

This repository provides a complete RISC-V development ecosystem with:

  • Cross-compilation toolchain for RISC-V 64-bit Linux
  • Go programming examples demonstrating embedded systems concepts
  • Buildroot integration for custom embedded Linux distributions
  • QEMU emulation for testing and development
  • Dev container support for consistent development environments
  • Practical examples covering GPIO, networking, sensors, and system monitoring

Quick Start

Using Dev Container (Recommended)

  1. Prerequisites: Docker and VS Code with Dev Containers extension
  2. Clone and open: Open this repository in VS Code
  3. Reopen in container: Use Command Palette → "Dev Containers: Reopen in Container"
  4. Build examples: Run make to build all examples
  5. Run an example: Try make run-example-gpio-led

🚀 One-Command Setup

# Clone, build, and test everything
git clone <repository-url> riscv-dev-standalone
cd riscv-dev-standalone
make build-examples && make test

✅ Verified Build Results

All examples successfully cross-compile to RISC-V 64-bit:

Example Binary Size Status
GPIO LED ~1.5MB ✅ Built & QEMU Tested
Network Server ~1.8MB ✅ Built & Verified
Sensor Reading ~1.6MB ✅ Built & Verified
Buildroot App ~2.1MB ✅ Built & Verified

QEMU Test Results:

🚀 Running GPIO LED example with QEMU...
💡 LED HIGH (blink #1)
💡 LED LOW (blink #2)
💡 LED HIGH (blink #3)
✅ Graceful shutdown handling

Manual Setup

# Install RISC-V toolchain
sudo apt-get update
sudo apt-get install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu
sudo apt-get install qemu-system-riscv64 qemu-user

# Clone and build
git clone <repository-url>
cd riscv-dev-standalone
make build-examples

Example Projects

This repository includes four comprehensive examples:

1. GPIO LED Control (examples/gpio-led/)

  • Purpose: Basic GPIO hardware interaction
  • Features: LED blinking, pin control, board detection
  • Skills: Hardware abstraction, GPIO programming, timing

2. Network Server (examples/network-server/)

  • Purpose: TCP socket programming on RISC-V
  • Features: Multi-client chat server, command processing
  • Skills: Network programming, concurrent connections, protocol design

3. Sensor Reading (examples/sensor-reading/)

  • Purpose: ADC interface and sensor data processing
  • Features: Simulated ADC readings, environmental monitoring
  • Skills: Data acquisition, signal processing, calibration

4. Buildroot Application (examples/buildroot-app/)

  • Purpose: Complete Buildroot package integration
  • Features: System monitoring web interface, service management
  • Skills: Embedded Linux packaging, system services, web development

📦 Complete Buildroot Package Included

The Buildroot App example includes a production-ready Buildroot package:

# Package structure
examples/buildroot-app/buildroot-package/
├── Config.in                    # Package configuration
├── riscv-system-monitor.mk      # Build instructions
└── rootfs-overlay/
    ├── etc/systemd/system/      # systemd service
    └── etc/init.d/              # init.d script

Ready-to-use Buildroot integration:

# 1. Copy package to Buildroot
cp examples/buildroot-app/buildroot-package/* /path/to/buildroot/package/

# 2. Enable in menuconfig
make menuconfig  # Enable riscv-system-monitor

# 3. Build and deploy
make
dd if=output/images/sdcard.img of=/dev/sdX bs=4M

Package Features:

  • Cross-compilation ready for RISC-V
  • System service integration (systemd/init.d)
  • Web interface at http://device-ip:8080
  • REST API endpoints for system monitoring
  • Production deployment scripts

Development Workflow

1. Development

# Build all examples
make

# Build specific example
make build-example-gpio-led

# Run with QEMU
make run-example-gpio-led

2. Testing

# Run tests
make test

# Cross-compile and test
GOOS=linux GOARCH=riscv64 go build ./examples/gpio-led/cmd/app
qemu-riscv64 ./gpio-led

3. Buildroot Integration

# Copy package to Buildroot
cp examples/buildroot-app/buildroot-package/* /path/to/buildroot/package/

# Enable in Buildroot menuconfig
make menuconfig  # Enable riscv-system-monitor

# Build the system
make

Architecture

Directory Structure

riscv-dev-standalone/
├── .devcontainer/         # Dev container configuration
├── examples/             # Example projects
│   ├── gpio-led/        # GPIO control example
│   ├── network-server/  # TCP server example
│   ├── sensor-reading/  # ADC interface example
│   └── buildroot-app/   # Buildroot integration
├── docs/                # Documentation
├── scripts/            # Utility scripts
├── bin/                # Build outputs (generated)
├── Makefile           # Build automation
├── go.work           # Go workspace (generated)
└── README.md         # This file

Technology Stack

  • Language: Go 1.21+ (cross-compiled to RISC-V)
  • Toolchain: GCC RISC-V 64-bit Linux
  • Emulation: QEMU system and user-mode
  • Build System: GNU Make
  • Embedded Linux: Buildroot (optional)
  • Development: VS Code + Dev Containers

Supported Hardware

Primary Targets

  • Milk-V Duo: RISC-V 64-bit SBC with CV1800B processor
  • HiFive Unmatched: SiFive RISC-V development board
  • QEMU virt machine: Generic RISC-V emulation

Architecture Support

  • ISA: RV64GC (64-bit with compression, atomics, floating-point)
  • ABI: lp64d (Linux 64-bit with double-precision float)
  • Endianness: Little-endian

Documentation

Key Features

Cross-Compilation

  • Seamless Go to RISC-V compilation
  • Static linking for embedded systems
  • Optimization for size and performance
  • Debug symbol generation

Buildroot Integration

  • Complete package templates
  • System service configuration
  • Init system support (systemd/init.d)
  • Root filesystem overlay

Development Tools

  • QEMU: Full system and user-mode emulation
  • GDB: Multi-arch debugging support
  • Dev Containers: Consistent development environment
  • VS Code: Integrated debugging and editing

🐳 Dev Container Features

The included dev container provides:

Pre-installed Toolchain

# RISC-V GCC Toolchain
riscv64-linux-gnu-gcc --version
# Go 1.21+ with cross-compilation
go version
# QEMU RISC-V support
qemu-system-riscv64 --version

Optimized for RISC-V Development

  • Automatic setup of RISC-V toolchain
  • Cross-compilation environment pre-configured
  • QEMU networking properly configured
  • VS Code extensions for RISC-V development
  • Buildroot SDK integration ready

One-Click Environment

# In VS Code:
# 1. Open repository
# 2. Cmd+Shift+P → "Dev Containers: Reopen in Container"
# 3. Ready to develop!

Container includes:

  • Ubuntu 22.04 base with RISC-V tools
  • Go 1.21+ with RISC-V cross-compilation
  • GCC RISC-V toolchain (binutils, gdb, etc.)
  • QEMU with RISC-V system/user emulation
  • Buildroot build environment
  • VS Code development extensions

Prerequisites

  • Docker: For dev container support
  • VS Code: With Dev Containers extension
  • Git: For repository management
  • Internet: For downloading toolchains and dependencies

Contributing

We welcome contributions! See our Contributing Guide for details on:

  • Development setup
  • Code standards
  • Testing procedures
  • Pull request process

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Related Projects


Built with ❤️ for the RISC-V community

About

Standalone developer container for fully integrated RISCV development

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published