diff options
| author | Warren Campbell <[email protected]> | 2024-04-15 14:54:01 -0400 |
|---|---|---|
| committer | Warren Campbell <[email protected]> | 2024-04-15 14:59:31 -0400 |
| commit | 2fa0bb7d6eaf73dcb589f831b97559f5b81bb9c1 (patch) | |
| tree | 49bfb7267b3f7aac4bf1d1c00e08fa1c4c11be35 /embassy-stm32/src/flash | |
| parent | 27ba2ad5b0aaf0638aac3b1f141e98f6ff2b84ab (diff) | |
Use non-secure registers for u5 flash
Diffstat (limited to 'embassy-stm32/src/flash')
| -rw-r--r-- | embassy-stm32/src/flash/u5.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/embassy-stm32/src/flash/u5.rs b/embassy-stm32/src/flash/u5.rs index 580c490da..4a2168b14 100644 --- a/embassy-stm32/src/flash/u5.rs +++ b/embassy-stm32/src/flash/u5.rs | |||
| @@ -14,26 +14,26 @@ pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] { | |||
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | pub(crate) unsafe fn lock() { | 16 | pub(crate) unsafe fn lock() { |
| 17 | pac::FLASH.seccr().modify(|w| w.set_lock(true)); | 17 | pac::FLASH.nscr().modify(|w| w.set_lock(true)); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | pub(crate) unsafe fn unlock() { | 20 | pub(crate) unsafe fn unlock() { |
| 21 | if pac::FLASH.seccr().read().lock() { | 21 | if pac::FLASH.nscr().read().lock() { |
| 22 | pac::FLASH.seckeyr().write_value(0x4567_0123); | 22 | pac::FLASH.nskeyr().write_value(0x4567_0123); |
| 23 | pac::FLASH.seckeyr().write_value(0xCDEF_89AB); | 23 | pac::FLASH.nskeyr().write_value(0xCDEF_89AB); |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | pub(crate) unsafe fn enable_blocking_write() { | 27 | pub(crate) unsafe fn enable_blocking_write() { |
| 28 | assert_eq!(0, WRITE_SIZE % 4); | 28 | assert_eq!(0, WRITE_SIZE % 4); |
| 29 | 29 | ||
| 30 | pac::FLASH.seccr().write(|w| { | 30 | pac::FLASH.nscr().write(|w| { |
| 31 | w.set_pg(pac::flash::vals::SeccrPg::B_0X1); | 31 | w.set_pg(pac::flash::vals::NscrPg::B_0X1); |
| 32 | }); | 32 | }); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | pub(crate) unsafe fn disable_blocking_write() { | 35 | pub(crate) unsafe fn disable_blocking_write() { |
| 36 | pac::FLASH.seccr().write(|w| w.set_pg(pac::flash::vals::SeccrPg::B_0X0)); | 36 | pac::FLASH.nscr().write(|w| w.set_pg(pac::flash::vals::NscrPg::B_0X0)); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { | 39 | pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { |
| @@ -50,19 +50,19 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) | |||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { | 52 | pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { |
| 53 | pac::FLASH.seccr().modify(|w| { | 53 | pac::FLASH.nscr().modify(|w| { |
| 54 | w.set_per(pac::flash::vals::SeccrPer::B_0X1); | 54 | w.set_per(pac::flash::vals::NscrPer::B_0X1); |
| 55 | w.set_pnb(sector.index_in_bank) | 55 | w.set_pnb(sector.index_in_bank) |
| 56 | }); | 56 | }); |
| 57 | 57 | ||
| 58 | pac::FLASH.seccr().modify(|w| { | 58 | pac::FLASH.nscr().modify(|w| { |
| 59 | w.set_strt(true); | 59 | w.set_strt(true); |
| 60 | }); | 60 | }); |
| 61 | 61 | ||
| 62 | let ret: Result<(), Error> = blocking_wait_ready(); | 62 | let ret: Result<(), Error> = blocking_wait_ready(); |
| 63 | pac::FLASH | 63 | pac::FLASH |
| 64 | .seccr() | 64 | .nscr() |
| 65 | .modify(|w| w.set_per(pac::flash::vals::SeccrPer::B_0X0)); | 65 | .modify(|w| w.set_per(pac::flash::vals::NscrPer::B_0X0)); |
| 66 | clear_all_err(); | 66 | clear_all_err(); |
| 67 | ret | 67 | ret |
| 68 | } | 68 | } |
| @@ -70,12 +70,12 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 70 | pub(crate) unsafe fn clear_all_err() { | 70 | pub(crate) unsafe fn clear_all_err() { |
| 71 | // read and write back the same value. | 71 | // read and write back the same value. |
| 72 | // This clears all "write 1 to clear" bits. | 72 | // This clears all "write 1 to clear" bits. |
| 73 | pac::FLASH.secsr().modify(|_| {}); | 73 | pac::FLASH.nssr().modify(|_| {}); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | unsafe fn blocking_wait_ready() -> Result<(), Error> { | 76 | unsafe fn blocking_wait_ready() -> Result<(), Error> { |
| 77 | loop { | 77 | loop { |
| 78 | let sr = pac::FLASH.secsr().read(); | 78 | let sr = pac::FLASH.nssr().read(); |
| 79 | 79 | ||
| 80 | if !sr.bsy() { | 80 | if !sr.bsy() { |
| 81 | if sr.pgserr() { | 81 | if sr.pgserr() { |
