MicroZig Embedded Development Framework

repository·main·Indexed 3 days ago

https://github.com/zigembeddedgroup/microzig

An embedded development framework for the Zig programming language designed to simplify microcontroller development. It provides Hardware Abstraction Layers (HALs) and register definitions for various targets, including Raspberry Pi RP2040/RP2350, ESP32-C3, Nordic nrf5x, NXP MCX, and NXP LPC. The framework includes support for CYW43 wireless drivers, lwip networking stacks, and examples for TCP/UDP communication, interrupt-driven networking, and direct register access.

Tokens
16.9K
Snippets
58
Records
99
Agent score
68%

What's inside MicroZig

  1. Overview of Sorcerer tools

    main

    Sorcerer is a suite of tools designed for visualizing and generating MicroZig register definitions. It supports multiple formats including SVD, ATDF, Embassy, and TargetDB via regz. It consists of two main components:

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

    Both tools use embedded Zig compile-time constants for schemas, meaning they do not require runtime file loading or JSON parsing.

  2. Overview of the Virtual Io interface

    main

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

    Key Behaviors:

    • RAM-backed storage: All I/O operations that would normally touch a physical disk are redirected to RAM, managed via a hash map.
    • Directory structure: It maintains a simulated directory structure and file contents in memory.
    • Strict isolation: Any I/O operation that is not explicitly handled by the virtual implementation will fail, ensuring no accidental disk access occurs.
  3. Overview of RP2xxx BSP Demos

    main

    The raspberrypi-rp2xxx Board Support Package (BSP) provides examples categorized by chip compatibility and hardware requirements:

    • Chip Agnostic: Demos that run on both RP2040 (Pico 1) and RP2350 (Pico 2) without code changes (e.g., blinky, watchdog timer, usb device).
    • RP2040 Only: Demos utilizing peripherals or HAL functionality not yet ported to the RP2350 (e.g., adc, i2c bus scan, pwm, spi host).
    • CYW43 (Wireless): Specific examples for the Pico W and Pico2 W boards. Because wireless boards drive the LED via the CYW43 chip rather than direct GPIO, these require different implementation logic.

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

  4. What is Printer and how does it work?

    main
    Printer is a tool designed to process logging output from your code and format it into a readable and 'pretty' format. Its current primary capability is annotating addresses from stack traces with their corresponding source code locations. It is designed to be extensible, with future support planned for defmt logging.
  5. Overview of 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 in Zig.

    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 });
    }
  6. WCH CH32H417 Package Overview

    main
    This package provides the SVD (System View Description) file for the WCH CH32H417 microcontroller. The SVD file was extracted from the MounRiver_Studio_Community_Linux_x64_V190.zip distribution. This file is typically used by debuggers and IDEs to provide peripheral register information during debugging sessions.
  7. 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 peripheral register information for debugging and hardware abstraction within the MicroZig ecosystem.
  8. Use NXP MCX Series HAL and register definitions

    main

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

    Supported Hardware:

    • Currently, only the MCXA153 is supported.

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