1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use stm32f4xx_hal as p_hal;
use p_hal::stm32 as pac;
use p_hal::stm32::I2C1;
use p_hal::gpio::GpioExt;
use p_hal::rcc::RccExt;
use p_hal::time::U32Ext;
pub fn setup_peripherals() -> (
UserLed1Type,
DelaySourceType,
I2c1PortType,
Spi1PortType,
ChipSelectPinType,
) {
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();
let clocks = rcc
.cfgr
.use_hse(25.mhz())
.sysclk(84.mhz())
.pclk1(48.mhz())
.pclk2(48.mhz())
.freeze();
let delay_source = p_hal::delay::Delay::new(cp.SYST, clocks);
let gpioa = dp.GPIOA.split();
let gpiob = dp.GPIOB.split();
let gpioc = dp.GPIOC.split();
let user_led1 = gpioc.pc13.into_push_pull_output();
let i2c1_port = {
let scl = gpiob
.pb8
.into_alternate_af4()
.internal_pull_up(true)
.set_open_drain();
let sda = gpiob
.pb9
.into_alternate_af4()
.internal_pull_up(true)
.set_open_drain();
p_hal::i2c::I2c::i2c1(dp.I2C1, (scl, sda), 400.khz(), clocks)
};
let spi1_port = {
let sck = gpioa.pa5.into_alternate_af5();
let miso = gpioa.pa6.into_alternate_af5();
let mosi = gpioa.pa7.into_alternate_af5();
p_hal::spi::Spi::spi1(
dp.SPI1,
(sck, miso, mosi),
embedded_hal::spi::MODE_0,
3_000_000.hz(),
clocks,
)
};
let spi_csn = gpioa.pa15.into_open_drain_output();
(user_led1, delay_source, i2c1_port, spi1_port, spi_csn)
}
pub type I2c1PortType = p_hal::i2c::I2c<
I2C1,
(
p_hal::gpio::gpiob::PB8<p_hal::gpio::AlternateOD<p_hal::gpio::AF4>>,
p_hal::gpio::gpiob::PB9<p_hal::gpio::AlternateOD<p_hal::gpio::AF4>>,
),
>;
pub type Spi1PortType = p_hal::spi::Spi<
pac::SPI1,
(
p_hal::gpio::gpioa::PA5<p_hal::gpio::Alternate<p_hal::gpio::AF5>>,
p_hal::gpio::gpioa::PA6<p_hal::gpio::Alternate<p_hal::gpio::AF5>>,
p_hal::gpio::gpioa::PA7<p_hal::gpio::Alternate<p_hal::gpio::AF5>>,
),
>;
pub type ChipSelectPinType =
p_hal::gpio::gpioa::PA15<p_hal::gpio::Output<p_hal::gpio::OpenDrain>>;
pub type UserLed1Type =
p_hal::gpio::gpioc::PC13<p_hal::gpio::Output<p_hal::gpio::PushPull>>;
pub type DelaySourceType = p_hal::delay::Delay;