Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regz and stm32: Support array fields in registers #343

Merged
merged 8 commits into from
Dec 30, 2024

Conversation

marnix
Copy link
Contributor

@marnix marnix commented Dec 30, 2024

For stm32, generate 'array fields' in src/chips/all.zig.

So instead of just having the first element of an array field, e.g.,

/// control register 2
CR2: mmio.Mmio(packed struct(u32) {
    reserved8: u8,
    /// Output Idle state x (x=1-6)
    OIS: u1,
    /// Output Idle state x N x (x=1-4)
    OISN: u1,
    reserved20: u10,
    /// Master mode selection 2
    MMS2: MMS2,
    padding: u8,
...

we now generate, e.g.,

/// control register 2
CR2: mmio.Mmio(packed struct(u32) {
    reserved8: u8,
    /// (1/6 of OIS) Output Idle state x (x=1-6)
    @"OIS[0]": u1,
    /// (1/4 of OISN) Output Idle state x N x (x=1-4)
    @"OISN[0]": u1,
    /// (2/6 of OIS) Output Idle state x (x=1-6)
    @"OIS[1]": u1,
    /// (2/4 of OISN) Output Idle state x N x (x=1-4)
    @"OISN[1]": u1,
    /// (3/6 of OIS) Output Idle state x (x=1-6)
    @"OIS[2]": u1,
    /// (3/4 of OISN) Output Idle state x N x (x=1-4)
    @"OISN[2]": u1,
    /// (4/6 of OIS) Output Idle state x (x=1-6)
    @"OIS[3]": u1,
    /// (4/4 of OISN) Output Idle state x N x (x=1-4)
    @"OISN[3]": u1,
    /// (5/6 of OIS) Output Idle state x (x=1-6)
    @"OIS[4]": u1,
    reserved18: u1,
    /// (6/6 of OIS) Output Idle state x (x=1-6)
    @"OIS[5]": u1,
    reserved20: u1,
    /// Master mode selection 2
    MMS2: MMS2,
    padding: u8,
...

We auto-correct (with a warning) an incorrect field array stride, where "stride" is less than the "bit_size", so that the array elements incorrectly would be self-overlapping. We assume that the stride is equal to the array element size.

Also some related regz changes:

  • Make the array field count a u16 (was u64).
  • Generate a warning comment for skipped overlapping fields.
  • Support fields that the JSON lists out of offset_bits order.
  • Skip fields that incorrectly go outside of their register.

@mattnite mattnite merged commit cd3180c into ZigEmbeddedGroup:main Dec 30, 2024
27 checks passed
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.

2 participants