Skip to content

Commit 5e15dc7

Browse files
committed
Add all pin combinations I could find
Add warnings/comments on pins that are available on some models only
1 parent ddab525 commit 5e15dc7

File tree

2 files changed

+97
-65
lines changed

2 files changed

+97
-65
lines changed

src/i2c.rs

Lines changed: 95 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
//! as of 2021-02-25.
44
55
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
6-
use crate::pac::{i2c1, I2C1, I2C2, I2C3, I2C4};
6+
#[cfg(any(feature = "stm32l4x1", feature = "stm32l4x2", feature = "stm32l4x6"))]
7+
use crate::pac::I2C4;
8+
use crate::pac::{i2c1, I2C1, I2C2, I2C3};
9+
710
use crate::rcc::{Clocks, APB1R1};
811
use crate::time::Hertz;
912
use cast::{u16, u8};
@@ -144,13 +147,9 @@ macro_rules! hal {
144147

145148
hal!(I2C1, enr, rstr, i2c1, i2c1en, i2c1rst);
146149
hal!(I2C2, enr, rstr, i2c2, i2c2en, i2c2rst);
147-
148-
#[cfg(any(feature = "stm32l4x3", feature = "stm32l4x5", feature = "stm32l4x6"))]
149150
hal!(I2C3, enr, rstr, i2c3, i2c3en, i2c3rst);
150151

151-
// Warning: available on stm32l4x5 according to reference manual,
152-
// but stm32l475rc (only one available) does not have this peripheral listed,
153-
#[cfg(any(feature = "stm32l4x5", feature = "stm32l4x6"))]
152+
#[cfg(any(feature = "stm32l4x1", feature = "stm32l4x2", feature = "stm32l4x6"))]
154153
hal!(I2C4, enr2, rstr2, i2c4, i2c4en, i2c4rst);
155154

156155
impl<SCL, SDA, I2C> I2c<I2C, (SCL, SDA)>
@@ -475,78 +474,109 @@ where
475474
}
476475
}
477476

