This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

it can't boot to dfu mode.

I have a Nordic 52840 hardware, which comes with the bootloader. Learned that the register GPREGRET address is 0x4000051C. The app is written in rust language, and the address is assigned 0xB1 directly in the app. But  it can't  enter the dfu mode.
code show as below:

let gpregret = 0x4000051Cusize;
         let pa = gpregret as * mut i32;
         unsafe {
             * pa = 0xB1;
         };

Am I writing it wrong?

thank you!

Parents
  • I'm not familiar with what you're trying to do, but from a Rust perspective, I can see one potential problem: As far as the compiler is concerned, you're writing to a memory address, then never access that address again. It might just decide that your write can be optimized out without changing the behavior of the program.

    What you need is a volatile write, which tells the compiler not to interfere: https://doc.rust-lang.org/core/ptr/fn.write_volatile.html

    Also, is there any reason you can't use nrf52840-pac (https://crates.io/crates/nrf52840-pac)? It's automatically generated from Nordic's SVD file, should contain all the correct register definitions, and will take care of the volatile writes under the hood.

Reply
  • I'm not familiar with what you're trying to do, but from a Rust perspective, I can see one potential problem: As far as the compiler is concerned, you're writing to a memory address, then never access that address again. It might just decide that your write can be optimized out without changing the behavior of the program.

    What you need is a volatile write, which tells the compiler not to interfere: https://doc.rust-lang.org/core/ptr/fn.write_volatile.html

    Also, is there any reason you can't use nrf52840-pac (https://crates.io/crates/nrf52840-pac)? It's automatically generated from Nordic's SVD file, should contain all the correct register definitions, and will take care of the volatile writes under the hood.

Children
No Data