Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#1,072 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
zig
Área
embedded-iot

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Zig
Estrellas
2.3k
Forks
198
Merge medio
1 d 8 h
PR fusionados (30 d)
37

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ZigEmbeddedGroup/microzig

Todos los issues de ZigEmbeddedGroup/microzig

Issues similares

Más issues de Embedded & IoT

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.