@@ -119,6 +119,14 @@ BUILD_ASSERT(QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 16),
119119#error "Unsupported base clock divider for wake-up frequency."
120120#endif
121121
122+ /* After the base clock divider is changed, some time is needed for the new
123+ * setting to take effect. This value specifies the delay (in microseconds)
124+ * to be applied to ensure that the clock is ready when the QSPI operation
125+ * starts. It was measured with a logic analyzer (unfortunately, the nRF5340
126+ * specification does not provide any numbers in this regard).
127+ */
128+ #define BASE_CLOCK_SWITCH_DELAY_US 7
129+
122130#else
123131/*
124132 * On nRF52 Series SoCs, the base clock divider is not configurable,
@@ -374,6 +382,7 @@ static inline void qspi_lock(const struct device *dev)
374382 */
375383#if defined(CONFIG_SOC_SERIES_NRF53X )
376384 nrf_clock_hfclk192m_div_set (NRF_CLOCK , BASE_CLOCK_DIV );
385+ k_busy_wait (BASE_CLOCK_SWITCH_DELAY_US );
377386#endif
378387}
379388
@@ -383,6 +392,7 @@ static inline void qspi_unlock(const struct device *dev)
383392 /* Restore the default base clock divider to reduce power consumption.
384393 */
385394 nrf_clock_hfclk192m_div_set (NRF_CLOCK , NRF_CLOCK_HFCLK_DIV_4 );
395+ k_busy_wait (BASE_CLOCK_SWITCH_DELAY_US );
386396#endif
387397
388398#ifdef CONFIG_MULTITHREADING
@@ -673,6 +683,7 @@ static inline void qspi_fill_init_struct(nrfx_qspi_config_t *initstruct)
673683
674684 /* Configure physical interface */
675685 initstruct -> phy_if .sck_freq = INST_0_SCK_CFG ;
686+
676687 /* Using MHZ fails checkpatch constant check */
677688 if (QSPI_IF_DEVICE_FREQUENCY >= 16000000 ) {
678689 qspi_cfg -> qspi_slave_latency = 1 ;
@@ -708,13 +719,15 @@ static int qspi_nrfx_configure(const struct device *dev)
708719 * divider.
709720 */
710721 nrf_clock_hfclk192m_div_set (NRF_CLOCK , BASE_CLOCK_DIV );
722+ k_busy_wait (BASE_CLOCK_SWITCH_DELAY_US );
711723#endif
712724
713725 nrfx_err_t res = _nrfx_qspi_init (& QSPIconfig , qspi_handler , dev_data );
714726
715727#if defined(CONFIG_SOC_SERIES_NRF53X )
716728 /* Restore the default /4 divider after the QSPI initialization. */
717729 nrf_clock_hfclk192m_div_set (NRF_CLOCK , NRF_CLOCK_HFCLK_DIV_4 );
730+ k_busy_wait (BASE_CLOCK_SWITCH_DELAY_US );
718731#endif
719732
720733 int ret = qspi_get_zephyr_ret_code (res );
0 commit comments