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

Generate API for "write 1 to toggle" registers #176

Closed
Serisium opened this issue Feb 18, 2018 · 6 comments
Closed

Generate API for "write 1 to toggle" registers #176

Serisium opened this issue Feb 18, 2018 · 6 comments
Assignees
Milestone

Comments

@Serisium
Copy link

Hey all,

Over in rust-embedded/wg#40, user @kinnison brought up that some of the STM32's USB control registers have a "write 0 to leave alone; write 1 to toggle" interface, and that svd2rust isn't generating the proper API for these registers. Since he hasn't filed an issue here yet, this is my attempt to document the feature.

In particular, the STM32F0x2 has a register for each USB endpoint with six of these toggleable bits. These registers are described in RM0091 under the name USB_EPnR:

When the application software writes ‘0, the value of DTOG_TX remains unchanged, while writing ‘1 makes the bit value toggle. This bit is read/write but it can only be toggled by writing 1.

Here is a link to the current output generated by svd2rust v0.12.0 from STM32F0x2.svd

STM32f0x2.svd

            <field>
              <name>DTOG_TX</name>
              <description>Data Toggle, for transmission
              transfers</description>
              <bitOffset>6</bitOffset>
              <bitWidth>1</bitWidth>
            </field>

svd2rust API

            #[doc = "Bit 6 - Data Toggle, for transmission transfers"]
            #[inline]
            pub fn dtog_tx(&self) -> DTOG_TXR {
                let bits = {
                    const MASK: bool = true;
                    const OFFSET: u8 = 6;
                    ((self.bits >> OFFSET) & MASK as u32) != 0
                };
                DTOG_TXR { bits }
            }
            #[doc = "Bit 6 - Data Toggle, for transmission transfers"]
            #[inline]
            pub fn dtog_tx(&mut self) -> _DTOG_TXW {
                _DTOG_TXW { w: self }
            }

Let me know if there's any other information I can dig up! I'm still learning embedded on Rust, and am really excited to see where things are headed.

@Emilgardis Emilgardis self-assigned this Mar 2, 2018
@Emilgardis Emilgardis added this to the cmsis-svd milestone Mar 2, 2018
@Emilgardis
Copy link
Member

Emilgardis commented Mar 2, 2018

To implement this we need to enable parsing of <modifiedWriteValues> as defined in the spec and make svd2rust understand this enum.

To make it work you'd have to patch this element into the SVD aswell

            <field>
              <name>DTOG_TX</name>
              <description>Data Toggle, for transmission
              transfers</description>
              <modifiedWriteValues>oneToToggle</modifiedWriteValues>
              <bitOffset>6</bitOffset>
              <bitWidth>1</bitWidth>
            </field>

@ah-
Copy link

ah- commented Mar 14, 2018

Out of interest, did you get anywhere with this? Are you working on a USB driver?

@Serisium
Copy link
Author

Serisium commented Mar 14, 2018

@ah- I haven't gotten anywhere with this yet, since working on svd2rust would be above my current experience with Rust. I have plans to work with the STM32f0 USB peripherals in a month or two, which is why I brought this up.

If this begins to block my work on USB devices and I feel more comfortable with the language, I'd be glad to contribute or assist @Emilgardis following the plan that they have laid out.

@bergus
Copy link

bergus commented May 2, 2018

The STM32L4 I'm working with also uses

read/clear (rc_w1):
Software can read as well as clear this bit by writing 1. Writing ‘0’ has no effect on the bit value.
read/clear (rc_w0):
Software can read as well as clear this bit by writing 0. Writing ‘1’ has no effect on the bit value.

I guess supporting modifiedWriteValues as suggested would include this, unfortunately the official SVDs don't use this description :-/

@ah-
Copy link

ah- commented May 2, 2018

@bergus I haven't looked in detail, but I've seen mechanisms to override the svd and fix issues like that in https://github.com/adamgreig/stm32-rs.

@burrbull
Copy link
Member

burrbull commented Nov 7, 2022

reopen if not fixed

@burrbull burrbull closed this as completed Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants