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

Issues when setting bits in registers #75

Closed
thejpster opened this issue Aug 8, 2021 · 3 comments
Closed

Issues when setting bits in registers #75

thejpster opened this issue Aug 8, 2021 · 3 comments

Comments

@thejpster
Copy link
Member

In pwm.rs I saw:

pad.gpio[self.pin].write(|w| w.ie().set_bit());
pad.gpio[self.pin].write(|w| w.od().clear_bit());

My understanding of write is that it does:

let w = register.defaults();
let w = closure(w);
register.set_bits(w);

So the second line (clearing od) will undo the effects of the first. This should probably be:

pad.gpio[self.pin].modify(|_r, w| {
    w.ie.set_bit();
    w.od.clear_bit();
    w
});
@thejpster
Copy link
Member Author

The default value is 0x56 or 0b01010110 which is bits 1, 2, 4 and 6. This is equal to:

  • OD = 0 = Output Enabled
  • IE = 1 = Input Enabled
  • DRIVE = 0b01 = 4mA
  • PUE = 0 = Pull-Up Disabled
  • PDE = 1 = Pull-Down Enabled
  • SCHMITT = 1 = Schmitt Input Enabled
  • SLEWFAST = 0 = Slow GPIO Mode

I think this means the two lines I highlighted above are at least /harmless/, as they reset the pin to defaults, and then change one specific bit to a value that it already has in the default.

@9names
Copy link
Member

9names commented Aug 8, 2021

I mentioned this in matrix but didn't remember to make an issue for it.
There was another write/modify mixup caught in a review comment on the PWM rework PR, but it's good to have a reminder that it's not done yet.

@9names
Copy link
Member

9names commented Aug 14, 2021

Fixed in #80

@9names 9names closed this as completed Aug 14, 2021
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