aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-08-25 06:05:41 +0000
committerGitHub <[email protected]>2024-08-25 06:05:41 +0000
commit1cfd5370ac012814b7b386ba9ad8499529bdde4e (patch)
treea19c6713ed3ca680e361ed18c0baf061bf72749b
parentf4c7ec746282e762f651f9544d120af483f8e7d5 (diff)
parent557cff708505eb02c2b4c7f264a726bb9c17812a (diff)
Merge pull request #3281 from elagil/ulpi_add_fs_support
feat: Add support for a full-speed ULPI mode
-rw-r--r--embassy-stm32/src/usb/otg.rs49
-rw-r--r--embassy-usb-synopsys-otg/src/lib.rs7
2 files changed, 54 insertions, 2 deletions
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs
index 8ee8dcc36..e27b164e4 100644
--- a/embassy-stm32/src/usb/otg.rs
+++ b/embassy-stm32/src/usb/otg.rs
@@ -97,6 +97,55 @@ impl<'d, T: Instance> Driver<'d, T> {
97 } 97 }
98 } 98 }
99 99
100 /// Initializes USB OTG peripheral with external Full-speed PHY (usually, a High-speed PHY in Full-speed mode).
101 ///
102 /// # Arguments
103 ///
104 /// * `ep_out_buffer` - An internal buffer used to temporarily store received packets.
105 /// Must be large enough to fit all OUT endpoint max packet sizes.
106 /// Endpoint allocation will fail if it is too small.
107 pub fn new_fs_ulpi(
108 _peri: impl Peripheral<P = T> + 'd,
109 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
110 ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd,
111 ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd,
112 ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd,
113 ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd,
114 ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd,
115 ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd,
116 ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd,
117 ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd,
118 ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd,
119 ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd,
120 ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd,
121 ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd,
122 ep_out_buffer: &'d mut [u8],
123 config: Config,
124 ) -> Self {
125 config_ulpi_pins!(
126 ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6,
127 ulpi_d7
128 );
129
130 let regs = T::regs();
131
132 let instance = OtgInstance {
133 regs: T::regs(),
134 state: T::state(),
135 fifo_depth_words: T::FIFO_DEPTH_WORDS,
136 extra_rx_fifo_words: RX_FIFO_EXTRA_SIZE_WORDS,
137 endpoint_count: T::ENDPOINT_COUNT,
138 phy_type: PhyType::ExternalFullSpeed,
139 quirk_setup_late_cnak: quirk_setup_late_cnak(regs),
140 calculate_trdt_fn: calculate_trdt::<T>,
141 };
142
143 Self {
144 inner: OtgDriver::new(ep_out_buffer, instance, config),
145 phantom: PhantomData,
146 }
147 }
148
100 /// Initializes USB OTG peripheral with external High-Speed PHY. 149 /// Initializes USB OTG peripheral with external High-Speed PHY.
101 /// 150 ///
102 /// # Arguments 151 /// # Arguments
diff --git a/embassy-usb-synopsys-otg/src/lib.rs b/embassy-usb-synopsys-otg/src/lib.rs
index f155f1522..5fb82db42 100644
--- a/embassy-usb-synopsys-otg/src/lib.rs
+++ b/embassy-usb-synopsys-otg/src/lib.rs
@@ -179,6 +179,8 @@ pub enum PhyType {
179 /// 179 ///
180 /// Available on a few STM32 chips. 180 /// Available on a few STM32 chips.
181 InternalHighSpeed, 181 InternalHighSpeed,
182 /// External ULPI Full-Speed PHY (or High-Speed PHY in Full-Speed mode)
183 ExternalFullSpeed,
182 /// External ULPI High-Speed PHY 184 /// External ULPI High-Speed PHY
183 ExternalHighSpeed, 185 ExternalHighSpeed,
184} 186}
@@ -188,14 +190,14 @@ impl PhyType {
188 pub fn internal(&self) -> bool { 190 pub fn internal(&self) -> bool {
189 match self { 191 match self {
190 PhyType::InternalFullSpeed | PhyType::InternalHighSpeed => true, 192 PhyType::InternalFullSpeed | PhyType::InternalHighSpeed => true,
191 PhyType::ExternalHighSpeed => false, 193 PhyType::ExternalHighSpeed | PhyType::ExternalFullSpeed => false,
192 } 194 }
193 } 195 }
194 196
195 /// Get whether this PHY is any of the high-speed types. 197 /// Get whether this PHY is any of the high-speed types.
196 pub fn high_speed(&self) -> bool { 198 pub fn high_speed(&self) -> bool {
197 match self { 199 match self {
198 PhyType::InternalFullSpeed => false, 200 PhyType::InternalFullSpeed | PhyType::ExternalFullSpeed => false,
199 PhyType::ExternalHighSpeed | PhyType::InternalHighSpeed => true, 201 PhyType::ExternalHighSpeed | PhyType::InternalHighSpeed => true,
200 } 202 }
201 } 203 }
@@ -204,6 +206,7 @@ impl PhyType {
204 match self { 206 match self {
205 PhyType::InternalFullSpeed => vals::Dspd::FULL_SPEED_INTERNAL, 207 PhyType::InternalFullSpeed => vals::Dspd::FULL_SPEED_INTERNAL,
206 PhyType::InternalHighSpeed => vals::Dspd::HIGH_SPEED, 208 PhyType::InternalHighSpeed => vals::Dspd::HIGH_SPEED,
209 PhyType::ExternalFullSpeed => vals::Dspd::FULL_SPEED_EXTERNAL,
207 PhyType::ExternalHighSpeed => vals::Dspd::HIGH_SPEED, 210 PhyType::ExternalHighSpeed => vals::Dspd::HIGH_SPEED,
208 } 211 }
209 } 212 }