NEORV32 Documentation

repository·main·Indexed 24 days ago

https://github.com/stnolting/neorv32

A customizable, platform-independent RISC-V SoC written in VHDL, designed as a standalone microcontroller or auxiliary controller. It features a 32-bit pipelined/multi-cycle modified-Harvard architecture with extensive ISA extension support, an optional on-chip debugger (OCD) compatible with RISC-V Debug Specification Version 1.0, and a comprehensive ecosystem including support for Zephyr, FreeRTOS, nommu-Linux, MicroPython, Ada, and Rust.

Tokens
76.9K
Snippets
121
Records
448
Agent score
80%

What's inside NEORV32

  1. Overview of the NEORV32 RISC-V Processor

    main

    The NEORV32 is an open-source, highly configurable RISC-V compatible processor system. It is designed to function either as an auxiliary processor within a larger SoC or as a standalone microcontroller.

    Key Components:

    • CPU Core: A 32-bit RISC-V CPU with support for base ISA, privileged ISA, and various optional extensions (e.g., M, F, Zicsr, Zicntr).
    • SoC (Processor System): A microcontroller-like system including optional peripherals such as UART, SPI, TWI, PWM, GPIO, timers, DMA, and embedded memories.
    • Software Framework: A C-based framework including a bootloader, HAL (Hardware Abstraction Layer), runtime environment, and example programs. It supports GCC, FreeRTOS, Zephyr, and MicroPython.
    • On-Chip Debugger: An OpenOCD/GDB compatible debugger accessible via JTAG.
  2. Use the NEORV32 Software Framework

    main

    The NEORV32 software ecosystem is a complete C-language RISC-V GCC-based framework. It includes a compiler toolchain, core hardware abstraction layer (HAL) libraries, a runtime environment, and a bootloader.

    Key components:

    • Core Libraries (HAL): Located in sw/lib, these allow easy integration of processor features. They are automatically included by adding #include <neorv32.h> to your code.
    • Example Programs: Annotated examples illustrating peripheral and IO usage are available in sw/example.
    • API Documentation: Doxygen-generated documentation is available online at https://stnolting.github.io/neorv32/sw/files.html.
  3. Overview of the General Purpose Timer (GPTMR)

    main

    The General Purpose Timer (GPTMR) module provides up to 16 individual 32-bit timer slices. Each slice consists of a counter register (SLICE[i].CNT) and a threshold register (SLICE[i].THR).

    Key Capabilities:

    • Configurable Slices: The number of slices is determined by the hardware generic IO_GPTMR_NUM (0..16).
    • Operation Modes: Each slice can operate in single-shot mode (stops at threshold) or continuous/interval mode (resets to zero after matching threshold).
    • Global Prescaler: A single global clock prescaler (CSR1.PRSC) affects the increment frequency for all slices.
    • Interrupts: A CPU interrupt is generated on the fast IRQ channel 12 when a slice's counter matches its threshold, provided the slice is enabled.

    Hardware and Software Files:

    • Hardware: neorv32_gptmr.vhd
    • Software Driver: neorv32_gptmr.c and neorv32_gptmr.h
  4. Overview of the Stream Link Interface (SLINK)

    main

    The Stream Link Interface (SLINK) provides independent RX and TX channels for high-bandwidth, low-latency streaming data. It is compatible with the AXI4-Stream standard and is ideal for coupling custom stream processors or streaming peripherals to the NEORV32 SoC.

    Key Features:

    • Independent RX and TX channels.
    • Configurable internal data FIFOs (via IO_SLINK_RX_FIFO and IO_SLINK_TX_FIFO generics).
    • Supports "last" (end-of-stream) and "source/destination" routing signals.
    • Interrupt-based signaling based on FIFO status.
    • AXI4-Stream compatibility (using dat, val, lst, rdy signals, with src/dst replacing AXI-specific routing names).
  5. Overview of NEORV32 Control and Status Registers (CSRs)

    main

    NEORV32 uses Control and Status Registers (CSRs) to manage CPU state, configuration, and status.

    Key Access Rules:

    • Privilege Modes: Access is restricted by mode: M (Machine), U (User), or D (Debug).
    • Read/Write Capabilities: RW (Read-Write), RO (Read-Only).
    • Unimplemented/Disabled CSRs: Any CSR or bit not listed, or disabled due to missing ISA extensions, is hardwired to zero. Accessing them raises an illegal instruction exception.
    • WARL Behavior: All writable CSRs follow 'Write All, Read Legal' behavior. You should always read back a CSR after writing to verify that the targeted bits were actually modified.
  6. Overview of the NEORV32 Bootloader

    main

    The NEORV32 bootloader is an optional built-in firmware that allows uploading new application firmware without re-synthesizing the FPGA bitstream. It is automatically executed after reset if enabled via the BOOT_MODE_SELECT generic.

    Key Features:

    • Interactive user console via UART.
    • Uploading executables via UART.
    • Loading/storing executables from SPI flash, TWI flash, or SD cards.
    • Automatic boot sequence from flash or SD card.

    Minimal Hardware Requirements:

    • ISA: rv32e_zicsr_zifencei configuration.
    • RAM (DMEM): At least 256 bytes.
    • Recommended Controllers: UART0, CLINT, and GPIO.
  7. What is the Custom Functions Unit (CFU)?

    main

    The Custom Functions Unit (CFU) is a NEORV32-specific ISA extension (Xcfu) that provides a generic hardware module for implementing custom RISC-V instructions.

    When to use CFU vs. other customization options:

    • Use CFU for: Custom instructions that are tightly coupled with the CPU (e.g., specialized arithmetic or bit manipulation).
    • Do NOT use CFU for: Complex, CPU-independent accelerators (like full AES encryption blocks). These should be implemented as stream- or memory-mapped co-processors (e.g., CFS) to allow them to operate independently of the CPU.
  8. Configure GPIO pin interrupts

    main

    Each input pin (gpio_i) can trigger an interrupt on the CPU via fast IRQ channel 8. Interrupts are configured per-pin using three registers:

    1. IRQ_ENABLE(i): Enables or disables the interrupt for pin i.
    2. IRQ_TYPE(i): Sets the trigger type (0 for level-triggered, 1 for edge-triggered).
    3. IRQ_POLARITY(i): Sets the polarity (0 for low-level/falling-edge, 1 for high-level/rising-edge).

    Trigger Configuration Table:

    IRQ_ENABLE(i)IRQ_TYPE(i)IRQ_POLARITY(i)Resulting trigger
    100low-level (GPIO_TRIG_LEVEL_LOW)
    101high-level (GPIO_TRIG_LEVEL_HIGH)
    110falling-edge (GPIO_TRIG_EDGE_FALLING)
    111rising-edge (GPIO_TRIG_EDGE_RISING)
    0--interrupt disabled

    When an interrupt fires, it is buffered in the IRQ_PENDING register. To clear a pending interrupt, write 0 to the corresponding bit in IRQ_PENDING.

  9. Use the Custom Functions Subsystem (CFS) for accelerators

    main

    The Custom Functions Subsystem (CFS) is a memory-mapped, processor-internal module template designed to simplify the implementation of hardware accelerators. It allows developers to focus on design logic rather than communication overhead.

    • Mechanism: The CPU communicates with the CFS via load/store operations (memory-mapped).
    • Data Access: The CFS does not have direct access to memory; all data and control instructions must be sent by the CPU.
    • Use Cases: Medium-scale accelerators like DSP modules (e.g., CORDIC), cryptography accelerators, or custom interfaces (e.g., IIS).
  10. Key Features of NEORV32

    main

    The NEORV32 processor offers several key advantages for digital designers and RISC-V developers:

    • Self-contained: No external dependencies; includes CPU, SoC, software framework, and test infrastructure.
    • Platform-independent: Written in behavioral VHDL without primitives or macros, allowing easy mapping to FPGA or ASIC memory primitives.
    • Highly Customizable: Extensive configuration options for both the CPU and the SoC to meet specific application requirements.
    • Optimized for Performance: Designed for high clock frequencies to facilitate timing closure during integration.
    • Extensive Ecosystem Support:
      • Operating Systems: Support for Zephyr, FreeRTOS, and nommu-Linux.
      • Languages/Frameworks: MicroPython port, Ada support, and Rust integration via the Embassy framework.
      • Build Tools: Integration with LiteX SoC builder and available as a Vivado IP Block.
      • Development Environments: Pre-configured Eclipse projects are available.
  11. Configure the NEORV32 CPU Core and ISA extensions

    main

    The NEORV32 CPU is a 32-bit little-endian pipelined/multi-cycle modified-Harvard architecture RISC-V core. It is highly configurable via generics, allowing for single-core or SMP dual-core setups. You can customize the instruction set by enabling various RISC-V ISA extensions.

    Supported extensions include:

    • Standard: I, E, M, A, C, B, U, X
    • Specialized/Custom: Sdext, Sdtrig, Smcntrpmf, Smpmp, Zaamo, Zalrsc, Zba, Zbb, Zbc, Zbkb, Zbkc, Zbkx, Zbs, Zcb, Zcmop, Zfinx, Zibi, Zicntr, Zicond, Zicsr, Zifencei, Zihpm, Zimop, Zmmul, Zkn, Zknd, Zkne, Zknh, Zkt, Zks, Zksed, Zksh, Xcfu (Custom Functions Unit).

    The core supports machine and optional user privilege modes and implements all RISC-V machine-level exceptions/interrupts, plus a NEORV32-specific extension of 16 fast interrupt request channels.