Skip to content

Add ARCHITECTURE.md - #1005

Open
Grazfather wants to merge 4 commits into
mainfrom
architecture.md
Open

Grazfather wants to merge 4 commits into
mainfrom
architecture.md

Conversation

@Grazfather

Copy link
Copy Markdown
Collaborator

No description provided.

@Grazfather
Grazfather force-pushed the architecture.md branch 2 times, most recently from 4ab4aa2 to e83c5d6 Compare August 6, 2026 03:08
Comment thread ARCHITECTURE.md Outdated

MicroZig is a Zig framework for programming microcontrollers. It provides a unified build system, hardware abstraction
layers, and device drivers across 14+ microcontroller families (ARM Cortex-M, RISC-V, AVR, MSP430). The core idea: write
portable embedded code in Zig, with platform details handled by ports and a code-generating build system.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit too "write once run everywhere" and implies heavy abstraction. We don't push this on everyone. The core idea is more to add convenience to the low level aspects of targeting an MCU, but not getting in between the user and hardware.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also specify that MicroZig is not a variant of the Zig language for microcontrollers. Many people ask me that when I tell them what I do and they guess what it is.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nixed the whole last sentence.

Comment thread ARCHITECTURE.md Outdated
The foundational library that every firmware links against. Key files in `core/src/`:

- _microzig.zig_: Root API. Exposes `cpu`, `chip`, `hal`, `board`, `drivers` namespaces. Implements the default panic
handler, `export_startup()` for entry point generation, and `std_options()` for logging integration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std_options isn't for logging integration, it just changes some defaults so we don't hit compile errors

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarified

Comment thread ARCHITECTURE.md Outdated
- _microzig.zig_: Root API. Exposes `cpu`, `chip`, `hal`, `board`, `drivers` namespaces. Implements the default panic
handler, `export_startup()` for entry point generation, and `std_options()` for logging integration.
- _mmio.zig_: `Mmio` generic type that wraps a packed struct into a volatile MMIO register interface with `read()`,
`write()`, `modify()`, `toggle()` methods. Validates register sizes at comptime.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Validates register sizes at comptime" is unneeded.

Comment thread ARCHITECTURE.md Outdated
`write()`, `modify()`, `toggle()` methods. Validates register sizes at comptime.
- _interrupt.zig_: `enable()`, `disable()`, critical sections, `Mutex` (HAL-provided or fallback
`CriticalSectionMutex`), `Handler` union type.
- _allocator.zig_: Multi-tier free-list allocator.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation details of the allocator are less important than the fact that it manages a fixed chunk of memory.

Comment thread ARCHITECTURE.md
vector tables.
- _riscv32.zig_: RISC-V 32-bit support.
- _avr_common.zig_, _avr25.zig_, _avr5.zig_: AVR architecture.
- _msp430.zig_, _msp430x.zig_: TI MSP430.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the point of this document to list other files? The comments here barely do more than restate the file name

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I can nix them if you want. I find it useful so you know what file to look for for each arch.

Comment thread ARCHITECTURE.md

## Build System

The build system centers on `MicroBuild`, defined in the root `build.zig`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above section is completely redundant, remove it because this is far better.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which part?

Comment thread ARCHITECTURE.md Outdated
- **Ports are self-contained**.
- **Core is port-agnostic.** It receives chip/HAL/board configuration through comptime module imports injected by the
build system.
- **Register definitions are generated, not hand-written.** The source of truth is the vendor SVD/ATDF file plus

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails to specify that patches are where the user fixes mistakes in vendors register schemas.

Comment thread ARCHITECTURE.md
to branch on chip features, CPU type, or board identity. HALs use it to select peripheral implementations, setup clocks,
etc.

**Startup sequence**: Each CPU architecture in _core/src/cpus/_ provides a `_start` entry point. The typical sequence

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good but I think it's already been mentioned.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not.

Comment thread ARCHITECTURE.md Outdated
**Startup sequence**: Each CPU architecture in _core/src/cpus/_ provides a `_start` entry point. The typical sequence
is: set stack pointer → zero BSS → copy `.data` from flash to RAM → call `microzig_main`.

**Naming conventions**: The codebase uses _snake_case_ (C-style), not the typical Zig camelCase. Run `zig fmt` for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misses the type naming format we use.

Comment thread ARCHITECTURE.md Outdated
**Naming conventions**: The codebase uses _snake_case_ (C-style), not the typical Zig camelCase. Run `zig fmt` for
formatting.

**MMIO access**: All register access should go through `Mmio`. The packed struct defines the register layout, the `Mmio`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this is redundant, and shouldn't be at the end of the file as an afterthought.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a blurb to the first mention above and removed this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants