Skip to content

Commit 501c6ab

Browse files
NeilChen93kartben
authored andcommitted
boards: frdm_mcxn236: Support sai for NXP frdm_mcxn236
1. Support sai for NXP frdm_mcxn236. 2. Verified tests/drivers/i2s/i2s_speed Signed-off-by: Neil Chen <[email protected]>
1 parent c9ce1a7 commit 501c6ab

File tree

9 files changed

+145
-14
lines changed

9 files changed

+145
-14
lines changed

boards/nxp/frdm_mcxn236/board.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,18 @@ void board_early_init_hook(void)
103103

104104
CLOCK_SetupExtClocking(BOARD_XTAL0_CLK_HZ);
105105

106-
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan1))
107-
/* Set up PLL1 for 80 MHz FlexCAN clock */
108-
const pll_setup_t pll1Setup = {
109-
.pllctrl = SCG_SPLLCTRL_SOURCE(1U) | SCG_SPLLCTRL_SELI(27U) |
110-
SCG_SPLLCTRL_SELP(13U),
111-
.pllndiv = SCG_SPLLNDIV_NDIV(3U),
112-
.pllpdiv = SCG_SPLLPDIV_PDIV(1U),
113-
.pllmdiv = SCG_SPLLMDIV_MDIV(10U),
114-
.pllRate = 80000000U
115-
};
106+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(sai0)) || DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(sai1))
107+
/* < Set up PLL1 */
108+
const pll_setup_t pll1_Setup = {
109+
.pllctrl = SCG_SPLLCTRL_SOURCE(1U) | SCG_SPLLCTRL_SELI(3U) |
110+
SCG_SPLLCTRL_SELP(1U),
111+
.pllndiv = SCG_SPLLNDIV_NDIV(25U),
112+
.pllpdiv = SCG_SPLLPDIV_PDIV(10U),
113+
.pllmdiv = SCG_SPLLMDIV_MDIV(256U),
114+
.pllRate = 24576000U};
116115

117116
/* Configure PLL1 to the desired values */
118-
CLOCK_SetPLL1Freq(&pll1Setup);
119-
/* PLL1 Monitor is disabled */
120-
CLOCK_SetPll1MonitorMode(kSCG_Pll1MonitorDisable);
117+
CLOCK_SetPLL1Freq(&pll1_Setup);
121118
/* Set PLL1 CLK0 divider to value 1 */
122119
CLOCK_SetClkDiv(kCLOCK_DivPLL1Clk0, 1U);
123120
#endif
@@ -216,7 +213,7 @@ void board_early_init_hook(void)
216213

217214
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan1))
218215
CLOCK_SetClkDiv(kCLOCK_DivFlexcan1Clk, 1U);
219-
CLOCK_AttachClk(kPLL1_CLK0_to_FLEXCAN1);
216+
CLOCK_AttachClk(kFRO_HF_to_FLEXCAN1);
220217
#endif
221218

222219
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(vref))
@@ -330,6 +327,18 @@ void board_early_init_hook(void)
330327
CLOCK_EnableClock(kCLOCK_Ewm0);
331328
#endif
332329

330+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(sai0))
331+
CLOCK_SetClkDiv(kCLOCK_DivSai0Clk, 1u);
332+
CLOCK_AttachClk(kPLL1_CLK0_to_SAI0);
333+
CLOCK_EnableClock(kCLOCK_Sai0);
334+
#endif
335+
336+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(sai1))
337+
CLOCK_SetClkDiv(kCLOCK_DivSai1Clk, 1u);
338+
CLOCK_AttachClk(kPLL1_CLK0_to_SAI1);
339+
CLOCK_EnableClock(kCLOCK_Sai1);
340+
#endif
341+
333342
/* Set SystemCoreClock variable. */
334343
SystemCoreClock = CLOCK_INIT_CORE_CLOCK;
335344
}

boards/nxp/frdm_mcxn236/frdm_mcxn236-pinctrl.dtsi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,29 @@
207207
input-enable;
208208
};
209209
};
210+
211+
pinmux_sai0: pinmux_sai0 {
212+
group0 {
213+
pinmux = <SAI0_TXD0_PIO3_10>,
214+
<SAI0_TX_BCLK_PIO3_8>,
215+
<SAI0_TX_FS_PIO3_9>;
216+
drive-strength = "high";
217+
slew-rate = "fast";
218+
input-enable;
219+
};
220+
};
221+
222+
pinmux_sai1: pinmux_sai1 {
223+
group0 {
224+
pinmux = <SAI1_TX_BCLK_PIO3_16>,
225+
<SAI1_TX_FS_PIO3_17>,
226+
<SAI1_TXD0_PIO2_8>,
227+
<SAI1_RX_FS_PIO1_7>,
228+
<SAI1_RX_BCLK_PIO3_18>,
229+
<SAI1_RXD0_PIO2_9>;
230+
drive-strength = "high";
231+
slew-rate = "fast";
232+
input-enable;
233+
};
234+
};
210235
};

boards/nxp/frdm_mcxn236/frdm_mcxn236.dts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,15 @@ p3t1755dp_ard_i2c_interface: &flexcomm5_lpi2c5 {};
404404

405405
dvp_20pin_i2c: &flexcomm2_lpi2c2 {};
406406
dvp_20pin_interface: &video_sdma {};
407+
408+
&sai0 {
409+
status = "okay";
410+
pinctrl-0 = <&pinmux_sai0>;
411+
pinctrl-names = "default";
412+
};
413+
414+
&sai1 {
415+
status = "okay";
416+
pinctrl-0 = <&pinmux_sai1>;
417+
pinctrl-names = "default";
418+
};

