Skip to content

Commit 78b252a

Browse files
Fix the rustc crash and other things
1 parent 14aab2a commit 78b252a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/spi.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ use nb;
66
pub use embedded_hal::spi::{Mode, Phase, Polarity};
77

88
use crate::stm32;
9+
// TODO Put this inside the macro
10+
// Currently that causes a compiler panic
911
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
10-
use crate::stm32::{RCC, SPI1};
12+
use crate::stm32::SPI1;
13+
#[cfg(any(feature = "stm32f030x8", feature = "stm32f030xc"))]
14+
use crate::stm32::SPI2;
1115

1216
use crate::gpio::*;
1317
use crate::rcc::Clocks;
@@ -74,10 +78,9 @@ spi_pins! {
7478
}
7579

7680
macro_rules! spi {
77-
($($SPI:ident: ($spi:ident, $spiXen:ident, $spiXrst:ident, $apbrstr:ident, $apbenr:ident),)+) => {
81+
($($SPI:ident: ($spi:ident, $spiXen:ident, $spiXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
7882
$(
79-
use crate::stm32::$SPI;
80-
impl<SCKPIN, MISOPIN, MOSIPIN> Spi<SPI1, SCKPIN, MISOPIN, MOSIPIN> {
83+
impl<SCKPIN, MISOPIN, MOSIPIN> Spi<$SPI, SCKPIN, MISOPIN, MOSIPIN> {
8184
pub fn $spi<F>(
8285
spi: $SPI,
8386
pins: (SCKPIN, MISOPIN, MOSIPIN),
@@ -92,12 +95,12 @@ macro_rules! spi {
9295
F: Into<Hertz>,
9396
{
9497
// NOTE(unsafe) This executes only during initialisation
95-
let rcc = unsafe { &(*RCC::ptr()) };
98+
let rcc = unsafe { &(*stm32::RCC::ptr()) };
9699

97-
/* Enable clock for SPI1 */
100+
/* Enable clock for SPI */
98101
rcc.$apbenr.modify(|_, w| w.$spiXen().set_bit());
99102

100-
/* Reset SPI1 */
103+
/* Reset SPI */
101104
rcc.$apbrstr.modify(|_, w| w.$spiXrst().set_bit());
102105
rcc.$apbrstr.modify(|_, w| w.$spiXrst().clear_bit());
103106
Spi { spi, pins }.spi_init(mode, speed, clocks)
@@ -106,6 +109,7 @@ macro_rules! spi {
106109
)+
107110
}
108111
}
112+
109113
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
110114
spi! {
111115
SPI1: (spi1, spi1en, spi1rst, apb2enr, apb2rstr),

0 commit comments

Comments
 (0)