@@ -2,6 +2,7 @@ use embedded_storage::nor_flash::{
22 ErrorType , MultiwriteNorFlash , NorFlash , NorFlashError , NorFlashErrorKind , ReadNorFlash ,
33} ;
44
5+ use crate :: pac:: flash:: cr:: PSIZE ;
56use crate :: pac:: FLASH ;
67use crate :: signature:: FlashSize ;
78use core:: { ptr, slice} ;
@@ -101,8 +102,6 @@ impl FlashExt for FLASH {
101102 }
102103}
103104
104- const PSIZE_X8 : u8 = 0b00 ;
105-
106105/// Read-only flash
107106///
108107/// # Examples
@@ -196,13 +195,14 @@ impl UnlockedFlash<'_> {
196195 pub fn erase ( & mut self , sector : u8 ) -> Result < ( ) , Error > {
197196 let snb = if sector < 12 { sector } else { sector + 4 } ;
198197
199- #[ rustfmt:: skip]
200- self . flash . cr ( ) . modify ( |_, w| unsafe {
198+ self . flash . cr ( ) . modify ( |_, w| {
201199 // start
202200 w. strt ( ) . set_bit ( ) ;
203- w. psize ( ) . bits ( PSIZE_X8 ) ;
201+ w. psize ( ) . variant ( PSIZE :: Psize8 ) ;
204202 // sector number
205- w. snb ( ) . bits ( snb) ;
203+ unsafe {
204+ w. snb ( ) . bits ( snb) ;
205+ }
206206 // sectore erase
207207 w. ser ( ) . set_bit ( ) ;
208208 // no programming
@@ -224,10 +224,8 @@ impl UnlockedFlash<'_> {
224224 bytes_written = 0 ;
225225 let amount = 16 - ( offset % 16 ) ;
226226
227- #[ rustfmt:: skip]
228- #[ allow( unused_unsafe) ]
229- self . flash . cr ( ) . modify ( |_, w| unsafe {
230- w. psize ( ) . bits ( PSIZE_X8 ) ;
227+ self . flash . cr ( ) . modify ( |_, w| {
228+ w. psize ( ) . variant ( PSIZE :: Psize8 ) ;
231229 // no sector erase
232230 w. ser ( ) . clear_bit ( ) ;
233231 // programming
@@ -265,7 +263,6 @@ impl UnlockedFlash<'_> {
265263const UNLOCK_KEY1 : u32 = 0x45670123 ;
266264const UNLOCK_KEY2 : u32 = 0xCDEF89AB ;
267265
268- #[ allow( unused_unsafe) ]
269266fn unlock ( flash : & FLASH ) {
270267 flash. keyr ( ) . write ( |w| unsafe { w. key ( ) . bits ( UNLOCK_KEY1 ) } ) ;
271268 flash. keyr ( ) . write ( |w| unsafe { w. key ( ) . bits ( UNLOCK_KEY2 ) } ) ;
0 commit comments