Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

regz: AVR peripherals generated at address 0 when the register-group name matches the module (ATDF)

オープン
#1,072 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
zig
領域
embedded-iot

調査の方向性

Start in tools/regz/src/atdf.zig, especially load_module_type and the inlined register-group path; compare it with load_register_group, which infers the lowest register offset. Check generated AVR peripherals such as ATmega328P.zig and verify the result for the listed ATmega and ATtiny devices, while preserving genuinely zero-based peripherals such as ATtiny1616 VPORTA. Done means generated peripheral pointers use valid bases and the reported Zig address-zero failure is avoided.

索引モデルが issue の本文から書いたものです。

説明

On AVR, many generated peripherals end up at address 0 with absolute register offsets. For example, in the generated ATmega328P.zig:

pub const SPI: *volatile types.peripherals.SPI = @ptrFromInt(0x0); // SPCR is at offset 0x4C

Using it with Zig 0.17.0 fails with pointer type '*volatile types.peripherals.SPI.SPI' does not allow address zero, so these peripherals can't be used through microzig.chip.peripherals.

Data-space peripherals at address 0 in the files generated locally from the current atpacks:

  • ATmega328P: TWI, ADC, AC, EXINT, SPI, WDT, EEPROM, CPU
  • ATtiny85 and ATtiny84: AC, ADC, USI, EXINT, EEPROM, WDT, BOOT_LOAD, CPU
  • ATtiny1634: TWI, ADC, AC, EEPROM, EXINT, CPU, USI, WDT

Cause (tools/regz/src/atdf.zig): in the ATDF, these instances have offset="0x00" and their registers use absolute data-space offsets. When a module's only register-group has the same name as the module (SPI, TWI, ...), load_module_type inlines it and skips the offset inference, so the instance keeps the zero base. When the names differ (USART0, PORTB, ...), load_register_group infers the lowest register offset and the instance uses it, which is why those come out right (0xC0, 0x23).

Possible fixes: run the same inference on the inlined path (SPI would get base 0x4C and SPCR offset 0), or emit an allowzero pointer for zero bases. The second would also cover the ATtiny1616's VPORTA, which really is at 0x0000.

Workaround I'm using for the ATmega328P SPI (tested on hardware): one pointer per register, keeping the generated types:

const SPI_Regs = microzig.chip.types.peripherals.SPI;
const SPCR: *volatile @FieldType(SPI_Regs, "SPCR") = @ptrFromInt(@offsetOf(SPI_Regs, "SPCR"));

I'm happy to try a fix in regz if that helps.

主要言語
Zig
スター
2.3k
フォーク
198
平均マージ
1日 8時間
マージ済み PR(30日)
37

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ZigEmbeddedGroup/microzig のほかの issue

ZigEmbeddedGroup/microzig の issue をすべて見る

似ている issue

Embedded & IoT の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。