Skip to content

Commit 581e7ff

Browse files
Raymond0225dkalowsk
authored andcommitted
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 baud rate 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 RX, if timer comparison value is not accurate, RX error happens on high baud 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 24843ae commit 581e7ff

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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ static void spi_flexio_master_init(FLEXIO_SPI_Type *base, flexio_spi_master_conf
201201
timerConfig.timerStart = kFLEXIO_TimerStartBitEnabled;
202202
/* Low 8-bits are used to configure baudrate. */
203203
timerDiv = (uint16_t)(srcClock_Hz / masterConfig->baudRate_Bps);
204+
205+
/* Add protection if the required band rate overflows.
206+
* FLEXIO input freq can't meet required band rate. Max band rate can
207+
* not exceed 1/4 of input freq. You can raise input freq or lower
208+
* bandrate required to remove this warning.
209+
*/
210+
if (timerDiv < 4) {
211+
timerDiv = 4;
212+
}
213+
/* If timeDiv is odd, get it to even. */
214+
timerDiv += timerDiv & 1UL;
215+
216+
if (masterConfig->baudRate_Bps != (srcClock_Hz / timerDiv)) {
217+
LOG_WRN("Bandrate req:%uKbps, got:%uKbps",
218+
(uint32_t)(masterConfig->baudRate_Bps / 1000),
219+
(uint32_t)(srcClock_Hz / (timerDiv*1000)));
220+
}
221+
204222
timerDiv = timerDiv / 2U - 1U;
205223
/* High 8-bits are used to configure shift clock edges(transfer width). */
206224
timerCmp = ((uint16_t)masterConfig->dataMode * 2U - 1U) << 8U;

soc/nxp/imxrt/imxrt10xx/soc.c

Lines changed: 12 additions & 0 deletions
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 baud 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

Lines changed: 12 additions & 0 deletions
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)