Skip to content

Commit b622e01

Browse files
authored
Merge pull request #620 from stm32-rs/serialx
usart deref
2 parents 37f32c7 + 2678900 commit b622e01

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
- Add autoimplementations of `DMASet` [#614]
1111
- Simplify `gpio::Outport` [#611]
12-
- rcc `enable_unchecked`, timer features
12+
- rcc `enable_unchecked`, timer features [#618]
1313
- Split SPI master and slave implementations [#609]
1414
- Split USART and UART implementations [#608]
1515
- Add `lapce` editor settings [#601]
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3737
[#611]: https://github.com/stm32-rs/stm32f4xx-hal/pull/611
3838
[#614]: https://github.com/stm32-rs/stm32f4xx-hal/pull/614
3939
[#617]: https://github.com/stm32-rs/stm32f4xx-hal/pull/617
40+
[#618]: https://github.com/stm32-rs/stm32f4xx-hal/pull/618
4041

4142
## [v0.15.0] - 2023-03-13
4243

src/serial.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
use core::fmt;
1818
use core::marker::PhantomData;
19+
use core::ops::Deref;
1920

2021
use crate::rcc;
2122
use nb::block;
@@ -192,34 +193,29 @@ impl<USART: Instance, WORD> Serial<USART, WORD> {
192193
return Err(config::InvalidConfig);
193194
};
194195

195-
unsafe { (*USART::ptr()).brr.write(|w| w.bits(div)) };
196+
usart.brr.write(|w| unsafe { w.bits(div) });
196197

197198
// Reset other registers to disable advanced USART features
198-
unsafe { (*USART::ptr()).cr2.reset() };
199-
unsafe { (*USART::ptr()).cr3.reset() };
199+
usart.cr2.reset();
200+
usart.cr3.reset();
200201

201202
// Enable transmission and receiving
202203
// and configure frame
203-
unsafe {
204-
(*USART::ptr()).cr1.write(|w| {
205-
w.ue().set_bit();
206-
w.over8().bit(over8);
207-
w.te().set_bit();
208-
w.re().set_bit();
209-
w.m().bit(config.wordlength == WordLength::DataBits9);
210-
w.pce().bit(config.parity != Parity::ParityNone);
211-
w.ps().bit(config.parity == Parity::ParityOdd)
212-
})
213-
};
204+
205+
usart.cr1.write(|w| {
206+
w.ue().set_bit();
207+
w.over8().bit(over8);
208+
w.te().set_bit();
209+
w.re().set_bit();
210+
w.m().bit(config.wordlength == WordLength::DataBits9);
211+
w.pce().bit(config.parity != Parity::ParityNone);
212+
w.ps().bit(config.parity == Parity::ParityOdd)
213+
});
214214

215215
match config.dma {
216-
DmaConfig::Tx => unsafe { (*USART::ptr()).cr3.write(|w| w.dmat().enabled()) },
217-
DmaConfig::Rx => unsafe { (*USART::ptr()).cr3.write(|w| w.dmar().enabled()) },
218-
DmaConfig::TxRx => unsafe {
219-
(*USART::ptr())
220-
.cr3
221-
.write(|w| w.dmar().enabled().dmat().enabled())
222-
},
216+
DmaConfig::Tx => usart.cr3.write(|w| w.dmat().enabled()),
217+
DmaConfig::Rx => usart.cr3.write(|w| w.dmar().enabled()),
218+
DmaConfig::TxRx => usart.cr3.write(|w| w.dmar().enabled().dmat().enabled()),
223219
DmaConfig::None => {}
224220
}
225221

@@ -246,7 +242,14 @@ impl<USART: Instance, WORD> Serial<USART, WORD> {
246242
use crate::pac::usart1 as uart_base;
247243

248244
// Implemented by all USART instances
249-
pub trait Instance: crate::Sealed + rcc::Enable + rcc::Reset + rcc::BusClock + CommonPins {
245+
pub trait Instance:
246+
crate::Sealed
247+
+ Deref<Target = uart_base::RegisterBlock>
248+
+ rcc::Enable
249+
+ rcc::Reset
250+
+ rcc::BusClock
251+
+ CommonPins
252+
{
250253
#[doc(hidden)]
251254
fn ptr() -> *const uart_base::RegisterBlock;
252255
#[doc(hidden)]

0 commit comments

Comments
 (0)