Skip to content

Commit 60d262a

Browse files
authored
Merge pull request #766 from stm32-rs/unsafe
rm unused unused_unsafe
2 parents 4ca768f + b7a6a41 commit 60d262a

File tree

6 files changed

+14
-29
lines changed

6 files changed

+14
-29
lines changed

src/flash.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
56
use crate::pac::FLASH;
67
use crate::signature::FlashSize;
78
use 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<'_> {
265263
const UNLOCK_KEY1: u32 = 0x45670123;
266264
const UNLOCK_KEY2: u32 = 0xCDEF89AB;
267265

268-
#[allow(unused_unsafe)]
269266
fn 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) });

src/qei.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ macro_rules! hal {
105105
impl Instance for $TIM {
106106
fn setup_qei(&mut self) {
107107
// Configure TxC1 and TxC2 as captures
108-
#[cfg(not(feature = "gpio-f410"))]
109108
self.ccmr1_input().write(|w| w.cc1s().ti1().cc2s().ti2());
110-
#[cfg(feature = "gpio-f410")]
111-
self.ccmr1_input()
112-
.write(|w| unsafe { w.cc1s().bits(0b01).cc2s().bits(0b01) });
113109
// enable and configure to capture on rising edge
114110
self.ccer().write(|w| {
115111
w.cc1e().set_bit().cc1p().clear_bit();

src/qspi.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,11 @@ impl<BANK: QspiPins> Qspi<BANK> {
381381
while self.qspi.sr().read().busy().bit_is_set() {}
382382

383383
self.qspi.cr().modify(|_, w| unsafe {
384-
w.prescaler()
385-
.bits(config.clock_prescaler)
386-
.sshift()
387-
.bit(config.sample_shift == SampleShift::HalfACycle)
388-
.fsel()
389-
.bit(BANK::FSEL)
390-
.dfm()
391-
.bit(BANK::DFM)
384+
w.prescaler().bits(config.clock_prescaler);
385+
w.sshift()
386+
.bit(config.sample_shift == SampleShift::HalfACycle);
387+
w.fsel().bit(BANK::FSEL);
388+
w.dfm().bit(BANK::DFM)
392389
});
393390
while self.is_busy() {}
394391

src/sdio.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ impl<P: SdioPeripheral> Sdio<P> {
352352
self.sdio.dlen().write(|w| w.datalength().set(length_bytes));
353353
// Transfer
354354
self.sdio.dctrl().write(|w| {
355-
#[allow(unused_unsafe)]
356355
unsafe {
357356
w.dblocksize().bits(block_size);
358357
} // 2^n bytes block size

src/timer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,7 @@ macro_rules! hal {
474474
}
475475
#[inline(always)]
476476
fn write_count(&mut self, value:Self::Width) {
477-
//TODO: remove "unsafe" when possible
478-
#[allow(unused_unsafe)]
479-
self.cnt().write(|w|unsafe{w.cnt().bits(value)});
477+
self.cnt().write(|w| unsafe { w.cnt().bits(value) });
480478
}
481479
#[inline(always)]
482480
fn start_one_pulse(&mut self) {
@@ -517,7 +515,6 @@ macro_rules! hal {
517515
fn set_cc_value(c: u8, value: u32) {
518516
let tim = unsafe { &*<$TIM>::ptr() };
519517
if c < Self::CH_NUMBER {
520-
#[allow(unused_unsafe)]
521518
tim.ccr(c as usize).write(|w| unsafe { w.bits(value) })
522519
}
523520
}

src/timer/pwm_input.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ macro_rules! hal {
7575
/// 1. When a new cycle is started: the duty cycle will be `1.00`
7676
/// 2. When the period is captured. the duty cycle will be an observable value.
7777
/// See the pwm input example for an suitable interrupt handler.
78-
#[allow(unused_unsafe)] //for some chips the operations are considered safe.
7978
pub fn pwm_input(
8079
mut self,
8180
best_guess: Hertz,

0 commit comments

Comments
 (0)