Skip to content

Commit 89690a8

Browse files
committed
Use modify instead of write for clearing sr1
1 parent 5fc8b99 commit 89690a8

File tree

10 files changed

+37
-23
lines changed

10 files changed

+37
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
Remove `RemapStruct`s. [#462] [#506] [#509]
1717
- Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462]
1818
- Take `&Clocks` instead of `Clocks` [#498]
19-
- Temporary replace `stm32f1` with `stm32f1-staging` [#503]
19+
- Temporary replace `stm32f1` with `stm32f1-staging` v0.17.1 [#503]
2020
- `Spi` now takes `Option<PIN>` for `SCK`, `MISO`, `MOSI` [#514]
2121
- move `Qei` mod inside `pwm_input` mod [#516]
2222

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
edition = "2021"
33
rust-version = "1.59"
44

5-
authors = ["Jorge Aparicio <[email protected]>", "Daniel Egger <[email protected]>"]
5+
authors = [
6+
"Jorge Aparicio <[email protected]>",
7+
"Daniel Egger <[email protected]>",
8+
]
69
categories = ["embedded", "hardware-support", "no-std"]
710
description = "HAL for the STM32F1xx family of microcontrollers"
811
keywords = ["arm", "cortex-m", "stm32", "hal"]
@@ -33,7 +36,7 @@ vcell = "0.1.3"
3336

3437
[dependencies.stm32f1]
3538
package = "stm32f1-staging"
36-
version = "0.16.0"
39+
version = "0.17.1"
3740
features = ["atomics"]
3841

3942
[dependencies.embedded-hal-02]

src/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ macro_rules! adc_hal {
256256

257257
#[inline(always)]
258258
pub fn set_external_trigger(&mut self, trigger: crate::pac::$adc::cr2::EXTSEL) {
259-
self.rb.cr2().modify(|_, w| w.extsel().variant(trigger))
259+
self.rb.cr2().modify(|_, w| w.extsel().variant(trigger));
260260
}
261261

262262
fn power_up(&mut self) {
@@ -336,7 +336,7 @@ macro_rules! adc_hal {
336336
16 => self.rb.smpr1().modify(|_, w| w.smp16().set(sample_time)),
337337
17 => self.rb.smpr1().modify(|_, w| w.smp17().set(sample_time)),
338338
_ => unreachable!(),
339-
}
339+
};
340340
}
341341

342342
fn set_regular_sequence (&mut self, channels: &[u8]) {

src/crc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Crc {
3030
}
3131

3232
pub fn write(&mut self, val: u32) {
33-
self.crc.dr().write(|w| w.dr().set(val))
33+
self.crc.dr().write(|w| w.dr().set(val));
3434
}
3535

3636
pub fn reset(&self) {

src/dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ impl<DMA: DmaExt, const C: u8> Ch<DMA, C> {
165165
match event {
166166
Event::HalfTransfer => self.ch().cr().modify(|_, w| w.htie().set_bit()),
167167
Event::TransferComplete => self.ch().cr().modify(|_, w| w.tcie().set_bit()),
168-
}
168+
};
169169
}
170170

171171
pub fn unlisten(&mut self, event: Event) {
172172
match event {
173173
Event::HalfTransfer => self.ch().cr().modify(|_, w| w.htie().clear_bit()),
174174
Event::TransferComplete => self.ch().cr().modify(|_, w| w.tcie().clear_bit()),
175-
}
175+
};
176176
}
177177

178178
pub fn ch(&mut self) -> &pac::dma1::CH {

src/gpio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,14 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
532532
fn _set_high(&mut self) {
533533
// NOTE(unsafe) atomic write to a stateless register
534534
let gpio = unsafe { &(*gpiox::<P>()) };
535-
gpio.bsrr().write(|w| w.bs(N).set_bit())
535+
gpio.bsrr().write(|w| w.bs(N).set_bit());
536536
}
537537

538538
#[inline(always)]
539539
fn _set_low(&mut self) {
540540
// NOTE(unsafe) atomic write to a stateless register
541541
let gpio = unsafe { &(*gpiox::<P>()) };
542-
gpio.bsrr().write(|w| w.br(N).set_bit())
542+
gpio.bsrr().write(|w| w.br(N).set_bit());
543543
}
544544

545545
#[inline(always)]
@@ -966,7 +966,7 @@ where
966966
} else {
967967
w.br(N).set_bit()
968968
}
969-
})
969+
});
970970
}
971971

