Setting DMA CMAR register

I'm new to rust and working through setting up a DMA channel on a stm32l432kc board using the stm32-hal2 and RTIC. I am trying to work fairly low level because the HALs are very confusing and hard to follow the source with all of their generics and empty types...

I'm sure this is a very beginner question but how do I get the address of a variable so I can put it into the CMAR register?

For the peripheral register I have:

dp.DMA1.cpar2.write(|w| unsafe{*dp.SPI1.dr.as_ptr())});

Not entirely sure if that is correct either...

But for the Memory address, it seems even more verbose so I'm not sure about it.

 #[init (local = [a: u16 = 0])]
    fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
        let raw_pointer = cx.local.a as *const u16 ;
        let addr = raw_pointer as usize;

        defmt::info!("addr1: {}", addr);
        dp.DMA1.cmar2.write(|w| unsafe{ as u32)});

Is this the correct way of obtaining an address? I think "a" should be in the shared struct, in there it's address should be fixed, right? If so, how do I access it from init so I can get it's address?

Sorry for the super basic question, I just want to make sure I am configuring the addresses of the DMA correctly so I don't spend hours trying to figure out why it isn't working :sweat_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.