Skip to content

Commit 63aeaf6

Browse files
committed
Add support for UART4/5
1 parent 97ff2ef commit 63aeaf6

File tree

12 files changed

+422
-40
lines changed

12 files changed

+422
-40
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/gpio.rs

Lines changed: 1 addition & 1 deletion
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;

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,18 @@ mod sealed {
157157
pub trait Sealed {}
158158
}
159159
use sealed::Sealed;
160+
use stm32f1::Periph;
161+
162+
pub trait Ptr {
163+
/// RegisterBlock structure
164+
type RB;
165+
/// Return the pointer to the register block
166+
fn ptr() -> *const Self::RB;
167+
}
168+
169+
impl<RB, const ADDR: usize> Ptr for Periph<RB, ADDR> {
170+
type RB = RB;
171+
fn ptr() -> *const Self::RB {
172+
Self::ptr()
173+
}
174+
}

src/rcc/enable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ macro_rules! ahb_bus {
6565
#[cfg(feature = "stm32f103")]
6666
bus! {
6767
ADC2 => (APB2, 10),
68-
CAN1 => (APB1, 25),
68+
CAN => (APB1, 25),
6969
}
7070
#[cfg(feature = "connectivity")]
7171
bus! {

0 commit comments

Comments
 (0)