rust-embedded / rust-embedded/svd

do validation when parsing serde yaml/json

Open
#247 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
84
Forks
64
PR merge metrics
No merged PRs in 30d

Description

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 ( ))

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided svd2rust --strict --source_type yaml reproduction in an empty directory and observe whether parsing accepts the invalid bit-field input. Trace the serde YAML/JSON parsing entry point; done should mean malformed input is rejected during parsing with a useful validation error instead of producing Rust that fails to compile.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, rust, yaml
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.