Skip to content

Commit f8944d1

Browse files
authored
Merge pull request #529 from stm32-rs/uart
Add support for UART4/5
2 parents 97ff2ef + 67ee9d8 commit f8944d1

File tree

16 files changed

+426
-47
lines changed

16 files changed

+426
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3838

3939
### Added
4040

41+
- `Serial` support for UART4/5
4142
- Allow to set HSE bypass bit in `RCC` clock configuration register to use an external clock input on the `OSC_IN` pin [#485]
4243
- initial support of `embedded-hal-1.0` [#416]
4344
- Add tools/check.py python script for local check [#467]

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ vcell = "0.1.3"
3636

3737
[dependencies.stm32f1]
3838
package = "stm32f1-staging"
39-
version = "0.17.1"
39+
version = "0.19.0"
4040
features = ["atomics"]
4141

4242
[dependencies.embedded-hal-02]

examples/can-echo.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ fn main() -> ! {
2929
let rx = gpioa.pa11;
3030
let tx = gpioa.pa12;
3131

32-
let can = dp.CAN1.can(
33-
#[cfg(not(feature = "connectivity"))]
34-
dp.USB,
35-
(tx, rx),
36-
);
32+
#[cfg(not(feature = "connectivity"))]
33+
let can = dp.CAN.can(dp.USB, (tx, rx));
34+
#[cfg(feature = "connectivity")]
35+
let can = dp.CAN1.can((tx, rx));
3736

3837
// APB1 (PCLK1): 8MHz, Bit rate: 125kBit/s, Sample Point 87.5%
3938
// Value was calculated with http://www.bittiming.can-wiki.info/

examples/can-loopback.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ fn main() -> ! {
2525
// resonator must be used.
2626
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
2727

28-
let can = Can::<_, Floating>::new_loopback(
29-
dp.CAN1,
30-
#[cfg(not(feature = "connectivity"))]
31-
dp.USB,
32-
);
28+
#[cfg(not(feature = "connectivity"))]
29+
let can = Can::<_, Floating>::new_loopback(dp.CAN, dp.USB);
30+
#[cfg(feature = "connectivity")]
31+
let can = Can::<_, Floating>::new_loopback(dp.CAN1);
3332

3433
// Use loopback mode: No pins need to be assigned to peripheral.
3534
// APB1 (PCLK1): 8MHz, Bit rate: 500Bit/s, Sample Point 87.5%

examples/can-rtic.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ mod app {
5555
use super::{enqueue_frame, PriorityFrame};
5656
use bxcan::{filter::Mask32, ExtendedId, Fifo, Frame, Interrupts, Rx0, StandardId, Tx};
5757
use heapless::binary_heap::{BinaryHeap, Max};
58-
use stm32f1xx_hal::{can::Can, pac::CAN1, prelude::*};
58+
#[cfg(not(feature = "connectivity"))]
59+
use stm32f1xx_hal::pac::CAN as CAN1;
60+
#[cfg(feature = "connectivity")]
61+
use stm32f1xx_hal::pac::CAN1;
62+
use stm32f1xx_hal::{can::Can, prelude::*};
5963

6064
#[local]
6165
struct Local {
@@ -88,7 +92,7 @@ mod app {
8892
let can_tx_pin = gpioa.pa12;
8993

9094
#[cfg(not(feature = "connectivity"))]
91-
let can = Can::new(cx.device.CAN1, cx.device.USB, (can_tx_pin, can_rx_pin));
95+
let can = Can::new(cx.device.CAN, cx.device.USB, (can_tx_pin, can_rx_pin));
9296

9397
#[cfg(feature = "connectivity")]
9498
let can = Can::new(cx.device.CAN1, (can_tx_pin, can_rx_pin));

src/afio.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ remap! {
215215

216216
#[cfg(feature = "stm32f103")]
217217
remap! {
218-
pac::CAN1: MAPR, u8: can_remap, { 0 | 2 | 3 };
218+
pac::CAN: MAPR, u8: can_remap, { 0 | 2 | 3 };
219219
}
220220

221221
#[cfg(feature = "connectivity")]
@@ -303,7 +303,11 @@ pub mod can1 {
303303
],
304304
}
305305

306-
impl CanCommon for pac::CAN1 {
306+
#[cfg(not(feature = "connectivity"))]
307+
use pac::CAN as CAN1;
308+
#[cfg(feature = "connectivity")]
309+
use pac::CAN1;
310+
impl CanCommon for CAN1 {
307311
type Tx = Tx;
308312
type Rx<PULL> = Rx<PULL>;
309313
}

src/can.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ impl<CAN: Instance> CanExt for CAN {
5858
}
5959

6060
pub trait Instance: crate::rcc::Enable + afio::CanCommon {}
61-
impl Instance for pac::CAN1 {}
61+
#[cfg(not(feature = "connectivity"))]
62+
use pac::CAN as CAN1;
63+
#[cfg(feature = "connectivity")]
64+
use pac::CAN1;
65+
66+
impl Instance for CAN1 {}
6267
#[cfg(feature = "connectivity")]
6368
impl Instance for pac::CAN2 {}
6469

@@ -125,18 +130,18 @@ impl<CAN: Instance, PULL: UpMode> Can<CAN, PULL> {
125130
}
126131
}
127132

128-
unsafe impl<PULL> bxcan::Instance for Can<pac::CAN1, PULL> {
129-
const REGISTERS: *mut bxcan::RegisterBlock = pac::CAN1::ptr() as *mut _;
133+
unsafe impl<PULL> bxcan::Instance for Can<CAN1, PULL> {
134+
const REGISTERS: *mut bxcan::RegisterBlock = CAN1::ptr() as *mut _;
130135
}
131136

132137
#[cfg(feature = "connectivity")]
133138
unsafe impl<PULL> bxcan::Instance for Can<pac::CAN2, PULL> {
134139
const REGISTERS: *mut bxcan::RegisterBlock = pac::CAN2::ptr() as *mut _;
135140
}
136141

137-
unsafe impl<PULL> bxcan::FilterOwner for Can<pac::CAN1, PULL> {
142+
unsafe impl<PULL> bxcan::FilterOwner for Can<CAN1, PULL> {
138143
const NUM_FILTER_BANKS: u8 = 28;
139144
}
140145

141146
#[cfg(feature = "connectivity")]
142-
unsafe impl<PULL> bxcan::MasterInstance for Can<pac::CAN1, PULL> {}
147+
unsafe impl<PULL> bxcan::MasterInstance for Can<CAN1, PULL> {}

src/flash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct FlashWriter<'a> {
6363
flash_sz: FlashSize,
6464
verify: bool,
6565
}
66-
impl<'a> FlashWriter<'a> {
66+
impl FlashWriter<'_> {
6767
fn unlock(&mut self) -> Result<()> {
6868
// Wait for any ongoing operations
6969
while self.flash.sr.sr().read().bsy().bit_is_set() {}
@@ -245,7 +245,7 @@ impl<'a> FlashWriter<'a> {
245245

246246
// Flash is written 16 bits at a time, so combine two bytes to get a
247247
// half-word
248-
let hword: u16 = (data[idx] as u16) | (data[idx + 1] as u16) << 8;
248+
let hword: u16 = (data[idx] as u16) | ((data[idx + 1] as u16) << 8);
249249

250250
// NOTE(unsafe) Write to FLASH area with no side effects
251251
unsafe { core::ptr::write_volatile(write_address, hword) };

src/gpio.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ mod sealed {
223223
}
224224
}
225225

226-
use crate::pac::gpioa::crl::{CNF0 as Cnf, MODE0 as Mode};
226+
use crate::pac::gpioa::crl::{CONFIG as Cnf, MODE as Mode};
227227

228228
use sealed::Interruptable;
229229
pub(crate) use sealed::PinMode;
@@ -519,7 +519,6 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
519519
before changing its mode to an output to avoid
520520
a short spike of an incorrect value
521521
*/
522-
523522
#[inline(always)]
524523
fn _set_state(&mut self, state: PinState) {
525524
match state {

src/i2c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<I2C: Instance> I2c<I2C> {
282282
fn send_addr(&self, addr: u8, read: bool) {
283283
self.i2c
284284
.dr()
285-
.write(|w| w.dr().set(addr << 1 | (u8::from(read))));
285+
.write(|w| w.dr().set((addr << 1) | (u8::from(read))));
286286
}
287287

288288
/// Generate STOP condition

0 commit comments

Comments
 (0)