Skip to content

Commit 6865d5f

Browse files
committed
drivers: spi: nxp: flexiospi spi_loopback test failed on flexio spi
Several reason cause loopback test failed: a) FlexIO input frequency is not correct, on RT11xx, input freq is 24M, while max bandrate can reach 1/4 of input freq, so it can only support 6Mbps. b) Flexio shift register depend on correct timer output to triggger TX and TX, if timer comparison value is not accurate, RX error happens on high band rate. This is the reason why test fails on RT1060. also fix a error on FlexIO clock ID calculation. Signed-off-by: Raymond Lei <[email protected]>
1 parent 2f9faa0 commit 6865d5f

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

drivers/clock_control/clock_control_mcux_ccm_rev2.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,8 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev,
225225
#endif
226226

227227
#ifdef CONFIG_MCUX_FLEXIO
228-
case IMX_CCM_FLEXIO1_CLK:
229-
clock_root = kCLOCK_Root_Flexio1;
230-
break;
231-
case IMX_CCM_FLEXIO2_CLK:
232-
clock_root = kCLOCK_Root_Flexio2;
228+
case IMX_CCM_FLEXIO_CLK:
229+
clock_root = kCLOCK_Root_Flexio1 + instance;
233230
break;
234231
#endif
235232

drivers/spi/spi_mcux_flexio.c

+18
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ static void spi_flexio_master_init(FLEXIO_SPI_Type *base, flexio_spi_master_conf
206206
timerConfig.timerStart = kFLEXIO_TimerStartBitEnabled;
207207
/* Low 8-bits are used to configure baudrate. */
208208
timerDiv = (uint16_t)(srcClock_Hz / masterConfig->baudRate_Bps);
209+
210+
/* Add protection if bandrate required is overflow.
211+
* FLEXIO input freq can not meet required bandrate. Max bandrate can
212+
* not exceed 1/4 of input freq. You can raise input freq or lower
213+
* bandrate required to remove this warning.
214+
*/
215+
if (timerDiv < 4) {
216+
timerDiv = 4;
217+
}
218+
/* If timeDiv is odd, get it to even. */
219+
timerDiv += timerDiv & 1UL;
220+
221+
if (masterConfig->baudRate_Bps != (srcClock_Hz / timerDiv)) {
222+
LOG_WRN("Bandrate req:%uKbps, got:%uKbps",
223+
(uint32_t)(masterConfig->baudRate_Bps / 1000),
224+
(uint32_t)(srcClock_Hz / (timerDiv*1000)));
225+
}
226+
209227
timerDiv = timerDiv / 2U - 1U;
210228
/* High 8-bits are used to configure shift clock edges(transfer width). */
211229
timerCmp = ((uint16_t)masterConfig->dataMode * 2U - 1U) << 8U;

soc/nxp/imxrt/imxrt10xx/soc.c

+12
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ __weak void clock_init(void)
215215
CLOCK_SetDiv(kCLOCK_LpspiDiv, 0); /* Set SPI divider to 1 */
216216
#endif
217217

218+
#ifdef CONFIG_MCUX_FLEXIO
219+
/* Configure input clock to be able to reach the datasheet specified band rate.
220+
* FLEXIO can reach to 120MHz. Select USB pll(480M) as source and divide by 2.
221+
* pre divider by default is 1 which means divide by 2.
222+
*/
223+
CLOCK_SetMux(kCLOCK_Flexio1Mux, 3);
224+
CLOCK_SetDiv(kCLOCK_Flexio1Div, 1);
225+
226+
CLOCK_SetMux(kCLOCK_Flexio2Mux, 3);
227+
CLOCK_SetDiv(kCLOCK_Flexio2Div, 1);
228+
#endif
229+
218230
#ifdef CONFIG_DISPLAY_MCUX_ELCDIF
219231
/* MUX selects video PLL, which is initialized to 93MHz */
220232
CLOCK_SetMux(kCLOCK_LcdifPreMux, 2);

soc/nxp/imxrt/imxrt11xx/soc.c

+12
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,18 @@ __weak void clock_init(void)
391391
CLOCK_SetRootClock(kCLOCK_Root_Lpuart2, &rootCfg);
392392
#endif
393393

394+
#ifdef CONFIG_MCUX_FLEXIO
395+
/* Configure flexio1 with oscRC400M */
396+
rootCfg.mux = kCLOCK_FLEXIO1_ClockRoot_MuxOscRc400M;
397+
rootCfg.div = 2;
398+
CLOCK_SetRootClock(kCLOCK_Root_Flexio1, &rootCfg);
399+
400+
/* Configure flexio2 using oscRC400M */
401+
rootCfg.mux = kCLOCK_FLEXIO2_ClockRoot_MuxOscRc400M;
402+
rootCfg.div = 2;
403+
CLOCK_SetRootClock(kCLOCK_Root_Flexio2, &rootCfg);
404+
#endif
405+
394406
#ifdef CONFIG_I2C_MCUX_LPI2C
395407
/* Configure Lpi2c1 using Osc48MDiv2 */
396408
rootCfg.mux = kCLOCK_LPI2C1_ClockRoot_MuxOscRc48MDiv2;

0 commit comments

Comments
 (0)