aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-01-11 17:51:30 +0100
committerDario Nieuwenhuis <[email protected]>2023-01-11 17:51:30 +0100
commit065a0a1ee71c3e4333f2e38140e9ca86b61b59d2 (patch)
treeb81dc9656f035f096387c9e796355c38f36c5461
parentce842fe28c27e6f57a05efc92bc417f6f7d7af64 (diff)
Update stm32-data.
-rw-r--r--embassy-stm32/build.rs30
-rw-r--r--embassy-stm32/src/lib.rs2
-rw-r--r--embassy-stm32/src/usb/usb.rs1
-rw-r--r--embassy-stm32/src/usb_otg.rs213
-rw-r--r--embassy-stm32/src/usb_otg/mod.rs138
m---------stm32-data0
6 files changed, 154 insertions, 230 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index ddfa97b29..dbfc1370d 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -277,22 +277,20 @@ fn main() {
277 (("dcmi", "PIXCLK"), quote!(crate::dcmi::PixClkPin)), 277 (("dcmi", "PIXCLK"), quote!(crate::dcmi::PixClkPin)),
278 (("usb", "DP"), quote!(crate::usb::DpPin)), 278 (("usb", "DP"), quote!(crate::usb::DpPin)),
279 (("usb", "DM"), quote!(crate::usb::DmPin)), 279 (("usb", "DM"), quote!(crate::usb::DmPin)),
280 (("otgfs", "DP"), quote!(crate::usb_otg::DpPin)), 280 (("otg", "DP"), quote!(crate::usb_otg::DpPin)),
281 (("otgfs", "DM"), quote!(crate::usb_otg::DmPin)), 281 (("otg", "DM"), quote!(crate::usb_otg::DmPin)),
282 (("otghs", "DP"), quote!(crate::usb_otg::DpPin)), 282 (("otg", "ULPI_CK"), quote!(crate::usb_otg::UlpiClkPin)),
283 (("otghs", "DM"), quote!(crate::usb_otg::DmPin)), 283 (("otg", "ULPI_DIR"), quote!(crate::usb_otg::UlpiDirPin)),
284 (("otghs", "ULPI_CK"), quote!(crate::usb_otg::UlpiClkPin)), 284 (("otg", "ULPI_NXT"), quote!(crate::usb_otg::UlpiNxtPin)),
285 (("otghs", "ULPI_DIR"), quote!(crate::usb_otg::UlpiDirPin)), 285 (("otg", "ULPI_STP"), quote!(crate::usb_otg::UlpiStpPin)),
286 (("otghs", "ULPI_NXT"), quote!(crate::usb_otg::UlpiNxtPin)), 286 (("otg", "ULPI_D0"), quote!(crate::usb_otg::UlpiD0Pin)),
287 (("otghs", "ULPI_STP"), quote!(crate::usb_otg::UlpiStpPin)), 287 (("otg", "ULPI_D1"), quote!(crate::usb_otg::UlpiD1Pin)),
288 (("otghs", "ULPI_D0"), quote!(crate::usb_otg::UlpiD0Pin)), 288 (("otg", "ULPI_D2"), quote!(crate::usb_otg::UlpiD2Pin)),
289 (("otghs", "ULPI_D1"), quote!(crate::usb_otg::UlpiD1Pin)), 289 (("otg", "ULPI_D3"), quote!(crate::usb_otg::UlpiD3Pin)),
290 (("otghs", "ULPI_D2"), quote!(crate::usb_otg::UlpiD2Pin)), 290 (("otg", "ULPI_D4"), quote!(crate::usb_otg::UlpiD4Pin)),
291 (("otghs", "ULPI_D3"), quote!(crate::usb_otg::UlpiD3Pin)), 291 (("otg", "ULPI_D5"), quote!(crate::usb_otg::UlpiD5Pin)),
292 (("otghs", "ULPI_D4"), quote!(crate::usb_otg::UlpiD4Pin)), 292 (("otg", "ULPI_D6"), quote!(crate::usb_otg::UlpiD6Pin)),
293 (("otghs", "ULPI_D5"), quote!(crate::usb_otg::UlpiD5Pin)), 293 (("otg", "ULPI_D7"), quote!(crate::usb_otg::UlpiD7Pin)),
294 (("otghs", "ULPI_D6"), quote!(crate::usb_otg::UlpiD6Pin)),
295 (("otghs", "ULPI_D7"), quote!(crate::usb_otg::UlpiD7Pin)),
296 (("can", "TX"), quote!(crate::can::TxPin)), 294 (("can", "TX"), quote!(crate::can::TxPin)),
297 (("can", "RX"), quote!(crate::can::RxPin)), 295 (("can", "RX"), quote!(crate::can::RxPin)),
298 (("eth", "REF_CLK"), quote!(crate::eth::RefClkPin)), 296 (("eth", "REF_CLK"), quote!(crate::eth::RefClkPin)),
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 16c46ca22..610c24888 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -58,7 +58,7 @@ pub mod spi;
58pub mod usart; 58pub mod usart;
59#[cfg(all(usb, feature = "time"))] 59#[cfg(all(usb, feature = "time"))]
60pub mod usb; 60pub mod usb;
61#[cfg(any(otgfs, otghs))] 61#[cfg(otg)]
62pub mod usb_otg; 62pub mod usb_otg;
63 63
64#[cfg(iwdg)] 64#[cfg(iwdg)]
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index 062c7ef77..03e792a21 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -154,6 +154,7 @@ impl<'d, T: Instance> Driver<'d, T> {
154 154
155 block_for(Duration::from_millis(100)); 155 block_for(Duration::from_millis(100));
156 156
157 #[cfg(not(usb_v4))]
157 regs.btable().write(|w| w.set_btable(0)); 158 regs.btable().write(|w| w.set_btable(0));
158 159
159 dp.set_as_af(dp.af_num(), AFType::OutputPushPull); 160 dp.set_as_af(dp.af_num(), AFType::OutputPushPull);
diff --git a/embassy-stm32/src/usb_otg.rs b/embassy-stm32/src/usb_otg.rs
deleted file mode 100644
index f7faf12a8..000000000
--- a/embassy-stm32/src/usb_otg.rs
+++ /dev/null
@@ -1,213 +0,0 @@
1use core::marker::PhantomData;
2
3use embassy_hal_common::into_ref;
4
5use crate::gpio::sealed::AFType;
6use crate::rcc::RccPeripheral;
7use crate::{peripherals, Peripheral};
8
9macro_rules! config_ulpi_pins {
10 ($($pin:ident),*) => {
11 into_ref!($($pin),*);
12 // NOTE(unsafe) Exclusive access to the registers
13 critical_section::with(|_| unsafe {
14 $(
15 $pin.set_as_af($pin.af_num(), AFType::OutputPushPull);
16 #[cfg(gpio_v2)]
17 $pin.set_speed(crate::gpio::Speed::VeryHigh);
18 )*
19 })
20 };
21}
22
23/// USB PHY type
24#[derive(Copy, Clone, Debug, Eq, PartialEq)]
25pub enum PhyType {
26 /// Internal Full-Speed PHY
27 ///
28 /// Available on most High-Speed peripherals.
29 InternalFullSpeed,
30 /// Internal High-Speed PHY
31 ///
32 /// Available on a few STM32 chips.
33 InternalHighSpeed,
34 /// External ULPI High-Speed PHY
35 ExternalHighSpeed,
36}
37
38pub struct UsbOtg<'d, T: Instance> {
39 phantom: PhantomData<&'d mut T>,
40 _phy_type: PhyType,
41}
42
43impl<'d, T: Instance> UsbOtg<'d, T> {
44 /// Initializes USB OTG peripheral with internal Full-Speed PHY
45 pub fn new_fs(
46 _peri: impl Peripheral<P = T> + 'd,
47 dp: impl Peripheral<P = impl DpPin<T>> + 'd,
48 dm: impl Peripheral<P = impl DmPin<T>> + 'd,
49 ) -> Self {
50 into_ref!(dp, dm);
51
52 unsafe {
53 dp.set_as_af(dp.af_num(), AFType::OutputPushPull);
54 dm.set_as_af(dm.af_num(), AFType::OutputPushPull);
55 }
56
57 Self {
58 phantom: PhantomData,
59 _phy_type: PhyType::InternalFullSpeed,
60 }
61 }
62
63 /// Initializes USB OTG peripheral with external High-Speed PHY
64 pub fn new_hs_ulpi(
65 _peri: impl Peripheral<P = T> + 'd,
66 ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd,
67 ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd,
68 ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd,
69 ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd,
70 ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd,
71 ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd,
72 ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd,
73 ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd,
74 ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd,
75 ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd,
76 ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd,
77 ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd,
78 ) -> Self {
79 config_ulpi_pins!(
80 ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6,
81 ulpi_d7
82 );
83
84 Self {
85 phantom: PhantomData,
86 _phy_type: PhyType::ExternalHighSpeed,
87 }
88 }
89}
90
91impl<'d, T: Instance> Drop for UsbOtg<'d, T> {
92 fn drop(&mut self) {
93 T::reset();
94 T::disable();
95 }
96}
97
98pub(crate) mod sealed {
99 pub trait Instance {
100 const REGISTERS: *const ();
101 const HIGH_SPEED: bool;
102 const FIFO_DEPTH_WORDS: usize;
103 const ENDPOINT_COUNT: usize;
104 }
105}
106
107pub trait Instance: sealed::Instance + RccPeripheral {}
108
109// Internal PHY pins
110pin_trait!(DpPin, Instance);
111pin_trait!(DmPin, Instance);
112
113// External PHY pins
114pin_trait!(UlpiClkPin, Instance);
115pin_trait!(UlpiDirPin, Instance);
116pin_trait!(UlpiNxtPin, Instance);
117pin_trait!(UlpiStpPin, Instance);
118pin_trait!(UlpiD0Pin, Instance);
119pin_trait!(UlpiD1Pin, Instance);
120pin_trait!(UlpiD2Pin, Instance);
121pin_trait!(UlpiD3Pin, Instance);
122pin_trait!(UlpiD4Pin, Instance);
123pin_trait!(UlpiD5Pin, Instance);
124pin_trait!(UlpiD6Pin, Instance);
125pin_trait!(UlpiD7Pin, Instance);
126
127foreach_peripheral!(
128 (otgfs, $inst:ident) => {
129 impl sealed::Instance for peripherals::$inst {
130 const REGISTERS: *const () = crate::pac::$inst.0 as *const ();
131 const HIGH_SPEED: bool = false;
132
133 cfg_if::cfg_if! {
134 if #[cfg(stm32f1)] {
135 const FIFO_DEPTH_WORDS: usize = 128;
136 const ENDPOINT_COUNT: usize = 8;
137 } else if #[cfg(any(
138 stm32f2,
139 stm32f401,
140 stm32f405,
141 stm32f407,
142 stm32f411,
143 stm32f415,
144 stm32f417,
145 stm32f427,
146 stm32f429,
147 stm32f437,
148 stm32f439,
149 ))] {
150 const FIFO_DEPTH_WORDS: usize = 320;
151 const ENDPOINT_COUNT: usize = 4;
152 } else if #[cfg(any(
153 stm32f412,
154 stm32f413,
155 stm32f423,
156 stm32f446,
157 stm32f469,
158 stm32f479,
159 stm32f7,
160 stm32l4,
161 stm32u5,
162 ))] {
163 const FIFO_DEPTH_WORDS: usize = 320;
164 const ENDPOINT_COUNT: usize = 6;
165 } else if #[cfg(stm32g0x1)] {
166 const FIFO_DEPTH_WORDS: usize = 512;
167 const ENDPOINT_COUNT: usize = 8;
168 } else {
169 compile_error!("USB_OTG_FS peripheral is not supported by this chip.");
170 }
171 }
172 }
173
174 impl Instance for peripherals::$inst {}
175 };
176
177 (otghs, $inst:ident) => {
178 impl sealed::Instance for peripherals::$inst {
179 const REGISTERS: *const () = crate::pac::$inst.0 as *const ();
180 const HIGH_SPEED: bool = true;
181
182 cfg_if::cfg_if! {
183 if #[cfg(any(
184 stm32f2,
185 stm32f405,
186 stm32f407,
187 stm32f415,
188 stm32f417,
189 stm32f427,
190 stm32f429,
191 stm32f437,
192 stm32f439,
193 ))] {
194 const FIFO_DEPTH_WORDS: usize = 1024;
195 const ENDPOINT_COUNT: usize = 6;
196 } else if #[cfg(any(
197 stm32f446,
198 stm32f469,
199 stm32f479,
200 stm32f7,
201 stm32h7,
202 ))] {
203 const FIFO_DEPTH_WORDS: usize = 1024;
204 const ENDPOINT_COUNT: usize = 9;
205 } else {
206 compile_error!("USB_OTG_HS peripheral is not supported by this chip.");
207 }
208 }
209 }
210
211 impl Instance for peripherals::$inst {}
212 };
213);
diff --git a/embassy-stm32/src/usb_otg/mod.rs b/embassy-stm32/src/usb_otg/mod.rs
new file mode 100644
index 000000000..2ee2891df
--- /dev/null
+++ b/embassy-stm32/src/usb_otg/mod.rs
@@ -0,0 +1,138 @@
1use embassy_cortex_m::interrupt::Interrupt;
2
3use crate::peripherals;
4use crate::rcc::RccPeripheral;
5
6pub(crate) mod sealed {
7 pub trait Instance {
8 const HIGH_SPEED: bool;
9 const FIFO_DEPTH_WORDS: u16;
10 const ENDPOINT_COUNT: usize;
11
12 fn regs() -> crate::pac::otg::Otg;
13 }
14}
15
16pub trait Instance: sealed::Instance + RccPeripheral {
17 type Interrupt: Interrupt;
18}
19
20// Internal PHY pins
21pin_trait!(DpPin, Instance);
22pin_trait!(DmPin, Instance);
23
24// External PHY pins
25pin_trait!(UlpiClkPin, Instance);
26pin_trait!(UlpiDirPin, Instance);
27pin_trait!(UlpiNxtPin, Instance);
28pin_trait!(UlpiStpPin, Instance);
29pin_trait!(UlpiD0Pin, Instance);
30pin_trait!(UlpiD1Pin, Instance);
31pin_trait!(UlpiD2Pin, Instance);
32pin_trait!(UlpiD3Pin, Instance);
33pin_trait!(UlpiD4Pin, Instance);
34pin_trait!(UlpiD5Pin, Instance);
35pin_trait!(UlpiD6Pin, Instance);
36pin_trait!(UlpiD7Pin, Instance);
37
38foreach_interrupt!(
39 (USB_OTG_FS, otg, $block:ident, GLOBAL, $irq:ident) => {
40 impl sealed::Instance for peripherals::USB_OTG_FS {
41 const HIGH_SPEED: bool = false;
42
43 cfg_if::cfg_if! {
44 if #[cfg(stm32f1)] {
45 const FIFO_DEPTH_WORDS: u16 = 128;
46 const ENDPOINT_COUNT: usize = 8;
47 } else if #[cfg(any(
48 stm32f2,
49 stm32f401,
50 stm32f405,
51 stm32f407,
52 stm32f411,
53 stm32f415,
54 stm32f417,
55 stm32f427,
56 stm32f429,
57 stm32f437,
58 stm32f439,
59 ))] {
60 const FIFO_DEPTH_WORDS: u16 = 320;
61 const ENDPOINT_COUNT: usize = 4;
62 } else if #[cfg(any(
63 stm32f412,
64 stm32f413,
65 stm32f423,
66 stm32f446,
67 stm32f469,
68 stm32f479,
69 stm32f7,
70 stm32l4,
71 stm32u5,
72 ))] {
73 const FIFO_DEPTH_WORDS: u16 = 320;
74 const ENDPOINT_COUNT: usize = 6;
75 } else if #[cfg(stm32g0x1)] {
76 const FIFO_DEPTH_WORDS: u16 = 512;
77 const ENDPOINT_COUNT: usize = 8;
78 } else if #[cfg(stm32h7)] {
79 const FIFO_DEPTH_WORDS: u16 = 1024;
80 const ENDPOINT_COUNT: usize = 9;
81 } else {
82 compile_error!("USB_OTG_FS peripheral is not supported by this chip.");
83 }
84 }
85
86 fn regs() -> crate::pac::otg::Otg {
87 crate::pac::USB_OTG_FS
88 }
89 }
90
91 impl Instance for peripherals::USB_OTG_FS {
92 type Interrupt = crate::interrupt::$irq;
93 }
94 };
95
96 (USB_OTG_HS, otg, $block:ident, GLOBAL, $irq:ident) => {
97 impl sealed::Instance for peripherals::USB_OTG_HS {
98 const HIGH_SPEED: bool = true;
99
100 cfg_if::cfg_if! {
101 if #[cfg(any(
102 stm32f2,
103 stm32f405,
104 stm32f407,
105 stm32f415,
106 stm32f417,
107 stm32f427,
108 stm32f429,
109 stm32f437,
110 stm32f439,
111 ))] {
112 const FIFO_DEPTH_WORDS: u16 = 1024;
113 const ENDPOINT_COUNT: usize = 6;
114 } else if #[cfg(any(
115 stm32f446,
116 stm32f469,
117 stm32f479,
118 stm32f7,
119 stm32h7,
120 ))] {
121 const FIFO_DEPTH_WORDS: u16 = 1024;
122 const ENDPOINT_COUNT: usize = 9;
123 } else {
124 compile_error!("USB_OTG_HS peripheral is not supported by this chip.");
125 }
126 }
127
128 fn regs() -> crate::pac::otg::Otg {
129 // OTG HS registers are a superset of FS registers
130 crate::pac::otg::Otg(crate::pac::USB_OTG_HS.0)
131 }
132 }
133
134 impl Instance for peripherals::USB_OTG_HS {
135 type Interrupt = crate::interrupt::$irq;
136 }
137 };
138);
diff --git a/stm32-data b/stm32-data
Subproject 14a448c318192fe9da1c95a4de1beb4ec4892f1 Subproject 844793fc3da2ba3f12ab6a69b78cd8e6fb5497b