From 8199a247a62b2cfb45dd1d5e348923e626d65bcb Mon Sep 17 00:00:00 2001 From: Raymond Lei Date: Mon, 3 Mar 2025 14:00:35 -0600 Subject: [PATCH] boards/soc: nxp: MCXA, imxrt11xx: reconfigure clock source of lpspi In spi loopback test, high bandrate is 16Mbps while some source of lpspi are too low to support this bandrate. According the reference mannual, to support 16Mbps, Input frequency at least should be 2*16MHz. Update LPSPI input freq to maximum to get more accurate band rate because band rate must be divisible by input freq. Signed-off-by: Raymond Lei --- boards/nxp/frdm_mcxa156/board.c | 6 ++++-- boards/nxp/frdm_mcxn236/board.c | 12 ++++++++---- boards/nxp/frdm_mcxn947/board.c | 12 ++++++++---- soc/nxp/imxrt/imxrt10xx/soc.c | 5 +++-- soc/nxp/imxrt/imxrt11xx/soc.c | 4 ++-- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/boards/nxp/frdm_mcxa156/board.c b/boards/nxp/frdm_mcxa156/board.c index eae24a90654..a85eb1cf392 100644 --- a/boards/nxp/frdm_mcxa156/board.c +++ b/boards/nxp/frdm_mcxa156/board.c @@ -199,13 +199,15 @@ void board_early_init_hook(void) #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi0)) + /* Configure input clock to be able to reach the datasheet specified band rate. */ CLOCK_SetClockDiv(kCLOCK_DivLPSPI0, 1u); - CLOCK_AttachClk(kFRO12M_to_LPSPI0); + CLOCK_AttachClk(kFRO_HF_DIV_to_LPSPI0); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lpspi1)) + /* Configure input clock to be able to reach the datasheet specified band rate. */ CLOCK_SetClockDiv(kCLOCK_DivLPSPI1, 1u); - CLOCK_AttachClk(kFRO12M_to_LPSPI1); + CLOCK_AttachClk(kFRO_HF_DIV_to_LPSPI1); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lptmr0)) diff --git a/boards/nxp/frdm_mcxn236/board.c b/boards/nxp/frdm_mcxn236/board.c index 35ce1fbd720..fff4c085a96 100644 --- a/boards/nxp/frdm_mcxn236/board.c +++ b/boards/nxp/frdm_mcxn236/board.c @@ -119,23 +119,27 @@ void board_early_init_hook(void) #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm1)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom1Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM1); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM1); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm2)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM2); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm3)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom3Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM3); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM3); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm4)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM4); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm5)) diff --git a/boards/nxp/frdm_mcxn947/board.c b/boards/nxp/frdm_mcxn947/board.c index 96f8f8f38d6..708c0fc081e 100644 --- a/boards/nxp/frdm_mcxn947/board.c +++ b/boards/nxp/frdm_mcxn947/board.c @@ -148,23 +148,27 @@ void board_early_init_hook(void) #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm1)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom1Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM1); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM1); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm2)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM2); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm4)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM4); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcomm7)) + /* Configure input clock to be able to reach the datasheet specified SPI band rate. */ CLOCK_SetClkDiv(kCLOCK_DivFlexcom7Clk, 1u); - CLOCK_AttachClk(kFRO12M_to_FLEXCOMM7); + CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM7); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(os_timer)) diff --git a/soc/nxp/imxrt/imxrt10xx/soc.c b/soc/nxp/imxrt/imxrt10xx/soc.c index b26d8d85a4a..9c11ba5372a 100644 --- a/soc/nxp/imxrt/imxrt10xx/soc.c +++ b/soc/nxp/imxrt/imxrt10xx/soc.c @@ -209,8 +209,9 @@ __weak void clock_init(void) #endif #ifdef CONFIG_SPI_MCUX_LPSPI - CLOCK_SetMux(kCLOCK_LpspiMux, 1); /* Set SPI source to USB1 PFD0 720M */ - CLOCK_SetDiv(kCLOCK_LpspiDiv, 7); /* Set SPI divider to 8 */ + /* Configure input clock to be able to reach the datasheet specified band rate. */ + CLOCK_SetMux(kCLOCK_LpspiMux, 1); /* Set SPI source to USB1 PFD0 */ + CLOCK_SetDiv(kCLOCK_LpspiDiv, 0); /* Set SPI divider to 1 */ #endif #ifdef CONFIG_DISPLAY_MCUX_ELCDIF diff --git a/soc/nxp/imxrt/imxrt11xx/soc.c b/soc/nxp/imxrt/imxrt11xx/soc.c index a1d7c03cf5f..e268a95ff8c 100644 --- a/soc/nxp/imxrt/imxrt11xx/soc.c +++ b/soc/nxp/imxrt/imxrt11xx/soc.c @@ -463,8 +463,8 @@ __weak void clock_init(void) #endif #ifdef CONFIG_SPI_MCUX_LPSPI - /* Configure lpspi using Osc48MDiv2 */ - rootCfg.mux = kCLOCK_LPSPI1_ClockRoot_MuxOscRc48MDiv2; + /* Configure input clock to be able to reach the datasheet specified band rate. */ + rootCfg.mux = kCLOCK_LPSPI1_ClockRoot_MuxOscRc400M; rootCfg.div = 1; CLOCK_SetRootClock(kCLOCK_Root_Lpspi1, &rootCfg); #endif