Skip to content

Commit 99131b9

Browse files
mmahadevan108nashif
authored andcommitted
boards: frdm_mcxn947: Enable CACHE64 FlexSPI cache
1. Enable CACHE64 block used by FlexSPI. 2. LPCAC cache is already enabled by SystemInit which is called earlier 3. Configure the FlexSPI clock when running in XIP mode as we cannot rely on the driver setting this up as it may not be enabled. Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent b32a86a commit 99131b9

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

boards/nxp/frdm_mcxn947/board.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
/* System clock frequency. */
2626
extern uint32_t SystemCoreClock;
2727

28-
__ramfunc static void enable_lpcac(void)
29-
{
30-
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_CLR_LPCAC_MASK;
31-
SYSCON->LPCAC_CTRL &= ~(SYSCON_LPCAC_CTRL_CLR_LPCAC_MASK |
32-
SYSCON_LPCAC_CTRL_DIS_LPCAC_MASK);
33-
}
34-
3528
/* Update Active mode voltage for OverDrive mode. */
3629
void power_mode_od(void)
3730
{
@@ -57,10 +50,38 @@ void power_mode_od(void)
5750
SPC_SetSRAMOperateVoltage(SPC0, &cfg);
5851
}
5952

60-
static int frdm_mcxn947_init(void)
53+
#if CONFIG_FLASH_MCUX_FLEXSPI_NOR || CONFIG_FLASH_MCUX_FLEXSPI_XIP
54+
__ramfunc static void enable_cache64(void)
6155
{
62-
enable_lpcac();
56+
/* Make sure the FlexSPI clock is enabled before configuring the FlexSPI cache. */
57+
SYSCON->AHBCLKCTRLSET[0] |= SYSCON_AHBCLKCTRL0_FLEXSPI_MASK;
58+
59+
/* Set command to invalidate all ways and write GO bit to initiate command */
60+
CACHE64_CTRL0->CCR = CACHE64_CTRL_CCR_INVW1_MASK | CACHE64_CTRL_CCR_INVW0_MASK;
61+
CACHE64_CTRL0->CCR |= CACHE64_CTRL_CCR_GO_MASK;
62+
/* Wait until the command completes */
63+
while ((CACHE64_CTRL0->CCR & CACHE64_CTRL_CCR_GO_MASK) != 0U) {
64+
}
65+
/* Enable cache, enable write buffer */
66+
CACHE64_CTRL0->CCR = (CACHE64_CTRL_CCR_ENWRBUF_MASK | CACHE64_CTRL_CCR_ENCACHE_MASK);
67+
68+
/* configure reg0, reg1 to cover the whole FlexSPI
69+
* reg 0 covers the space where Zephyr resides in case of XIP from FlexSPI
70+
* reg 1 covers the storage space in case of XIP from FlexSPI
71+
*/
72+
CACHE64_POLSEL0->REG0_TOP = 0x7FFC00;
73+
CACHE64_POLSEL0->REG1_TOP = 0x0;
74+
CACHE64_POLSEL0->POLSEL =
75+
(CACHE64_POLSEL_POLSEL_REG0_POLICY(1) | CACHE64_POLSEL_POLSEL_REG1_POLICY(0) |
76+
CACHE64_POLSEL_POLSEL_REG2_POLICY(0));
77+
78+
__ISB();
79+
__DSB();
80+
}
81+
#endif
6382

83+
static int frdm_mcxn947_init(void)
84+
{
6485
power_mode_od();
6586

6687
/* Enable SCG clock */
@@ -232,12 +253,11 @@ static int frdm_mcxn947_init(void)
232253
CLOCK_AttachClk(kFRO_HF_to_USDHC);
233254
#endif
234255

235-
#if CONFIG_FLASH_MCUX_FLEXSPI_NOR
236-
/* We downclock the FlexSPI to 50MHz, it will be set to the
237-
* optimum speed supported by the Flash device during FLEXSPI
238-
* Init
239-
*/
240-
flexspi_clock_set_freq(MCUX_FLEXSPI_CLK, MHZ(50));
256+
#if CONFIG_FLASH_MCUX_FLEXSPI_NOR || CONFIG_FLASH_MCUX_FLEXSPI_XIP
257+
/* Setup the FlexSPI clock */
258+
flexspi_clock_set_freq(MCUX_FLEXSPI_CLK,
259+
DT_PROP(DT_NODELABEL(w25q64jvssiq), spi_max_frequency));
260+
enable_cache64();
241261
#endif
242262

243263
#if DT_NODE_HAS_STATUS(DT_NODELABEL(vref), okay)

0 commit comments

Comments
 (0)