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

do validation when parsing serde yaml/json #247

Open
ReinoutHeeck opened this issue Jan 15, 2023 · 3 comments
Open

do validation when parsing serde yaml/json #247

ReinoutHeeck opened this issue Jan 15, 2023 · 3 comments

Comments

@ReinoutHeeck
Copy link

ReinoutHeeck commented Jan 15, 2023

I was handcrafting some svd (yaml) and early on ran into a generator issue.

To reproduce run the following in an empty directory:

cargo init simple_bit_field_failure \
&& cd simple_bit_field_failure \
&& cargo add cortex_m vcell \
&& cd src \
&& echo """
name: MyDevice
version: 0
description: My Device
addressUnitBits: 32
width: 32
peripherals:
  - name: MyPeripheral
    baseAddress: 0xb8000300
    registers:
      - register:
          name: MyRegister
          description: My register.
          addressOffset: 0
          size: 1
          fields:
            - name: MyBitField
              description: My bit field.
              bitRange: \"[0:0]\"
""" |  RUST_LOG=debug svd2rust --strict --source_type yaml \
&&cargo fmt -- --config normalize_doc_attributes=true \
&&cargo build

result:

...
error[E0308]: mismatched types
   --> src/lib.rs:779:37
    |
779 |                 MY_BIT_FIELD_R::new(self.bits)
    |                 ------------------- ^^^^^^^^^ expected `bool`, found `u8`
    |                 |
    |                 arguments to this function are incorrect
    |
...

The first doc line reports version:

//!Peripheral access API for MYDEVICE microcontrollers (generated using svd2rust v0.28.0 ( ))
@ReinoutHeeck
Copy link
Author

ReinoutHeeck commented Jan 15, 2023

After delving into the generator sources it turns out that register 'size' above is measured in bits instead of bytes as I was using it.

This uncovers a broken corner case in the logic for computing use_cast in register.rs.

Fixing support for single-bit registers is not very urgent I guess ;-)

On a more serious note: should the generator have complained that bit fields beyond the register width were specified in my project?

@burrbull
Copy link
Member

no need to dive in code. there is specification https://www.keil.com/pack/doc/CMSIS/SVD/html/elem_special.html#registerPropertiesGroup_gr

@ReinoutHeeck
Copy link
Author

I knew that site but seeing uncompilable code generated I also 'knew' it was a bug and had to dive in. It's my knee-jerk reaction :-/

@burrbull burrbull transferred this issue from rust-embedded/svd2rust Nov 24, 2023
@burrbull burrbull changed the title Simple bitfield definition generates type error do check when parsing serde jaml/json Nov 24, 2023
@burrbull burrbull changed the title do check when parsing serde jaml/json do checks when parsing serde yaml/json Nov 24, 2023
@burrbull burrbull changed the title do checks when parsing serde yaml/json do validation when parsing serde yaml/json Nov 24, 2023
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

No branches or pull requests

2 participants