@@ -85,18 +85,39 @@ BUILD_ASSERT(QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 16),
8585 * PCLK192M frequency"), but after that operation is complete, the default
8686 * divider needs to be restored to avoid increased current consumption.
8787 */
88- /* To prevent anomaly 159, use only divider /1 for HFCLK192M. */
88+ #if (INST_0_SCK_FREQUENCY >= NRF_QSPI_BASE_CLOCK_FREQ )
89+ /* For requested SCK >= 96 MHz, use HFCLK192M / 1 / (2*1) = 96 MHz */
8990#define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_1
90- #if (QSPI_IF_DEVICE_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 4 ))
91- /* For requested SCK >= 24 MHz, use HFCLK192M / 1 / (2*4) = 24 MHz */
92- #define INST_0_SCK_CFG NRF_QSPI_FREQ_DIV4
91+ #define INST_0_SCK_CFG NRF_QSPI_FREQ_DIV1
92+ /* If anomaly 159 is to be prevented, only /1 divider can be used. */
93+ #elif NRF53_ERRATA_159_ENABLE_WORKAROUND
94+ #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_1
95+ #define INST_0_SCK_CFG (DIV_ROUND_UP(NRF_QSPI_BASE_CLOCK_FREQ, \
96+ INST_0_SCK_FREQUENCY) - 1)
97+ #elif (INST_0_SCK_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 2 ))
98+ /* For 96 MHz > SCK >= 48 MHz, use HFCLK192M / 2 / (2*1) = 48 MHz */
99+ #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_2
100+ #define INST_0_SCK_CFG NRF_QSPI_FREQ_DIV1
101+ #elif (INST_0_SCK_FREQUENCY >= (NRF_QSPI_BASE_CLOCK_FREQ / 3 ))
102+ /* For 48 MHz > SCK >= 32 MHz, use HFCLK192M / 1 / (2*3) = 32 MHz */
103+ #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_1
104+ #define INST_0_SCK_CFG NRF_QSPI_FREQ_DIV3
93105#else
94- /* For requested SCK < 24 MHz, calculate the configuration value. */
106+ /* For requested SCK < 32 MHz, use divider /2 for HFCLK192M. */
107+ #define BASE_CLOCK_DIV NRF_CLOCK_HFCLK_DIV_2
95108#define INST_0_SCK_CFG (DIV_ROUND_UP(NRF_QSPI_BASE_CLOCK_FREQ / 2, \
96109 QSPI_IF_DEVICE_FREQUENCY) - 1)
97110#endif
111+
112+ #if BASE_CLOCK_DIV == NRF_CLOCK_HFCLK_DIV_1
113+ /* For 8 MHz, use HFCLK192M / 1 / (2*12) */
114+ #define INST_0_SCK_CFG_WAKE NRF_QSPI_FREQ_DIV12
115+ #elif BASE_CLOCK_DIV == NRF_CLOCK_HFCLK_DIV_2
98116/* For 8 MHz, use HFCLK192M / 2 / (2*6) */
99117#define INST_0_SCK_CFG_WAKE NRF_QSPI_FREQ_DIV6
118+ #else
119+ #error "Unsupported base clock divider for wake-up frequency."
120+ #endif
100121
101122#else
102123/*
0 commit comments