Skip to content

Commit 54238fe

Browse files
authored
Merge pull request #156 from braun-embedded/stm32l4-upgrade
Upgrade to latest version of `stm32l4`
2 parents fb40e9f + d4ce6aa commit 54238fe

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ edition = "2018"
2323
[dependencies]
2424
cortex-m = "0.6.3"
2525
nb = "0.1.1"
26-
stm32l4 = "0.11.0"
26+
stm32l4 = "0.12.1"
2727
as-slice = "0.1"
2828
generic-array = "0.13"
2929

src/crc.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use crate::rcc;
2020
use crate::stm32::CRC;
2121
use core::hash::Hasher;
22-
use core::ptr;
2322

2423
/// Extension trait to constrain the CRC peripheral.
2524
pub trait CrcExt {
@@ -119,17 +118,15 @@ impl Config {
119118
Some(BitReversal::ByWord) => 0b11,
120119
};
121120

122-
crc.init.write(|w| unsafe { w.crc_init().bits(init) });
121+
crc.init.write(|w| w.init().bits(init));
123122
crc.pol.write(|w| unsafe { w.bits(poly) });
124123
crc.cr.write(|w| {
125-
unsafe {
126-
w.rev_in()
127-
.bits(in_rev_bits)
128-
.polysize()
129-
.bits(poly_bits)
130-
.reset()
131-
.set_bit();
132-
}
124+
w.rev_in()
125+
.bits(in_rev_bits)
126+
.polysize()
127+
.bits(poly_bits)
128+
.reset()
129+
.set_bit();
133130

134131
if self.output_bit_reversal {
135132
w.rev_out().set_bit()
@@ -162,21 +159,16 @@ impl Crc {
162159
pub fn reset_with_inital_value(&mut self, initial_value: u32) {
163160
let crc = unsafe { &(*CRC::ptr()) };
164161

165-
crc.init
166-
.write(|w| unsafe { w.crc_init().bits(initial_value) });
162+
crc.init.write(|w| w.init().bits(initial_value));
167163
crc.cr.modify(|_, w| w.reset().set_bit());
168164
}
169165

170166
/// Feed the CRC with data
171167
#[inline]
172168
pub fn feed(&mut self, data: &[u8]) {
173169
let crc = unsafe { &(*CRC::ptr()) };
174-
for byte in data {
175-
unsafe {
176-
// Workaround with svd2rust, it does not generate the byte interface to the DR
177-
// register
178-
ptr::write_volatile(&crc.dr as *const _ as *mut u8, *byte);
179-
}
170+
for &byte in data {
171+
crc.dr8().write(|w| w.dr8().bits(byte));
180172
}
181173
}
182174

@@ -197,7 +189,7 @@ impl Crc {
197189
pub fn peek_result(&self) -> u32 {
198190
let crc = unsafe { &(*CRC::ptr()) };
199191

200-
crc.dr.read().bits()
192+
crc.dr().read().bits()
201193
}
202194
}
203195

src/dma.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ macro_rules! dma {
417417
/// `inc` indicates whether the address will be incremented after every byte transfer
418418
#[inline]
419419
pub fn set_peripheral_address(&mut self, address: u32, inc: bool) {
420-
self.cpar().write(|w| w.pa().bits(address) );
420+
self.cpar().write(|w|
421+
unsafe { w.pa().bits(address) }
422+
);
421423
self.ccr().modify(|_, w| w.pinc().bit(inc) );
422424
}
423425

@@ -426,7 +428,9 @@ macro_rules! dma {
426428
/// `inc` indicates whether the address will be incremented after every byte transfer
427429
#[inline]
428430
pub fn set_memory_address(&mut self, address: u32, inc: bool) {
429-
self.cmar().write(|w| w.ma().bits(address) );
431+
self.cmar().write(|w|
432+
unsafe { w.ma().bits(address) }
433+
);
430434
self.ccr().modify(|_, w| w.minc().bit(inc) );
431435
}
432436

0 commit comments

Comments
 (0)