Hi,
I'm trying to hack together changing the SPI mode on an STM32 microprocessor as the SPI hal does not make it convenient or obvious how to access the mode bits. I can setup a raw pointer for reading and have confirmed it reads correctly, however, it does not let me write to the register CFG2 (I have confirmed that the register is read/write). I also confirmed that I can read/write to GPIO registers. Does anyone know why it is not letting me write to this SPI1 CFG2 register? I'm more or less following the syntax from page 420 of "the Rust Programming Language" book.
Here is a code snippet.
// initialize SPI
#[allow(unused_mut)]
let mut spi1 = ctx.device.SPI1.spi(
(spi1_sclk, spi1_miso, spi1_mosi),
spi::MODE_0, // DAC and ADC uses MODE_1, DDS uses MODE_0
3.mhz(),
ccdr.peripheral.SPI1,
&ccdr.clocks,
);
// raw pointer Hack, as SPI HAL does not give convenient or obvious access to mode
unsafe {
//stm32h7xx
let spi1_cfg2_address = 0x4001300c; //spi1 peripheral address
let cfg2_val = spi1_cfg2_address as *mut u32;
let mut _cfg2_val_read = 0u32;
_cfg2_val_read = *cfg2_val; // read is correct
*cfg2_val = 0x0101abcd; // write does not work. why?
_cfg2_val_read = *cfg2_val;
}
Thanks,
Nathan
ps