972972
match N {

src/i2c.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ impl<I2C: Instance> I2c<I2C> {
271271

272272
/// Generate START condition
273273
fn send_start(&mut self) {
274+
// Clear all pending error bits
275+
// NOTE(unsafe): Writing 0 clears the r/w bits and has no effect on the r bits
276+
self.i2c.sr1().write(|w| unsafe { w.bits(0) });
274277
self.i2c.cr1().modify(|_, w| w.start().set_bit());
275278
}
276279

src/rcc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl CFGR {
213213
} else {
214214
0b010
215215
})
216-
})
216+
});
217217
}
218218

219219
let rcc = unsafe { &*RCC::ptr() };

src/rtc.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Rtc<RtcClkLse> {
128128
w.rtcen().set_bit();
129129
// Set the source of the RTC to LSE
130130
w.rtcsel().lse()
131-
})
131+
});
132132
}
133133
}
134134

@@ -202,7 +202,7 @@ impl Rtc<RtcClkLsi> {
202202
w.rtcen().set_bit();
203203
// Set the source of the RTC to LSI
204204
w.rtcsel().lsi()
205-
})
205+
});
206206
}
207207
}
208208

@@ -280,7 +280,7 @@ impl Rtc<RtcClkHseDiv128> {
280280
w.rtcen().set_bit();
281281
// Set the source of the RTC to HSE/128
282282
w.rtcsel().hse()
283-
})
283+
});
284284
}
285285
}
286286

@@ -365,22 +365,30 @@ impl<CS> Rtc<CS> {
365365

366366
/// Enables triggering the RTC interrupt every time the RTC counter is increased
367367
pub fn listen_seconds(&mut self) {
368-
self.perform_write(|s| s.regs.crh().modify(|_, w| w.secie().set_bit()))
368+
self.perform_write(|s| {
369+
s.regs.crh().modify(|_, w| w.secie().set_bit());
370+
})
369371
}
370372

371373
/// Disables the RTC second interrupt
372374
pub fn unlisten_seconds(&mut self) {
373-
self.perform_write(|s| s.regs.crh().modify(|_, w| w.secie().clear_bit()))
375+
self.perform_write(|s| {
376+
s.regs.crh().modify(|_, w| w.secie().clear_bit());
377+
})
374378
}
375379

376380
/// Clears the RTC second interrupt flag
377381
pub fn clear_second_flag(&mut self) {
378-
self.perform_write(|s| s.regs.crl().modify(|_, w| w.secf().clear_bit()))
382+
self.perform_write(|s| {
383+
s.regs.crl().modify(|_, w| w.secf().clear_bit());
384+
})
379385
}
380386

381387
/// Clears the RTC alarm interrupt flag
382388
pub fn clear_alarm_flag(&mut self) {
383-
self.perform_write(|s| s.regs.crl().modify(|_, w| w.alrf().clear_bit()))
389+
self.perform_write(|s| {
390+
s.regs.crl().modify(|_, w| w.alrf().clear_bit());
391+
})
384392
}
385393

386394
/**

src/timer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ macro_rules! hal {
325325
}
326326
#[inline(always)]
327327
unsafe fn set_auto_reload_unchecked(&mut self, arr: u32) {
328-
self.arr().write(|w| w.bits(arr))
328+
self.arr().write(|w| w.bits(arr));
329329
}
330330
#[inline(always)]
331331
fn set_auto_reload(&mut self, arr: u32) -> Result<(), Error> {
@@ -445,7 +445,7 @@ macro_rules! with_pwm {
445445
let tim = unsafe { &*<$TIM>::ptr() };
446446
#[allow(unused_unsafe)]
447447
if channel < Self::CH_NUMBER {
448-
tim.ccr(channel as usize).write(|w| unsafe { w.bits(value) })
448+
tim.ccr(channel as usize).write(|w| unsafe { w.bits(value) });
449449
}
450450
}
451451

@@ -493,7 +493,7 @@ macro_rules! with_pwm {
493493
let tim = unsafe { &*<$TIM>::ptr() };
494494
#[allow(unused_unsafe)]
495495
if channel < Self::CH_NUMBER {
496-
tim.ccr(channel as usize).write(|w| unsafe { w.bits(value) })
496+
tim.ccr(channel as usize).write(|w| unsafe { w.bits(value) });
497497
}
498498
}
499499

@@ -539,7 +539,7 @@ macro_rules! with_pwm {
539539
#[inline(always)]
540540
fn set_cc_value(channel: u8, value: u32) {
541541
let tim = unsafe { &*<$TIM>::ptr() };
542-
tim.ccr(channel as usize).write(|w| unsafe { w.bits(value) })
542+
tim.ccr(channel as usize).write(|w| unsafe { w.bits(value) });
543543
}
544544

545545
#[inline(always)]

0 commit comments

Comments
 (0)