aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/flash/g.rs
diff options
context:
space:
mode:
authorchanterheld <[email protected]>2025-01-02 20:05:01 +0100
committerchanterheld <[email protected]>2025-01-02 20:05:01 +0100
commitf1ffbf2f7edc2afbf83ce75c7a3e0f59da09de00 (patch)
tree66859c4d44f9ae98318e030469a984268365935f /embassy-stm32/src/flash/g.rs
parenteaa44c3d3ff71fe3f6c3c343843272bea8b08cf3 (diff)
embassy-stm32. support g0 second flash bank
Diffstat (limited to 'embassy-stm32/src/flash/g.rs')
-rw-r--r--embassy-stm32/src/flash/g.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/embassy-stm32/src/flash/g.rs b/embassy-stm32/src/flash/g.rs
index 01a0c603f..d02e1435d 100644
--- a/embassy-stm32/src/flash/g.rs
+++ b/embassy-stm32/src/flash/g.rs
@@ -20,7 +20,7 @@ pub(crate) unsafe fn lock() {
20} 20}
21pub(crate) unsafe fn unlock() { 21pub(crate) unsafe fn unlock() {
22 // Wait, while the memory interface is busy. 22 // Wait, while the memory interface is busy.
23 while pac::FLASH.sr().read().bsy() {} 23 wait_busy();
24 24
25 // Unlock flash 25 // Unlock flash
26 if pac::FLASH.cr().read().lock() { 26 if pac::FLASH.cr().read().lock() {
@@ -53,12 +53,16 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE])
53 53
54pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { 54pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> {
55 let idx = (sector.start - super::FLASH_BASE as u32) / super::BANK1_REGION.erase_size as u32; 55 let idx = (sector.start - super::FLASH_BASE as u32) / super::BANK1_REGION.erase_size as u32;
56 while pac::FLASH.sr().read().bsy() {} 56 wait_busy();
57 clear_all_err(); 57 clear_all_err();
58 58
59 interrupt::free(|_| { 59 interrupt::free(|_| {
60 pac::FLASH.cr().modify(|w| { 60 pac::FLASH.cr().modify(|w| {
61 w.set_per(true); 61 w.set_per(true);
62 w.set_bker(sector.bank == crate::flash::FlashBank::Bank2);
63 #[cfg(flash_g0x0)]
64 w.set_pnb(idx as u16);
65 #[cfg(not(flash_g0x0))]
62 w.set_pnb(idx as u8); 66 w.set_pnb(idx as u8);
63 w.set_strt(true); 67 w.set_strt(true);
64 }); 68 });
@@ -94,3 +98,13 @@ pub(crate) unsafe fn clear_all_err() {
94 // This clears all "write 1 to clear" bits. 98 // This clears all "write 1 to clear" bits.
95 pac::FLASH.sr().modify(|_| {}); 99 pac::FLASH.sr().modify(|_| {});
96} 100}
101
102#[cfg(any(flash_g0x0, flash_g0x1))]
103fn wait_busy(){
104 while pac::FLASH.sr().read().bsy() & pac::FLASH.sr().read().bsy2() {}
105}
106
107#[cfg(not(any(flash_g0x0, flash_g0x1)))]
108fn wait_busy(){
109 while pac::FLASH.sr().read().bsy() {}
110} \ No newline at end of file