boards/nxp/frdm_mcxn236/frdm_mcxn236.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ supported:
2121
- flash
2222
- gpio
2323
- i2c
24+
- i2s
2425
- i3c
2526
- pwm
2627
- regulator

dts/arm/nxp/nxp_mcxn23x_common.dtsi

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,40 @@
924924
interrupts = <100 0>;
925925
clk-divider = <0x0>;
926926
};
927+
928+
sai0: sai@106000 {
929+
compatible = "nxp,mcux-i2s";
930+
#address-cells = <1>;
931+
#size-cells = <0>;
932+
#pinmux-cells = <2>;
933+
reg = < 0x106000 0x1000>;
934+
clocks = <&syscon MCUX_SAI0_CLK>;
935+
pinmuxes = <&sai0 0x100 0x40000000>;
936+
interrupts = <59 0>;
937+
dmas = <&edma0 0 99>, <&edma0 0 100>;
938+
dma-names = "rx", "tx";
939+
nxp,tx-channel = <1>;
940+
nxp,tx-dma-channel = <0>;
941+
nxp,rx-dma-channel = <1>;
942+
status = "disabled";
943+
};
944+
945+
sai1: sai@107000 {
946+
compatible = "nxp,mcux-i2s";
947+
#address-cells = <1>;
948+
#size-cells = <0>;
949+
#pinmux-cells = <2>;
950+
reg = < 0x107000 0x1000>;
951+
clocks = <&syscon MCUX_SAI1_CLK>;
952+
pinmuxes = <&sai1 0x100 0x40000000>;
953+
interrupts = <60 0>;
954+
dmas = <&edma0 0 101>, <&edma0 0 102>;
955+
dma-names = "rx", "tx";
956+
nxp,tx-channel = <1>;
957+
nxp,tx-dma-channel = <2>;
958+
nxp,rx-dma-channel = <3>;
959+
status = "disabled";
960+
};
927961
};
928962

929963
&systick {

tests/drivers/i2s/i2s_api/testcase.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tests:
1212
- mimxrt685_evk/mimxrt685s/cm33
1313
- nrf54h20dk/nrf54h20/cpuapp
1414
- mimxrt1060_evk/mimxrt1062/qspi
15+
- frdm_mcxn236/mcxn236
1516
drivers.i2s.gpio_loopback:
1617
depends_on:
1718
- i2s
@@ -27,6 +28,7 @@ tests:
2728
- mimxrt595_evk/mimxrt595s/cm33
2829
- mimxrt685_evk/mimxrt685s/cm33
2930
- nrf54h20dk/nrf54h20/cpuapp
31+
- frdm_mcxn236/mcxn236
3032
harness_config:
3133
fixture: gpio_loopback
3234
drivers.i2s.gpio_loopback.nrf54h:

tests/drivers/i2s/i2s_speed/Readme.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ These are the HW changes required to run this test on MIMXRT1060-EVK[B/C]:
4646

4747
- NOTE: these connections cause contention with the following signals/features:
4848
- camera CSI_D[2-7]
49+
50+
FRDM-MCXN236:
51+
This board uses CONFIG_I2S_TEST_SEPARATE_DEVICES=y and connects two SAI peripherals by shorting
52+
signals externally on the EVK. These are the HW changes required to run this test:
53+
- Short BCLK J1-pin9 (SAI1_RX_BCLK/P3_18) to J8-pin25 (SAI0_TX_BCLK/P3_8)
54+
- Short SYNC J1-pin13 (SAI1_RX_FS/P1_7) to J8-pin26 (SAI0_TX_FS/P3_9)
55+
- Short Data J1-pin15 (SAI1_RXD0/P2_9) to J8-pin27 (SAI0_TXD0/P3_10)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) 2024, NXP
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
# SAI peripheral does not have loopback mode. Use 2 SAI peripherals connected
8+
# together externally.
9+
CONFIG_I2S_TEST_SEPARATE_DEVICES=y
10+
11+
# CONFIG_DMA_TCD_QUEUE_SIZE sets size of queue used to chain DMA blocks (TCDs)
12+
# together, and should be sized as needed by the application. If not large
13+
# enough, the DMA may starve. Symptoms of this issue include transmit blocks
14+
# repeated, or RX blocks skipped. For I2S driver, queue size must be at least 3.
15+
CONFIG_DMA_TCD_QUEUE_SIZE=4
16+
17+
# Repeat test continually to help find intermittent issues
18+
CONFIG_ZTEST_RETEST_IF_PASSED=y
19+
20+
# I2S and DMA logging can occur in interrupt context, and interfere with I2S
21+
# stream timing. If using either logging, set logging to deferred
22+
# CONFIG_LOG_MODE_DEFERRED=y
23+
24+
CONFIG_DMA_LOG_LEVEL_OFF=y
25+
CONFIG_I2S_LOG_LEVEL_OFF=y
26+
CONFIG_I2S_TEST_USE_GPIO_LOOPBACK=y
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* i2s_speed with CONFIG_I2S_TEST_SEPARATE_DEVICES=y uses two I2S peripherals:
2+
* i2s-node0 is the receiver
3+
* i2s-node1 is the transmitter
4+
*/
5+
6+
/ {
7+
aliases {
8+
i2s-node0 = &sai1;
9+
i2s-node1 = &sai0;
10+
};
11+
};
12+
13+
&sai0 {
14+
mclk-output;
15+
};

0 commit comments

Comments
 (0)