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

Make Register::set use volatile_write #31

Closed
MalteT opened this issue Aug 3, 2020 · 2 comments
Closed

Make Register::set use volatile_write #31

MalteT opened this issue Aug 3, 2020 · 2 comments

Comments

@MalteT
Copy link

MalteT commented Aug 3, 2020

I was writing a small programs that uses the internal EEPROM of the ATmega328P, when I noticed that no writing was occuring.
I was using

EECR::set(EECR::EEMPE);
EECR::set(EECR::EEPE);

to start writing to the EEPROM, but the memory was unchanged.

When I replaced the above code with the following:

EECR::write(EECR::EEMPE);
EECR::write(EECR::EEPE);

it worked like a charme.

I might be mistaken, but after digging through the Register code, I noticed that Register::set is not using volatile_write

ruduino/src/register.rs

Lines 53 to 57 in 302095d

fn set_mask_raw(mask: Self::T) {
unsafe {
*Self::ADDRESS |= mask;
}
}

while Register::unset, Register::write, etc are doing so. Is there a particular reason for this, that I may not understand yet?

ruduino/src/register.rs

Lines 70 to 74 in 302095d

fn unset_mask_raw(mask: Self::T) {
unsafe {
core::ptr::write_volatile(Self::ADDRESS, core::ptr::read_volatile(Self::ADDRESS) & !mask)
}
}

Thanks!

@laris
Copy link

laris commented Sep 18, 2020

I also find the bug and you need to change the code.

@dylanmckay
Copy link
Member

Indeed, every other method in this file was changed to use volatile memory operations, but this one method was fixed. I've given the file two passes over checking to see if there are any other nonvolatile memops on registers but this seems to be the only one. Now fixed.

Thanks for raising this!

I've released v0.2.7 which contains the fix for this issue.

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

3 participants