stm32-rs / stm32l4xx-hal

A Hardware abstraction layer for the stm32l432xx series chips written in rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`

MollyJHoward opened this issue · comments

I'm attempting to add support for GPIO Port H for the STM32l431. I have forked the main branch and when I try to build my project with it I receive these errors (with or without any changes). If I simply add stm32l4xx-hal to my project, it builds just fine. I tried stashing my changes and checking out at v0.7.1 but the same thing happened. Anyone have any advice?

Error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   --> $(PATH)/stm32l4xx-hal/src/qspi.rs:679:21
    |
679 |                     ptr::write_volatile(&self.qspi.dr as *const _ as *mut u8, *byte);
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
    = note: `#[deny(invalid_reference_casting)]` on by default

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   --> $(PATH)/stm32l4xx-hal/src/serial.rs:523:29
    |
523 |                               ptr::write_volatile(&(*pac::$USARTX::ptr()).tdr as *const _ as *mut _, byte)
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
849 | / hal! {
850 | |     USART1: (usart1, pclk2, tx: (TxDma1, dma1::C4, DmaInput::Usart1Tx), rx: (RxDma1, dma1::C5, DmaInput::Usart1Rx)),
851 | |     USART2: (usart2, pclk1, tx: (TxDma2, dma1::C7, DmaInput::Usart2Tx), rx: (RxDma2, dma1::C6, DmaInput::Usart2Rx)),
852 | | }
    | |_- in this macro invocation
    |
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
    = note: this error originates in the macro `hal` (in Nightly builds, run with -Z macro-backtrace for more info)

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   --> $(PATH)/stm32l4xx-hal/src/serial.rs:523:29
    |
523 |                               ptr::write_volatile(&(*pac::$USARTX::ptr()).tdr as *const _ as *mut _, byte)
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
855 | / hal! {
856 | |     USART3: (usart3, pclk1, tx: (TxDma3, dma1::C2, DmaInput::Usart3Tx), rx: (RxDma3, dma1::C3, DmaInput::Usart3Rx)),
857 | | }
    | |_- in this macro invocation
    |
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
    = note: this error originates in the macro `hal` (in Nightly builds, run with -Z macro-backtrace for more info)

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   --> $(PATH)/stm32l4xx-hal/src/spi.rs:256:34
    |
256 |                           unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut u8, byte) }
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
293 | / hal! {
294 | |     SPI1: (spi1, spi1_slave, pclk2),
295 | | }
    | |_- in this macro invocation
    |
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
    = note: this error originates in the macro `hal` (in Nightly builds, run with -Z macro-backtrace for more info)

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   --> $(PATH)/stm32l4xx-hal/src/spi.rs:256:34
    |
256 |                           unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut u8, byte) }
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
325 | / hal! {
326 | |     SPI3: (spi3, spi3_slave, pclk1),
327 | | }
    | |_- in this macro invocation
    |
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
    = note: this error originates in the macro `hal` (in Nightly builds, run with -Z macro-backtrace for more info)

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   --> $(PATH)/stm32l4xx-hal/src/spi.rs:256:34
    |
256 |                           unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut u8, byte) }
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
356 | / hal! {
357 | |     SPI2: (spi2, spi2_slave, pclk1),
358 | | }
    | |_- in this macro invocation
    |
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
    = note: this error originates in the macro `hal` (in Nightly builds, run with -Z macro-backtrace for more info)