478-
/// **Warning**: A9 and A10 in AF4 don't have this function on stm32l471qe,
479-
/// but do on stm32l431cb and stm32l451cc
480-
mod i2c_pins_default {
481-
use super::{I2C1, I2C2};
482-
use crate::gpio::gpioa::{PA10, PA9};
483-
use crate::gpio::gpiob::{PB10, PB11, PB6, PB7};
484-
use crate::gpio::{Alternate, OpenDrain, Output, AF4};
477+
#[cfg(feature = "stm32l4x1")]
478+
mod stm32l4x1_pins {
479+
use super::{I2C1, I2C2, I2C3, I2C4};
480+
use crate::gpio::*;
481+
use gpioa::{PA10, PA7, PA9};
482+
use gpiob::{PB10, PB11, PB13, PB14, PB4, PB6, PB7, PB8, PB9};
483+
use gpioc::{PC0, PC1};
485484

486-
pins!(I2C1, AF4,
487-
SCL: [PA9, PB6],
488-
SDA: [PA10, PB7]);
485+
pins!(I2C1, AF4, SCL: [PB6, PB8], SDA: [PB7, PB9]);
489486

490-
pins!(I2C2, AF4, SCL: [PB10], SDA: [PB11]);
491-
}
487+
// Not on STM32L471xx
488+
pins!(I2C1, AF4, SCL: [PA9], SDA: [PA10]);
492489

493-
#[cfg(any(feature = "stm32l4x1", feature = "stm32l4x2", feature = "stm32l4x6"))]
494-
mod i2c_pins_pb8_pb9 {
495-
use super::{I2C1, I2C2};
496-
use crate::gpio::gpiob::{PB13, PB14, PB8, PB9};
497-
use crate::gpio::{Alternate, OpenDrain, Output, AF4};
490+
pins!(I2C2, AF4, SCL: [PB10, PB13], SDA: [PB11, PB14]);
491+
492+
pins!(I2C3, AF4, SCL: [PC0], SDA: [PC1]);
498493

499-
pins!(I2C1, AF4, SCL: [PB8], SDA: [PB9]);
500-
pins!(I2C2, AF4, SCL: [PB13], SDA: [PB14]);
494+
// Not on STM32L471xx
495+
pins!(I2C3, AF4, SCL: [PA7], SDA: [PB4]);
496+
497+
// Both only on STM32L451XX
498+
pins!(I2C4, AF4, SCL: [PD12], SDA: [PD13]);
499+
pins!(I2C4, AF3, SCL: [PB10], SDA: [PB11]);
501500
}
502501

503-
#[cfg(any(
504-
feature = "stm32l4x1",
505-
feature = "stm32l4x3",
506-
feature = "stm32l4x5",
507-
feature = "stm32l4x6"
508-
))]
509-
mod i2c_pins_pbc0_pc1 {
510-
use super::I2C3;
511-
use crate::gpio::gpioc::{PC0, PC1};
512-
use crate::gpio::{Alternate, OpenDrain, Output, AF4};
502+
#[cfg(feature = "stm32l4x2")]
503+
mod stm32l4x2_pins {
504+
use super::{I2C1, I2C2, I2C3, I2C4};
505+
use crate::gpio::*;
506+
use gpioa::{PA10, PA7, PA9};
507+
use gpiob::{PB10, PB11, PB13, PB14, PB4, PB6, PB7, PB8, PB9};
508+
use gpioc::{PC0, PC1};
509+
510+
pins!(I2C1, AF4, SCL: [PA9, PB6], SDA: [PA10, PB7]);
513511

512+
// Technically not present on STM32L432XX and STM32l442XX (pins missing from ref. manual)
513+
pins!(I2C2, AF4, SCL: [PB8, PB10, PB13], SDA: [PB9, PB11, PB14]);
514+
515+
pins!(I2C3, AF4, SCL: [PA7], SDA: [PB4]);
516+
517+
// Technically not present on STM32L432XX and STM32l442XX (pins missing from ref. manual)
514518
pins!(I2C3, AF4, SCL: [PC0], SDA: [PC1]);
519+
520+
// All three only on STM32l452XX and STM32l462XX
521+
pins!(I2C4, AF2, SCL: [PC0], SDA: [PC1]);
522+
pins!(I2C4, AF3, SCL: [PB10], SDA: [PB11]);
523+
pins!(I2C4, AF4, SCL: [PD12], SDA: [PD13]);
515524
}
516525

517-
/// **Warning**: PA7 and PB4 don't have this function on stm32l486jg and stm32l476je,
518-
/// but do on stm32l496ae and stm32l4a6ag
519-
///
520-
/// **Warning**: PA7 and PB4 don't have this function on stm32l471qe and stm32l475rc,
521-
/// but do on stm32l431cb and stm32l451cc
522-
#[cfg(any(
523-
feature = "stm32l4x1",
524-
feature = "stm32l4x2",
525-
feature = "stm32l4x3",
526-
feature = "stm32l4x6"
527-
))]
528-
mod i2c_pins_pa7_pb4 {
529-
use super::I2C3;
530-
use crate::gpio::gpioa::PA7;
531-
use crate::gpio::gpiob::PB4;
532-
use crate::gpio::{Alternate, OpenDrain, Output, AF4};
533-
534-
// These pins aren't as nicely consistent
535-
pins!(I2C3, AF4, SCL: [PA7], SDA: [PB4]);
526+
#[cfg(feature = "stm32l4x3")]
527+
mod stm32l4x3_pins {
528+
use super::{I2C1, I2C2, I2C3};
529+
use crate::gpio::*;
530+
use gpioa::{PA10, PA7, PA9};
531+
use gpiob::{PB10, PB11, PB13, PB14, PB4, PB6, PB7, PB8, PB9};
532+
use gpioc::{PC0, PC1};
533+
534+
pins!(I2C1, AF4, SCL: [PA9, PB6, PB8], SDA: [PA10, PB7, PB9]);
535+
536+
pins!(I2C2, AF4, SCL: [PB10, PB13], SDA: [PB11, PB14]);
537+
538+
pins!(I2C3, AF4, SCL: [PA7, PC0], SDA: [PB4, PC1]);
539+
}
540+
541+
#[cfg(feature = "stm32l4x5")]
542+
mod stm32l4x5_pins {
543+
use super::{I2C1, I2C2, I2C3};
544+
use crate::gpio::*;
545+
use gpiob::{PB10, PB11, PB13, PB14, PB6, PB7, PB8, PB9};
546+
use gpioc::{PC0, PC1};
547+
548+
pins!(I2C1, AF4, SCL: [PB6, PB8], SDA: [PB7, PB9]);
549+
550+
pins!(I2C2, AF4, SCL: [PB10, PB13], SDA: [PB11, PB14]);
551+
552+
pins!(I2C3, AF4, SCL: [PC0], SDA: [PC1]);
536553
}
537554

538-
/// **Warning**: these pins don't have this function on stm32l486jg and stm32l476je,
539-
/// but do on stm32l496ae and stm32l4a6ag
540555
#[cfg(feature = "stm32l4x6")]
541-
mod i2c_pins_pd12_pd13_pf0_pf1_pf14_pf15 {
542-
use super::{I2C2, I2C4};
543-
use crate::gpio::gpiod::{PD12, PD13};
544-
use crate::gpio::gpiof::{PF0, PF1, PF14, PF15};
545-
use crate::gpio::{Alternate, OpenDrain, Output, AF4};
556+
mod stm32l4x6_pins {
557+
use super::{I2C1, I2C2, I2C3, I2C4};
558+
use crate::gpio::*;
559+
use gpioa::PA7;
560+
use gpiob::{PB10, PB11, PB13, PB14, PB4, PB6, PB7, PB8, PB9};
561+
use gpioc::{PC0, PC1};
562+
use gpiod::{PD12, PD13};
563+
use gpiof::{PF0, PF1, PF14, PF15};
564+
use gpiog::{PG13, PG14, PG7, PG8};
546565

547-
// SCL and SDA are "reversed", correct according to reference manual
548-
pins!(I2C2, AF4, SCL: [PF1], SDA: [PF0]);
566+
pins!(I2C1, AF4, SCL: [PB6, PB8], SDA: [PB7, PB9]);
549567

550-
pins!(I2C4, AF4, SCL: [PD12], SDA: [PD13]);
551-
pins!(I2C4, AF4, SCL: [PF14], SDA: [PF15]);
568+
pins!(I2C2, AF4, SCL: [PB10, PB13, PF1], SDA: [PB11, PB14, PF0]);
569+
570+
pins!(I2C3, AF4, SCL: [PC0, PG7, PG14], SDA: [PC1, PG8, PG13]);
571+
572+
// Both not on STM32L486XX and STM32L476XX
573+
pins!(I2C3, AF4, SCL: [PA7], SDA: [PB4]);
574+
pins!(I2C4, AF4, SCL: [PD12, PF14], SDA: [PD13, PF15]);
575+
576+
// These are present on STM32L496XX and STM32L4A6xG, but the
577+
// PAC does not have gpioh, so we can't actually these pins
578+
// Both not on STM32L486XX and STM32L476XX
579+
// use gpioh::{PH4, PH5, PH7, PH8};
580+
// pins!(I2C2, AF4, SCL: [PH4], SDA: [PH5]);
581+
// pins!(I2C3, AF4, SCL: [PH7], SDA: [PH8]);
552582
}

src/rcc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,13 @@ impl APB1R1 {
256256
unsafe { &(*RCC::ptr()).apb1rstr1 }
257257
}
258258

259+
#[cfg(not(any(feature = "stm32l4x3", feature = "stm32l4x5")))]
259260
pub(crate) fn enr2(&mut self) -> &rcc::APB1ENR2 {
260261
// NOTE(unsafe) this proxy grants exclusive access to this register
261262
unsafe { &(*RCC::ptr()).apb1enr2 }
262263
}
263264

265+
#[cfg(not(any(feature = "stm32l4x3", feature = "stm32l4x5")))]
264266
pub(crate) fn rstr2(&mut self) -> &rcc::APB1RSTR2 {
265267
// NOTE(unsafe) this proxy grants exclusive access to this register
266268
unsafe { &(*RCC::ptr()).apb1rstr2 }

0 commit comments

Comments
 (0)