Skip to content

Commit 85cea2f

Browse files
committed
Fix for incorrect register field width in STM32G4 category metadata
1 parent ccbe320 commit 85cea2f

File tree

1 file changed

+11
-1
lines changed
  • embassy-stm32/src/flash

1 file changed

+11
-1
lines changed

embassy-stm32/src/flash/g.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE])
5151
wait_ready_blocking()
5252
}
5353

54+
/// Fix for incorrect register field width in STM32G4 category metadata
55+
#[cfg(flash_g4c4)]
56+
#[inline(always)]
57+
pub fn set_pnb_c4(cr: &mut stm32_metapac::flash::regs::Cr, val: u8) {
58+
cr.0 = (cr.0 & !(0xff << 3usize)) | (((val as u32) & 0xff) << 3usize);
59+
}
60+
5461
pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> {
5562
let idx = (sector.start - super::FLASH_BASE as u32) / super::BANK1_REGION.erase_size as u32;
5663
wait_busy();
@@ -63,7 +70,10 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E
6370
w.set_bker(sector.bank == crate::flash::FlashBank::Bank2);
6471
#[cfg(flash_g0x0)]
6572
w.set_pnb(idx as u16);
66-
#[cfg(not(flash_g0x0))]
73+
#[cfg(flash_g4c4)]
74+
set_pnb_c4(w, idx as u8);
75+
// otherwise
76+
#[cfg(not(any(flash_g0x0, flash_g4c4)))]
6777
w.set_pnb(idx as u8);
6878
w.set_strt(true);
6979
});

0 commit comments

Comments
 (0)