Skip to main content

esp_hal/psram/
esp32c5_c61.rs

1use core::ops::Range;
2
3use super::{EXTMEM_ORIGIN, PsramSize};
4use crate::{
5    peripherals::{CACHE, SPI0, SPI1},
6    psram::implem::quad::MspiTimingSpeedMode,
7};
8
9mod quad;
10
11use procmacros::ram;
12use quad::CommandMode;
13
14const FUNC_SPICS1_SPICS1: u8 = 0;
15const PIN_FUNC_GPIO: u8 = 1;
16
17cfg_select! {
18    esp32c61 => {
19        const PSRAM_CS_IO: u8 = 14;
20        const SPI_CS1_GPIO_NUM: u8 = 14;
21        const SPICS1_OUT_IDX: u8 = 102;
22        const PSRAM_SPIWP_SD3_IO: u8 = 17;
23    }
24    esp32c5 => {
25        const PSRAM_CS_IO: u8 = 15;
26        const SPI_CS1_GPIO_NUM: u8 = 15;
27        const SPICS1_OUT_IDX: u8 = 101;
28        const PSRAM_SPIWP_SD3_IO: u8 = 18;
29    }
30    esp32h4 => {
31        const PSRAM_CS_IO: u8 = 6;
32        const SPI_CS1_GPIO_NUM: u8 = 6;
33        const SPICS1_OUT_IDX: u8 = 102;
34        const PSRAM_SPIWP_SD3_IO: u8 = 9;
35    }
36    _ => {}
37}
38
39#[derive(Copy, Clone, Debug, PartialEq, Eq)]
40pub(crate) enum PsramLlCsIdT {
41    PsramLlCsId0,
42    PsramLlCsId1,
43}
44
45#[cfg(any(esp32c5, esp32c61))]
46mod chip {
47    use super::{CACHE, MspiTimingSpeedMode};
48
49    /// Frequency of flash memory
50    #[derive(Copy, Clone, Debug, Default, PartialEq)]
51    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
52    pub enum FlashFreq {
53        /// Flash frequency 40 MHz
54        FlashFreq40m = 40,
55        /// Flash frequency 80 MHz
56        #[default]
57        FlashFreq80m = 80,
58    }
59
60    impl FlashFreq {
61        pub(super) fn mhz(&self) -> u32 {
62            match self {
63                FlashFreq::FlashFreq40m => 40,
64                FlashFreq::FlashFreq80m => 80,
65            }
66        }
67    }
68
69    /// Frequency of PSRAM memory
70    #[derive(Copy, Clone, Debug, Default, PartialEq)]
71    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
72    pub enum SpiRamFreq {
73        /// PSRAM frequency 40 MHz
74        Freq40m = 40,
75        /// PSRAM frequency 80 MHz. Default.
76        #[default]
77        Freq80m = 80,
78    }
79
80    impl SpiRamFreq {
81        pub(crate) fn need_timing_tuning(&self) -> bool {
82            *self != SpiRamFreq::Freq40m
83        }
84
85        pub(super) fn mhz(&self) -> u32 {
86            match self {
87                SpiRamFreq::Freq40m => 40,
88                SpiRamFreq::Freq80m => 80,
89            }
90        }
91    }
92
93    #[inline(always)]
94    pub(super) fn core_clock_for_mode(_speed_mode: MspiTimingSpeedMode) -> u32 {
95        // in all cases (low and high speed) we use an MSPI clock of 80 MHz on this target
96        80
97    }
98
99    /// Sets MSPI_FAST_CLK's high-speed divider (valid when SOC_ROOT clock source is PLL).
100    #[inline(always)]
101    pub(crate) fn mspi_timing_ll_set_core_clock(core_clk_mhz: u32) {
102        let divider = match core_clk_mhz {
103            80 => 6,
104            _ => panic!("Invalid core clock"),
105        };
106
107        crate::peripherals::PCR::regs()
108            .mspi_clk_conf()
109            .modify(|_, w| unsafe { w.mspi_fast_div_num().bits(divider - 1) });
110    }
111
112    pub(super) fn enable_cache_buses() {
113        CACHE::regs().cache_ctrl().modify(|_, w| {
114            w.cache_shut_bus0().clear_bit();
115            w.cache_shut_bus1().clear_bit()
116        });
117    }
118}
119
120#[cfg(esp32h4)]
121mod chip {
122    use super::{CACHE, MspiTimingSpeedMode};
123
124    /// Frequency of flash memory
125    #[derive(Copy, Clone, Debug, Default, PartialEq)]
126    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
127    pub enum FlashFreq {
128        /// Flash frequency 32 MHz
129        FlashFreq32m = 32,
130        /// Flash frequency 64 MHz
131        #[default]
132        FlashFreq64m = 64,
133    }
134
135    impl FlashFreq {
136        pub(super) fn mhz(&self) -> u32 {
137            match self {
138                FlashFreq::FlashFreq32m => 32,
139                FlashFreq::FlashFreq64m => 64,
140            }
141        }
142    }
143
144    /// Frequency of PSRAM memory
145    #[derive(Copy, Clone, Debug, Default, PartialEq)]
146    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
147    pub enum SpiRamFreq {
148        /// PSRAM frequency 32 MHz
149        Freq32m = 32,
150        /// PSRAM frequency 64 MHz. Default.
151        #[default]
152        Freq64m = 64,
153    }
154
155    impl SpiRamFreq {
156        pub(super) fn mhz(&self) -> u32 {
157            match self {
158                SpiRamFreq::Freq32m => 32,
159                SpiRamFreq::Freq64m => 64,
160            }
161        }
162    }
163
164    pub(super) fn core_clock_for_mode(_speed_mode: MspiTimingSpeedMode) -> u32 {
165        64
166    }
167
168    // The bootloader sets XTAL_X2_CLK as the MSPI core clock. Flash also uses this clock.
169    #[inline(always)]
170    pub(crate) fn mspi_timing_ll_set_core_clock(_core_clk_mhz: u32) {}
171
172    pub(super) fn enable_cache_buses() {
173        // Each core has its own instruction and data bus.
174        CACHE::regs().l1_icache_ctrl().modify(|_, w| {
175            w.l1_icache_shut_ibus0().clear_bit();
176            w.l1_icache_shut_ibus1().clear_bit()
177        });
178        CACHE::regs().l1_dcache_ctrl().modify(|_, w| {
179            w.l1_dcache_shut_dbus0().clear_bit();
180            w.l1_dcache_shut_dbus1().clear_bit()
181        });
182    }
183}
184
185pub use chip::{FlashFreq, SpiRamFreq};
186use chip::{core_clock_for_mode, enable_cache_buses, mspi_timing_ll_set_core_clock};
187#[cfg(psram_has_timing_tuning)]
188pub use tuning::MspiTimingTuningParam;
189
190/// PSRAM configuration
191///
192/// [`Psram::new`](super::Psram::new) runs the PSRAM start-up, which changes the MSPI clocks. An
193/// interrupt handler in flash must not run in that time, so `Psram::new` must be called before any
194/// interrupt is enabled. See [Optimization level](crate#optimization-level) for the build
195/// requirement.
196#[derive(Copy, Clone, Debug, Default, PartialEq)]
197#[cfg_attr(feature = "defmt", derive(defmt::Format))]
198pub struct PsramConfig {
199    /// PSRAM size
200    pub size: PsramSize,
201    /// Frequency of flash memory
202    pub flash_frequency: FlashFreq,
203    /// Flash timing tuning configuration.
204    /// Used as needed.
205    #[cfg(psram_has_timing_tuning)]
206    pub flash_tuning: MspiTimingTuningParam,
207    /// Frequency of PSRAM memory
208    pub ram_frequency: SpiRamFreq,
209    /// PSRAM timing tuning configuration.
210    /// Used as needed.
211    #[cfg(psram_has_timing_tuning)]
212    pub ram_tuning: MspiTimingTuningParam,
213}
214
215/// Initializes PSRAM to be used for data.
216#[procmacros::ram]
217pub(crate) fn init_psram(config: &mut PsramConfig) -> bool {
218    // The register setters keep only the bits of each field, so a value out of range must fail
219    // here, before the MSPI timing changes. The start-up writes the values only when the PSRAM
220    // frequency needs timing tuning.
221    #[cfg(psram_has_timing_tuning)]
222    if config.ram_frequency.need_timing_tuning() {
223        for param in [config.flash_tuning, config.ram_tuning] {
224            assert!(param.spi_din_mode <= 7);
225            assert!(param.spi_din_num <= 3);
226        }
227    }
228
229    // The flash and PSRAM frequency while the start-up changes the timing.
230    const LOW_SPEED_MHZ: u32 = 20;
231
232    // The division and its assertion have panic paths in flash, so the clock register values are
233    // calculated before the start-up changes the MSPI clocks.
234    let low_speed = clock_reg(
235        LOW_SPEED_MHZ,
236        MspiTimingSpeedMode::MspiTimingSpeedModeLowPerf,
237    );
238    let flash = clock_reg(
239        config.flash_frequency.mhz(),
240        MspiTimingSpeedMode::MspiTimingSpeedModeNormalPerf,
241    );
242    let psram = clock_reg(
243        config.ram_frequency.mhz(),
244        MspiTimingSpeedMode::MspiTimingSpeedModeNormalPerf,
245    );
246    match quad::psram_init(config, low_speed, flash, psram) {
247        quad::ChipId::NotRead => {}
248        quad::ChipId::Unknown(id) => {
249            warn!(
250                "Unknown PSRAM chip ID: {:x}. PSRAM chip not found or not supported. Check if ESP_HAL_CONFIG_PSRAM_MODE is configured correctly.",
251                id
252            );
253            return true;
254        }
255        quad::ChipId::Known { id, density, size } => {
256            info!("Detected PSRAM chip id = {:x}", id);
257            info!("Detected PSRAM chip density = {}", density);
258            info!("PSRAM size is {}", size);
259        }
260    }
261
262    info!(
263        "PSRAM clock {} MHz, flash clock {} MHz",
264        config.ram_frequency.mhz(),
265        config.flash_frequency.mhz()
266    );
267
268    true
269}
270
271#[procmacros::ram]
272pub(crate) fn map_psram(config: PsramConfig) -> Range<usize> {
273    const MMU_PAGE_SIZE: u32 = property!("mmu.page_size");
274    const FLASH_MMU_TABLE_SIZE: u32 = property!("mmu.entry_num");
275
276    fn select_mmu_entry(entry_id: u32) {
277        SPI0::regs()
278            .mmu_item_index()
279            .write(|w| unsafe { w.mmu_item_index().bits(entry_id) });
280    }
281
282    fn mmu_entry_is_valid(entry_id: u32) -> bool {
283        select_mmu_entry(entry_id);
284        SPI0::regs().mmu_item_content().read().valid().bit()
285    }
286
287    fn write_psram_mmu_entry(entry_id: u32, page: u16) {
288        select_mmu_entry(entry_id);
289        SPI0::regs().mmu_item_content().write(|w| {
290            unsafe { w.paddr().bits(page) };
291            w.access_spiram().set_bit();
292            w.valid().set_bit()
293        });
294    }
295
296    // calculate the PSRAM start address to map
297    // the linker scripts can produce a gap between mapped IROM and DROM segments
298    // bigger than a flash page - i.e. we will see an unmapped memory slot
299    // start from the end and find the last mapped flash page
300    let mut mapped_pages = 0;
301
302    // the bootloader is using the last page to access flash internally
303    // (e.g. to read the app descriptor) so we just skip that
304    for i in (0..(FLASH_MMU_TABLE_SIZE - 1)).rev() {
305        if mmu_entry_is_valid(i) {
306            mapped_pages = i + 1;
307            break;
308        }
309    }
310    let start = EXTMEM_ORIGIN as u32 + (MMU_PAGE_SIZE * mapped_pages);
311    debug!("PSRAM start address = {:x}", start);
312
313    for i in 0..config.size.get() as u32 / MMU_PAGE_SIZE {
314        write_psram_mmu_entry(i + mapped_pages, i as u16);
315    }
316
317    enable_cache_buses();
318
319    start as usize..start as usize + config.size.get()
320}
321
322mod ctrlr_ll {
323    use super::*;
324
325    pub(crate) const PSRAM_CTRLR_LL_MSPI_ID_0: u32 = 0;
326
327    #[inline(always)]
328    pub(crate) fn psram_ctrlr_ll_set_cs_hold(_mspi_id: u32, hold_n: u32) {
329        assert!(hold_n > 0);
330
331        SPI0::regs().smem_ac().modify(|_, w| {
332            w.smem_cs_hold().set_bit();
333            unsafe {
334                w.smem_cs_hold_time().bits(hold_n as u8 - 1);
335            }
336            w
337        });
338    }
339
340    #[inline(always)]
341    pub(crate) fn psram_ctrlr_ll_set_cs_setup(_mspi_id: u32, setup_n: u32) {
342        assert!(setup_n > 0);
343
344        SPI0::regs().smem_ac().modify(|_, w| {
345            w.smem_cs_setup().set_bit();
346            unsafe {
347                w.smem_cs_setup_time().bits(setup_n as u8 - 1);
348            }
349            w
350        });
351    }
352
353    #[inline(always)]
354    pub(crate) fn psram_ctrlr_ll_set_read_mode(mspi_id: u32, read_mode: CommandMode) {
355        assert!(mspi_id == 0);
356
357        SPI0::regs().cache_sctrl().modify(|_, w| {
358            w.usr_sram_dio().bit(read_mode == CommandMode::PsramCmdSpi);
359            w.usr_sram_qio().bit(read_mode == CommandMode::PsramCmdQpi);
360            w
361        });
362    }
363
364    /// Sets PSRAM write cmd.
365    #[inline(always)]
366    pub(crate) fn psram_ctrlr_ll_set_wr_cmd(_mspi_id: u32, cmd_bitlen: u32, cmd_val: u32) {
367        assert!(cmd_bitlen > 0);
368        SPI0::regs()
369            .cache_sctrl()
370            .modify(|_, w| w.cache_sram_usr_wcmd().set_bit());
371
372        SPI0::regs().sram_dwr_cmd().modify(|_, w| {
373            unsafe { w.cache_sram_usr_wr_cmd_bitlen().bits(cmd_bitlen as u8 - 1) };
374            unsafe { w.cache_sram_usr_wr_cmd_value().bits(cmd_val as u16) };
375            w
376        });
377    }
378
379    /// Sets PSRAM read cmd.
380    #[inline(always)]
381    pub(crate) fn psram_ctrlr_ll_set_rd_cmd(_mspi_id: u32, cmd_bitlen: u32, cmd_val: u32) {
382        assert!(cmd_bitlen > 0);
383
384        SPI0::regs()
385            .cache_sctrl()
386            .modify(|_, w| w.cache_sram_usr_rcmd().set_bit());
387
388        SPI0::regs().sram_drd_cmd().modify(|_, w| {
389            unsafe { w.cache_sram_usr_rd_cmd_bitlen().bits(cmd_bitlen as u8 - 1) };
390            unsafe { w.cache_sram_usr_rd_cmd_value().bits(cmd_val as u16) };
391            w
392        });
393    }
394
395    /// Sets PSRAM addr bitlen.
396    #[inline(always)]
397    pub(crate) fn psram_ctrlr_ll_set_addr_bitlen(_mspi_id: u32, addr_bitlen: u32) {
398        assert!(addr_bitlen > 0);
399
400        SPI0::regs()
401            .cache_sctrl()
402            .modify(|_, w| unsafe { w.sram_addr_bitlen().bits(addr_bitlen as u8 - 1) });
403    }
404
405    /// Sets PSRAM read dummy.
406    #[inline(always)]
407    pub(crate) fn psram_ctrlr_ll_set_rd_dummy(_mspi_id: u32, dummy_n: u32) {
408        assert!(dummy_n > 0);
409
410        SPI0::regs().cache_sctrl().modify(|_, w| {
411            w.usr_rd_sram_dummy().set_bit();
412            unsafe { w.sram_rdummy_cyclelen().bits(dummy_n as u8 - 1) };
413            w
414        });
415    }
416
417    /// Selects which pin to use for the psram.
418    #[inline(always)]
419    pub(crate) fn psram_ctrlr_ll_set_cs_pin(_mspi_id: u32, cs_id: PsramLlCsIdT) {
420        SPI1::regs().misc().modify(|_, w| {
421            w.cs0_dis().bit(cs_id == PsramLlCsIdT::PsramLlCsId0);
422            w.cs1_dis().bit(cs_id == PsramLlCsIdT::PsramLlCsId1);
423            w
424        });
425    }
426}
427
428/// Returns the clock register value that divides the MSPI core clock of `speed_mode` to
429/// `freq_mhz`.
430fn clock_reg(freq_mhz: u32, speed_mode: MspiTimingSpeedMode) -> u32 {
431    let freqdiv: u32 = core_clock_for_mode(speed_mode) / freq_mhz;
432    assert!(freqdiv > 0);
433    mspi_timing_ll_calculate_clock_reg(freqdiv)
434}
435
436#[ram(unstable(checked))]
437fn mspi_timing_config_set_flash_clock(reg_val: u32, speed_mode: MspiTimingSpeedMode) {
438    // SPI0 and SPI1 share the register for core clock. So we only set SPI0 here.
439    mspi_timing_ll_set_core_clock(core_clock_for_mode(speed_mode));
440
441    mspi_timing_ll_set_flash_clock(0, reg_val);
442    mspi_timing_ll_set_flash_clock(1, reg_val);
443}
444
445/// Calculates spi_flash clock frequency division parameters for register.
446#[inline(always)]
447fn mspi_timing_ll_calculate_clock_reg(clkdiv: u32) -> u32 {
448    if clkdiv == 1 {
449        1 << 31
450    } else {
451        (clkdiv - 1) | ((((clkdiv - 1) / 2) & 0xff) << 8) | (((clkdiv - 1) & 0xff) << 16)
452    }
453}
454
455/// Sets Flash clock.
456#[inline(always)]
457fn mspi_timing_ll_set_flash_clock(mspi_id: u32, clock_conf: u32) {
458    if mspi_id == 0 {
459        SPI0::regs()
460            .clock()
461            .write(|w| unsafe { w.bits(clock_conf) });
462    } else {
463        SPI1::regs()
464            .clock()
465            .write(|w| unsafe { w.bits(clock_conf) });
466    }
467}
468
469#[ram(unstable(checked))]
470fn mspi_timing_config_set_psram_clock(reg_val: u32, speed_mode: MspiTimingSpeedMode) {
471    // bool control_both_mspi = true
472    // SPI0 and SPI1 share the register for core clock. So we only set SPI0 here.
473    mspi_timing_ll_set_core_clock(core_clock_for_mode(speed_mode));
474
475    mspi_timing_ll_set_psram_clock(reg_val);
476}
477
478/// Sets PSRAM clock.
479#[inline(always)]
480fn mspi_timing_ll_set_psram_clock(clock_conf: u32) {
481    SPI0::regs()
482        .sram_clk()
483        .write(|w| unsafe { w.bits(clock_conf) });
484}
485
486#[cfg(psram_has_timing_tuning)]
487mod tuning {
488    use crate::peripherals::{SPI0, SPI1};
489
490    /// MSPI timing tuning parameters.
491    #[derive(Copy, Clone, Debug, PartialEq)]
492    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
493    pub struct MspiTimingTuningParam {
494        /// Input signal delay mode
495        pub spi_din_mode: u8,
496        /// Input signal delay number
497        pub spi_din_num: u8,
498        /// Extra dummy length
499        pub extra_dummy_len: u8,
500    }
501
502    impl Default for MspiTimingTuningParam {
503        fn default() -> Self {
504            // IDF default 80 MHz STR tuning point
505            Self {
506                spi_din_mode: 3,
507                spi_din_num: 1,
508                extra_dummy_len: 2,
509            }
510        }
511    }
512
513    /// Sets MSPI Flash din mode.
514    #[inline(always)]
515    pub(crate) fn mspi_timing_ll_set_flash_din_mode(mspi_id: u8, din_mode: u8) {
516        assert!(mspi_id == 0);
517        // `din_mode` must be at most 7. `init_psram` validates it before the MSPI timing changes.
518
519        SPI0::regs().din_mode().modify(|_, w| {
520            unsafe {
521                w.din0_mode().bits(din_mode);
522                w.din1_mode().bits(din_mode);
523                w.din2_mode().bits(din_mode);
524                w.din3_mode().bits(din_mode);
525                w.din4_mode().bits(din_mode);
526                w.din5_mode().bits(din_mode);
527                w.din6_mode().bits(din_mode);
528                w.din7_mode().bits(din_mode);
529                w.dins_mode().bits(din_mode);
530            }
531
532            w
533        });
534
535        SPI0::regs()
536            .timing_cali()
537            .modify(|_, w| w.update().set_bit());
538    }
539
540    /// Sets MSPI Flash din num.
541    #[inline(always)]
542    pub(crate) fn mspi_timing_ll_set_flash_din_num(mspi_id: u8, din_num: u8) {
543        assert!(mspi_id == 0);
544        // `din_num` must be at most 3. `init_psram` validates it before the MSPI timing changes.
545
546        SPI0::regs().din_num().modify(|_, w| {
547            unsafe {
548                w.din0_num().bits(din_num);
549                w.din1_num().bits(din_num);
550                w.din2_num().bits(din_num);
551                w.din3_num().bits(din_num);
552                w.din4_num().bits(din_num);
553                w.din5_num().bits(din_num);
554                w.din6_num().bits(din_num);
555                w.din7_num().bits(din_num);
556                w.dins_num().bits(din_num);
557            }
558
559            w
560        });
561
562        SPI0::regs()
563            .timing_cali()
564            .modify(|_, w| w.update().set_bit());
565    }
566
567    /// Sets MSPI Flash extra dummy.
568    #[inline(always)]
569    pub(crate) fn mspi_timing_ll_set_flash_extra_dummy(mspi_id: u8, extra_dummy: u8) {
570        if mspi_id == 0 {
571            SPI0::regs().timing_cali().modify(|_, w| {
572                w.timing_cali().bit(extra_dummy > 0);
573                unsafe { w.extra_dummy_cyclelen().bits(extra_dummy) };
574                w
575            });
576        } else {
577            SPI1::regs().timing_cali().modify(|_, w| {
578                w.timing_cali().bit(extra_dummy > 0);
579                unsafe { w.extra_dummy_cyclelen().bits(extra_dummy) };
580                w
581            });
582        }
583
584        SPI0::regs()
585            .timing_cali()
586            .modify(|_, w| w.update().set_bit());
587    }
588
589    /// Sets MSPI PSRAM din mode.
590    #[inline(always)]
591    pub(crate) fn mspi_timing_ll_set_psram_din_mode(mspi_id: u8, din_mode: u8) {
592        assert!(mspi_id == 0);
593        // `din_mode` must be at most 7. `init_psram` validates it before the MSPI timing changes.
594
595        SPI0::regs().smem_din_mode().modify(|_, w| {
596            unsafe {
597                w.smem_din0_mode().bits(din_mode);
598                w.smem_din1_mode().bits(din_mode);
599                w.smem_din2_mode().bits(din_mode);
600                w.smem_din3_mode().bits(din_mode);
601                w.smem_din4_mode().bits(din_mode);
602                w.smem_din5_mode().bits(din_mode);
603                w.smem_din6_mode().bits(din_mode);
604                w.smem_din7_mode().bits(din_mode);
605                w.smem_dins_mode().bits(din_mode);
606            }
607
608            w
609        });
610
611        SPI0::regs()
612            .timing_cali()
613            .modify(|_, w| w.update().set_bit());
614    }
615
616    /// Sets MSPI PSRAM din num.
617    #[inline(always)]
618    pub(crate) fn mspi_timing_ll_set_psram_din_num(mspi_id: u8, din_num: u8) {
619        assert!(mspi_id == 0);
620        // `din_num` must be at most 3. `init_psram` validates it before the MSPI timing changes.
621
622        SPI0::regs().smem_din_num().modify(|_, w| {
623            unsafe {
624                w.smem_din0_num().bits(din_num);
625                w.smem_din1_num().bits(din_num);
626                w.smem_din2_num().bits(din_num);
627                w.smem_din3_num().bits(din_num);
628                w.smem_din4_num().bits(din_num);
629                w.smem_din5_num().bits(din_num);
630                w.smem_din6_num().bits(din_num);
631                w.smem_din7_num().bits(din_num);
632                w.smem_dins_num().bits(din_num);
633            }
634
635            w
636        });
637
638        SPI0::regs()
639            .timing_cali()
640            .modify(|_, w| w.update().set_bit());
641    }
642
643    /// Sets MSPI PSRAM extra dummy.
644    #[inline(always)]
645    pub(crate) fn mspi_timing_ll_set_psram_extra_dummy(mspi_id: u8, extra_dummy: u8) {
646        assert!(mspi_id == 0);
647
648        SPI0::regs().smem_timing_cali().modify(|_, w| {
649            w.smem_timing_cali().bit(extra_dummy > 0);
650            unsafe { w.smem_extra_dummy_cyclelen().bits(extra_dummy) };
651            w
652        });
653
654        SPI0::regs()
655            .timing_cali()
656            .modify(|_, w| w.update().set_bit());
657    }
658}