Skip to content

Generating STM32 Registers From Array-Registers Only Works With Stride Of 4 Bytes #416

@tim-hilt

Description

@tim-hilt

[Please suggest a better title. It feels very convoluted]

Problem Description

The file all.zig contains register-definitions for almost all STM32 microcontrollers. It's generated from data hosted by the embassy project.

The data-format that acts as the source for the code-generator models multiple instances of the same registers (e.g. multiple channels of a DMA peripheral) as arrays. These arrays are mostly arrays of registers of the same type (effectively []u32), but in some cases they are arrays of register-clusters (e.g. []{ u32, u32, u32, u32 }).

The current code-generator skips over all instances, where stride is != 4

if (stride != 4) {
std.log.warn("ignoring register array with unsupported stride: {} != 4 for register {s} in {s} in {s}", .{ stride, register_name, key["block/".len..], name });
break :blk null;
}

This leads to the omission of several registers, that the embassy-data models as arrays of clusters

Example:

https://github.com/embassy-rs/stm32-data-generated/blob/aee345990e1a14efd018877b52aff1d63e16bb7f/data/registers/bdma_v2.json#L46-L55

Without this, DMA is effectively not usable on my Microcontroller.

Suggested Fix

I see two ways of fixing this issue:

  1. Implementing code-generation all stride values (changes to data-model required)
  2. Rewriting the code-generator to use vendor-provided SVDs + regz (same approach as stm32-rs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions