aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuliDi <[email protected]>2023-09-05 19:06:50 +0200
committerJuliDi <[email protected]>2023-10-02 09:30:58 +0200
commit81da9ca6215ff156f1055762f47efce6fc03d004 (patch)
tree212bcb70a8645dfee8f8aa23562a8b85f8514b08
parent729338875ccb1acd9f991dd2fec47ed33a66e415 (diff)
Bump stm32-metapac, add flash selection
-rw-r--r--embassy-stm32/src/qspi/enums.rs16
-rw-r--r--embassy-stm32/src/qspi/mod.rs44
2 files changed, 51 insertions, 9 deletions
diff --git a/embassy-stm32/src/qspi/enums.rs b/embassy-stm32/src/qspi/enums.rs
index 2dbe2b061..0412d991a 100644
--- a/embassy-stm32/src/qspi/enums.rs
+++ b/embassy-stm32/src/qspi/enums.rs
@@ -38,6 +38,22 @@ impl Into<u8> for QspiWidth {
38 } 38 }
39} 39}
40 40
41#[allow(dead_code)]
42#[derive(Copy, Clone)]
43pub enum FlashSelection {
44 Flash1,
45 Flash2,
46}
47
48impl Into<bool> for FlashSelection {
49 fn into(self) -> bool {
50 match self {
51 FlashSelection::Flash1 => false,
52 FlashSelection::Flash2 => true,
53 }
54 }
55}
56
41#[derive(Copy, Clone)] 57#[derive(Copy, Clone)]
42pub enum MemorySize { 58pub enum MemorySize {
43 _1KiB, 59 _1KiB,
diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs
index 9ca40f8f7..641315063 100644
--- a/embassy-stm32/src/qspi/mod.rs
+++ b/embassy-stm32/src/qspi/mod.rs
@@ -4,6 +4,7 @@ pub mod enums;
4 4
5use embassy_hal_internal::{into_ref, PeripheralRef}; 5use embassy_hal_internal::{into_ref, PeripheralRef};
6use enums::*; 6use enums::*;
7use stm32_metapac::quadspi::regs::Cr;
7 8
8use crate::dma::Transfer; 9use crate::dma::Transfer;
9use crate::gpio::sealed::AFType; 10use crate::gpio::sealed::AFType;
@@ -119,6 +120,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
119 Some(nss.map_into()), 120 Some(nss.map_into()),
120 dma, 121 dma,
121 config, 122 config,
123 FlashSelection::Flash2,
122 ) 124 )
123 } 125 }
124 126
@@ -139,13 +141,13 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
139 sck.set_speed(crate::gpio::Speed::VeryHigh); 141 sck.set_speed(crate::gpio::Speed::VeryHigh);
140 nss.set_as_af(nss.af_num(), AFType::OutputPushPull); 142 nss.set_as_af(nss.af_num(), AFType::OutputPushPull);
141 nss.set_speed(crate::gpio::Speed::VeryHigh); 143 nss.set_speed(crate::gpio::Speed::VeryHigh);
142 d0.set_as_af(d0.af_num(), AFType::OutputPushPull); 144 d0.set_as_af(d0.af_num(), AFType::OutputOpenDrain);
143 d0.set_speed(crate::gpio::Speed::VeryHigh); 145 d0.set_speed(crate::gpio::Speed::VeryHigh);
144 d1.set_as_af(d1.af_num(), AFType::OutputPushPull); 146 d1.set_as_af(d1.af_num(), AFType::OutputOpenDrain);
145 d1.set_speed(crate::gpio::Speed::VeryHigh); 147 d1.set_speed(crate::gpio::Speed::VeryHigh);
146 d2.set_as_af(d2.af_num(), AFType::OutputPushPull); 148 d2.set_as_af(d2.af_num(), AFType::OutputOpenDrain);
147 d2.set_speed(crate::gpio::Speed::VeryHigh); 149 d2.set_speed(crate::gpio::Speed::VeryHigh);
148 d3.set_as_af(d3.af_num(), AFType::OutputPushPull); 150 d3.set_as_af(d3.af_num(), AFType::OutputOpenDrain);
149 d3.set_speed(crate::gpio::Speed::VeryHigh); 151 d3.set_speed(crate::gpio::Speed::VeryHigh);
150 152
151 Self::new_inner( 153 Self::new_inner(
@@ -158,6 +160,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
158 Some(nss.map_into()), 160 Some(nss.map_into()),
159 dma, 161 dma,
160 config, 162 config,
163 FlashSelection::Flash2,
161 ) 164 )
162 } 165 }
163 166
@@ -171,24 +174,42 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
171 nss: Option<PeripheralRef<'d, AnyPin>>, 174 nss: Option<PeripheralRef<'d, AnyPin>>,
172 dma: impl Peripheral<P = Dma> + 'd, 175 dma: impl Peripheral<P = Dma> + 'd,
173 config: Config, 176 config: Config,
177 fsel: FlashSelection,
174 ) -> Self { 178 ) -> Self {
175 into_ref!(peri, dma); 179 into_ref!(peri, dma);
176 180
177 T::enable(); 181 T::enable();
178 T::REGS.cr().write(|w| w.set_fthres(config.fifo_threshold.into())); 182 T::reset();
179 183
180 while T::REGS.sr().read().busy() {} 184 while T::REGS.sr().read().busy() {}
181 185
182 T::REGS.cr().write(|w| { 186 // Apply precautionary steps according to the errata...
183 w.set_prescaler(config.prescaler); 187 T::REGS.cr().write_value(Cr(0));
188 while T::REGS.sr().read().busy() {}
189 T::REGS.cr().write_value(Cr(0xFF000001));
190 T::REGS.ccr().write(|w| w.set_frcm(true));
191 T::REGS.ccr().write(|w| w.set_frcm(true));
192 T::REGS.cr().write_value(Cr(0));
193 while T::REGS.sr().read().busy() {}
194
195 T::REGS.cr().modify(|w| {
184 w.set_en(true); 196 w.set_en(true);
197 //w.set_tcen(false);
198 w.set_sshift(false);
199 w.set_fthres(config.fifo_threshold.into());
200 w.set_prescaler(config.prescaler);
201 w.set_fsel(fsel.into());
185 }); 202 });
186 T::REGS.dcr().write(|w| { 203 T::REGS.dcr().modify(|w| {
187 w.set_fsize(config.memory_size.into()); 204 w.set_fsize(config.memory_size.into());
188 w.set_csht(config.cs_high_time.into()); 205 w.set_csht(config.cs_high_time.into());
189 w.set_ckmode(false); 206 w.set_ckmode(true);
190 }); 207 });
191 208
209 // FOR TESTING ONLY
210 //T::REGS.ccr().write(|w| w.set_frcm(true));
211 // END FOR TESTING ONLY
212
192 Self { 213 Self {
193 _peri: peri, 214 _peri: peri,
194 sck, 215 sck,
@@ -203,6 +224,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
203 } 224 }
204 225
205 pub fn command(&mut self, transaction: TransferConfig) { 226 pub fn command(&mut self, transaction: TransferConfig) {
227 #[cfg(not(stm32h7))]
206 T::REGS.cr().modify(|v| v.set_dmaen(false)); 228 T::REGS.cr().modify(|v| v.set_dmaen(false));
207 self.setup_transaction(QspiMode::IndirectWrite, &transaction); 229 self.setup_transaction(QspiMode::IndirectWrite, &transaction);
208 230
@@ -211,6 +233,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
211 } 233 }
212 234
213 pub fn blocking_read(&mut self, buf: &mut [u8], transaction: TransferConfig) { 235 pub fn blocking_read(&mut self, buf: &mut [u8], transaction: TransferConfig) {
236 #[cfg(not(stm32h7))]
214 T::REGS.cr().modify(|v| v.set_dmaen(false)); 237 T::REGS.cr().modify(|v| v.set_dmaen(false));
215 self.setup_transaction(QspiMode::IndirectWrite, &transaction); 238 self.setup_transaction(QspiMode::IndirectWrite, &transaction);
216 239
@@ -234,6 +257,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
234 } 257 }
235 258
236 pub fn blocking_write(&mut self, buf: &[u8], transaction: TransferConfig) { 259 pub fn blocking_write(&mut self, buf: &[u8], transaction: TransferConfig) {
260 #[cfg(not(stm32h7))]
237 T::REGS.cr().modify(|v| v.set_dmaen(false)); 261 T::REGS.cr().modify(|v| v.set_dmaen(false));
238 self.setup_transaction(QspiMode::IndirectWrite, &transaction); 262 self.setup_transaction(QspiMode::IndirectWrite, &transaction);
239 263
@@ -277,6 +301,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
277 ) 301 )
278 }; 302 };
279 303
304 #[cfg(not(stm32h7))]
280 T::REGS.cr().modify(|v| v.set_dmaen(true)); 305 T::REGS.cr().modify(|v| v.set_dmaen(true));
281 306
282 transfer.blocking_wait(); 307 transfer.blocking_wait();
@@ -303,6 +328,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> {
303 ) 328 )
304 }; 329 };
305 330
331 #[cfg(not(stm32h7))]
306 T::REGS.cr().modify(|v| v.set_dmaen(true)); 332 T::REGS.cr().modify(|v| v.set_dmaen(true));
307 333
308 transfer.blocking_wait(); 334 transfer.blocking_wait();