MicroZig Documentation

repository·main·Indexed 24 days ago

https://github.com/zigembeddedgroup/microzig

An embedded development framework for the Zig programming language. MicroZig provides Hardware Abstraction Layers (HALs) and register definitions for various platforms including ESP32-C3, Nordic nRF5x, NXP MCX, NXP LPC1768, Raspberry Pi RP2040/RP2350, and WCH CH32V series. It includes a FreeRTOS module for task management, type-safe queues, semaphores, and mutexes, as well as support for CYW43 WiFi firmware.

Tokens
14.4K
Snippets
45
Records
89
Agent score
80%

What's inside MicroZig

  1. Overview of the Virtual Io interface

    main

    The virtual-io module provides a Zig I/O implementation that simulates a file system entirely in RAM. It is designed for testing or environments where disk access is undesirable or unavailable.

    Key characteristics:

    • In-Memory Storage: All I/O operations that would normally touch the disk are redirected to RAM, backed by a hash map.
    • Directory Structure: It maintains a simulated directory structure and file contents within the hash map.
    • Strict Isolation: Any I/O operation that cannot be satisfied within the RAM-backed structure will fail.
  2. What is regz?

    main

    regz is a Zig code generator designed for microcontrollers. It converts vendor-provided register description files—such as ARM's System View Description (SVD) or AVR's ATDF—into a single Zig file. This generated file allows you to interact with hardware registers using a type-safe, structured API.

    const regs = @import("nrf52.zig").registers;
    
    pub fn main() void {
        regs.P0.PIN_CNF[17].modify(.{
            .DIR = 1,
            .INPUT = 1,
            .PULL = 0,
            .DRIVE = 0,
            .SENSE = 0,
        });
        regs.P0.OUT.modify(.{ .PIN17 = 1 });
    }
  3. Overview of Nordic nrf5x support in MicroZig

    main

    The port/nordic/nrf5x directory provides Hardware Abstraction Layers (HALs) and register definitions specifically for Nordic nRF5x series devices. This port is designed to facilitate embedded development on these chips using Zig.

    Currently, Renode emulation support is available for the nrf52840 development kit.

  4. What is Printer?

    main
    Printer is a tool designed to process logging output from your code and format it into a readable and pretty format. Currently, its primary capability is annotating addresses from stack traces with their corresponding source code locations. Future updates are planned to include support for defmt logging.
  5. What is Sorcerer

    main

    Sorcerer is a suite of tools designed for visualizing and generating MicroZig register definitions. It supports SVD, ATDF, and Embassy formats and uses regz to generate type-safe Zig code. It consists of two main components:

    • Sorcerer (GUI): A graphical application for browsing, editing, and searching register definitions, viewing generated Zig code, and managing patch files.
    • sorcerer-cli: A lightweight command-line tool for generating register code without GUI dependencies.
  6. WCH CH32Vx03 Package Overview

    main
    This package provides SVD (System View Description) files for the WCH CH32Vx03 microcontroller series. These files are extracted from the MounRiver_Studio_Community_Linux_x64_V190.zip distribution and are used to provide debug information and peripheral register definitions for the CH32Vx03 hardware.
  7. Use NXP MCX Series HAL and register definitions

    main

    This port provides Hardware Abstraction Layer (HAL) and register definitions for the NXP MCX series microcontrollers.

    Supported Hardware: Currently, only the MCXA153 is supported.

    Data Source: Register definitions are derived from the official NXP MCUXpresso SVD files located at: https://github.com/nxp-mcuxpresso/mcux-soc-svd/.

  8. Understand Raspberry Pi RP2xxx Demo Categories

    main

    Demos for the raspberrypi-rp2xxx BSP are categorized by hardware compatibility:

    • Chip Agnostic: Code that runs on both RP2040 (Pico 1) and RP2350 (Pico 2) without modification (e.g., watchdog timer, USB device, basic blinky).
    • RP2040 Only: Examples utilizing features or HAL functionality currently specific to the RP2040 (e.g., ADC, I2C bus scan, SPI host, PIO square wave).
    • RP2350 Only: Reserved for future features unique to the RP2350 (e.g., HSTX).
    • CYW43: Specific to wireless boards (Pico W and Pico2 W) because the LED is driven via the CYW43 wireless chip rather than standard GPIO.

    Note: All demos compatible with the standard Pico are also compatible with the RP2040-Plus without modification.