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

Register read/write not writing on stm32l433 #340

Open
sousandrei opened this issue Apr 16, 2023 · 2 comments
Open

Register read/write not writing on stm32l433 #340

sousandrei opened this issue Apr 16, 2023 · 2 comments

Comments

@sousandrei
Copy link
Contributor

Something seems to be off.

When writing on registers using the following code, the results tells the the read/write from won't work unless I go hardcore on ptr::read or ptr::write.

Maybe I'm using the wrong register, but I'm using stm32l4::stm32l4x3::SPI2::PTR as a reference 🤔

When writing with prt::write, it actually works on ptr::read but not on the dp read, always zero

Am I missing something?

Context: was trying to use some SPI crate and the result was very random all the time, could not pinpoint the error so started digging down

let dp = stm32::Peripherals::take().unwrap();
let mut spi2 = 0x4000_3800;

writeln!(sys, "dp read {:?}", dp.SPI2.cr1.read().bits()).unwrap();
writeln!(sys, "core read {:?}", unsafe { core::ptr::read(&spi2) }).unwrap();

dp.SPI2.cr1.modify(|_, w| w.spe().enabled());

writeln!(sys, "dp read {:?}", dp.SPI2.cr1.read().bits()).unwrap();
writeln!(sys, "core read {:?}", unsafe { core::ptr::read(&spi2) }).unwrap();

unsafe { core::ptr::write(&mut spi2, 1) }
writeln!(sys, "core write 1").unwrap();

writeln!(sys, "dp read {:?}", dp.SPI2.cr1.read().bits()).unwrap();
writeln!(sys, "core read {:?}", unsafe { core::ptr::read(&spi2) }).unwrap();

Resulting in

23:34:06.743 dp read 0
23:34:06.743 core read 1073756160

23:34:06.743 dp read 0
23:34:06.743 core read 1073756160

23:34:06.743 core write 1

23:34:06.743 dp read 0
23:34:06.743 core read 1
@snakehand
Copy link

Seems there is something wrong with your code as the decimal value 1073756160 = 0x40003800 , so I suspect you are just reading the variable you have declared, and not the memory adress it points to.

@snakehand
Copy link

Also you should make sure that the SPI2 device is actually enabled by setting SPI2EN bit in APB1ENR1 register, otherwise the memory mapped registers typically will just read 0.

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