Skip to content

Commit 608d5fc

Browse files
authored
Merge pull request #6 from starboundstitch/starboundstitch/stm32c071-init
Add support for stm32c071
2 parents b3a23c9 + 2e3669f commit 608d5fc

File tree

9 files changed

+64
-3
lines changed

9 files changed

+64
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ device-selected = []
4848
rt = ["stm32c0/rt"]
4949
stm32c011 = ["stm32c0/stm32c011", "device-selected"]
5050
stm32c031 = ["stm32c0/stm32c031", "device-selected"]
51+
stm32c071 = ["stm32c0/stm32c071", "device-selected"]
5152

5253
i2c-blocking = []
5354
i2c-nonblocking = []

src/exti.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub enum Event {
2323
GPIO15 = 15,
2424
RTC = 19,
2525
I2C1 = 23,
26+
#[cfg(feature = "stm32c071")]
27+
I2C2 = 24,
2628
USART1 = 25,
2729
LSE_CSS = 31,
2830
}

src/i2c/blocking.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use crate::rcc::*;
66
use crate::stm32::I2C1;
77
use hal::blocking::i2c::{Read, Write, WriteRead};
88

9+
#[cfg(feature = "stm32c071")]
10+
use crate::stm32::I2C2;
11+
912
pub trait I2cSlave {
1013
/// Enable/Disable Slave Byte Control. Default SBC is switched on.
1114
/// For master write/read the transaction should start with sbc disabled.
@@ -521,3 +524,25 @@ i2c!(
521524
(PB7<Output<OpenDrain>>, AltFunction::AF14),
522525
],
523526
);
527+
528+
#[cfg(feature = "stm32c071")]
529+
i2c!(
530+
I2C2,
531+
i2c2,
532+
sda: [
533+
(PA6<Output<OpenDrain>>, AltFunction::AF6),
534+
(PA12<Output<OpenDrain>>, AltFunction::AF6),
535+
(PA10<Output<OpenDrain>>, AltFunction::AF8),
536+
(PB4<Output<OpenDrain>>, AltFunction::AF6),
537+
(PB11<Output<OpenDrain>>, AltFunction::AF6),
538+
(PB14<Output<OpenDrain>>, AltFunction::AF6),
539+
],
540+
scl: [
541+
(PA7<Output<OpenDrain>>, AltFunction::AF6),
542+
(PA11<Output<OpenDrain>>, AltFunction::AF6),
543+
(PA9<Output<OpenDrain>>, AltFunction::AF8),
544+
(PB3<Output<OpenDrain>>, AltFunction::AF5),
545+
(PB10<Output<OpenDrain>>, AltFunction::AF6),
546+
(PB13<Output<OpenDrain>>, AltFunction::AF6),
547+
],
548+
);

src/i2c/nonblocking.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use crate::rcc::*;
77
use crate::stm32::I2C;
88
use nb::Error::{Other, WouldBlock};
99

10+
#[cfg(feature = "stm32c071")]
11+
use crate::stm32::I2C2;
12+
1013
pub trait I2cControl {
1114
/// Start listening for an interrupt event, will also enable non_blocking mode
1215
fn listen(&mut self);
@@ -604,3 +607,25 @@ i2c!(
604607
(PB7<Output<OpenDrain>>, AltFunction::AF14),
605608
],
606609
);
610+
611+
#[cfg(feature = "stm32c071")]
612+
i2c!(
613+
I2C2,
614+
i2c2,
615+
sda: [
616+
(PA6<Output<OpenDrain>>, AltFunction::AF6),
617+
(PA12<Output<OpenDrain>>, AltFunction::AF6),
618+
(PA10<Output<OpenDrain>>, AltFunction::AF8),
619+
(PB4<Output<OpenDrain>>, AltFunction::AF6),
620+
(PB11<Output<OpenDrain>>, AltFunction::AF6),
621+
(PB14<Output<OpenDrain>>, AltFunction::AF6),
622+
],
623+
scl: [
624+
(PA7<Output<OpenDrain>>, AltFunction::AF6),
625+
(PA11<Output<OpenDrain>>, AltFunction::AF6),
626+
(PA9<Output<OpenDrain>>, AltFunction::AF8),
627+
(PB3<Output<OpenDrain>>, AltFunction::AF5),
628+
(PB10<Output<OpenDrain>>, AltFunction::AF6),
629+
(PB13<Output<OpenDrain>>, AltFunction::AF6),
630+
],
631+
);

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub use stm32c0::stm32c011 as stm32;
2323
#[cfg(feature = "stm32c031")]
2424
pub use stm32c0::stm32c031 as stm32;
2525

26+
#[cfg(feature = "stm32c071")]
27+
pub use stm32c0::stm32c071 as stm32;
28+
2629
#[cfg(feature = "rt")]
2730
pub use crate::stm32::interrupt;
2831

src/rcc/enable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,8 @@ bus! {
137137
GPIOD => (IOP, gpioden, gpiodsmen, gpiodrst), // 3
138138
GPIOF => (IOP, gpiofen, gpiofsmen, gpiofrst), // 5
139139
}
140+
141+
#[cfg(feature = "stm32c071")]
142+
bus! {
143+
I2C2 => (APB1, i2c2en, i2c2smen, i2c2rst), // 21
144+
}

src/timer/opm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ macro_rules! opm {
6767
unsafe {
6868
let tim = &*$TIMX::ptr();
6969
tim.psc().write(|w| w.psc().bits(psc as u16));
70-
tim.arr().write(|w| w.$arr().bits(reload as u16));
70+
tim.arr().write(|w| w.$arr().bits((reload as u16).into()));
7171
$(
7272
tim.arr.modify(|_, w| w.$arr_h().bits((reload >> 16) as u16));
7373
)*

src/timer/pwm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ macro_rules! pwm {
8888

8989
unsafe {
9090
self.tim.psc().write(|w| w.psc().bits(psc as u16));
91-
self.tim.arr().write(|w| w.$arr().bits(arr as u16));
91+
self.tim.arr().write(|w| w.$arr().bits((arr as u16).into()));
9292
$(
9393
self.tim.arr().modify(|_, w| w.$arr_h().bits((arr >> 16) as u16));
9494
)*

src/timer/qei.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ macro_rules! qei {
8383
type Count = u16;
8484

8585
fn count(&self) -> u16 {
86-
self.tim.cnt().read().$cnt().bits()
86+
self.tim.cnt().read().$cnt().bits() as u16
8787
}
8888

8989
fn direction(&self) -> Direction {

0 commit comments

Comments
 (0)