Skip to content

Commit 1f958b9

Browse files
committed
variants: migrate FRDM-MCXN947 to connector-based pin configuration
Define the Arduino header and its ADC and PWM mappings using connector nodes. Enable ADC and PWM support and remove the legacy digital-pin-gpios configuration. Use arduino_serial, arduino_i2c, and arduino_spi aliases for the peripherals exposed through the Arduino header. This changes Serial1 from LPUART4 to LPUART2. The connector definitions are based on the newer Zephyr board configuration and can be removed when the bundled Zephyr version is updated. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 1f05f46 commit 1f958b9

2 files changed

Lines changed: 171 additions & 5 deletions

File tree

variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ CONFIG_BUILD_OUTPUT_HEX=y
66
CONFIG_BUILD_NO_GAP_FILL=y
77

88
CONFIG_FLASH=y
9+
CONFIG_ADC=y
10+
CONFIG_PWM=y
911

1012
#CONFIG_USB_DC_NXP_EHCI=y
1113
CONFIG_USB_DEVICE_STACK=y

variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.overlay

Lines changed: 169 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <zephyr/dt-bindings/gpio/arduino-header-r3.h>
8+
#include <zephyr/dt-bindings/adc/adc.h>
9+
#include <zephyr/dt-bindings/adc/mcux-lpadc.h>
10+
711
&zephyr_udc0 {
812
status = "okay";
913
board_cdc_acm_uart: board_cdc_acm_uart {
@@ -26,11 +30,171 @@
2630

2731
/ {
2832
zephyr,user {
29-
digital-pin-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>, <&gpio0 27 GPIO_ACTIVE_LOW>, <&gpio1 2 GPIO_ACTIVE_LOW>;
30-
builtin-led-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>, <&gpio0 27 GPIO_ACTIVE_LOW>, <&gpio1 2 GPIO_ACTIVE_LOW>;
3133
cdc-acm-serial = <&board_cdc_acm_uart>; /* 'Serial' object is managed by SerialUSB */
32-
serials = <&flexcomm4_lpuart4>; /* 'Serial1' onwards */
33-
i2cs = <&flexcomm2_lpi2c2>;
34-
spis = <&flexcomm1_lpspi1>;
34+
};
35+
36+
arduino_header: arduino-connector {
37+
compatible = "arduino-header-r3";
38+
#gpio-cells = <2>;
39+
gpio-map-mask = <0xffffffff 0xffffffc0>;
40+
gpio-map-pass-thru = <0 0x3f>;
41+
gpio-map = <ARDUINO_HEADER_R3_A2 0 &gpio0 14 0>,
42+
<ARDUINO_HEADER_R3_A3 0 &gpio0 22 0>,
43+
<ARDUINO_HEADER_R3_A4 0 &gpio0 15 0>,
44+
<ARDUINO_HEADER_R3_A5 0 &gpio0 23 0>,
45+
<ARDUINO_HEADER_R3_D0 0 &gpio4 3 0>, /* RX */
46+
<ARDUINO_HEADER_R3_D1 0 &gpio4 2 0>, /* TX */
47+
<ARDUINO_HEADER_R3_D2 0 &gpio0 29 0>,
48+
<ARDUINO_HEADER_R3_D3 0 &gpio1 23 0>,
49+
<ARDUINO_HEADER_R3_D4 0 &gpio0 30 0>,
50+
<ARDUINO_HEADER_R3_D5 0 &gpio1 21 0>,
51+
<ARDUINO_HEADER_R3_D6 0 &gpio1 2 0>,
52+
<ARDUINO_HEADER_R3_D7 0 &gpio0 31 0>,
53+
<ARDUINO_HEADER_R3_D8 0 &gpio0 28 0>,
54+
<ARDUINO_HEADER_R3_D9 0 &gpio0 10 0>,
55+
<ARDUINO_HEADER_R3_D10 0 &gpio0 27 0>, /* CS */
56+
<ARDUINO_HEADER_R3_D11 0 &gpio0 24 0>, /* MOSI */
57+
<ARDUINO_HEADER_R3_D12 0 &gpio0 26 0>, /* MISO */
58+
<ARDUINO_HEADER_R3_D13 0 &gpio0 25 0>, /* SCK */
59+
<ARDUINO_HEADER_R3_D14 0 &gpio4 0 0>, /* SDA */
60+
<ARDUINO_HEADER_R3_D15 0 &gpio4 1 0>; /* SCL */
61+
};
62+
63+
/*
64+
* Arduino analog header A2..A5 -> LPADC0 (per FRDM-MCXN947 mapping):
65+
* A2 = PIO0_14 = ADC0_B14 A3 = PIO0_22 = ADC0_A14
66+
* A4 = PIO0_15 = ADC0_B15 A5 = PIO0_23 = ADC0_A15
67+
* A0/A1 are not routed to ADC on this board's Arduino header.
68+
*/
69+
arduino_adc: analog-connector {
70+
compatible = "arduino,uno-adc";
71+
#io-channel-cells = <1>;
72+
io-channel-map = <ARDUINO_HEADER_R3_A2 &lpadc0 0>,
73+
<ARDUINO_HEADER_R3_A3 &lpadc0 1>,
74+
<ARDUINO_HEADER_R3_A4 &lpadc0 2>,
75+
<ARDUINO_HEADER_R3_A5 &lpadc0 3>;
76+
};
77+
78+
/*
79+
* Arduino PWM pins on FRDM-MCXN947 (classic D3/D5/D6/D9, none of which
80+
* overlap the I2C/SPI/UART pins). D6/D9 are also the on-board blue/red
81+
* LEDs (disabled by default), so analogWrite() fades those LEDs.
82+
* D3 = PIO1_23 = SCT0_OUT5 D5 = PIO1_21 = SCT0_OUT9
83+
* D6 = PIO1_2 = CT1_MAT0 D9 = PIO0_10 = CT0_MAT0
84+
*/
85+
arduino_pwm: pwm-connector {
86+
compatible = "arduino-header-pwm";
87+
#pwm-cells = <3>;
88+
pwm-map-mask = <0xffffffff 0x0 0x0>;
89+
pwm-map-pass-thru = <0x0 0xffffffff 0xffffffff>;
90+
pwm-map = <ARDUINO_HEADER_R3_D3 0 0 &sc_timer 5 0 0>,
91+
<ARDUINO_HEADER_R3_D5 0 0 &sc_timer 9 0 0>,
92+
<ARDUINO_HEADER_R3_D6 0 0 &ctimer1_pwm 0 0 0>,
93+
<ARDUINO_HEADER_R3_D9 0 0 &ctimer0_pwm 0 0 0>;
3594
};
3695
};
96+
97+
&lpadc0 {
98+
#address-cells = <1>;
99+
#size-cells = <0>;
100+
101+
channel@0 { /* A2 */
102+
reg = <0>;
103+
zephyr,gain = "ADC_GAIN_1";
104+
zephyr,reference = "ADC_REF_EXTERNAL0";
105+
zephyr,vref-mv = <3300>;
106+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
107+
zephyr,resolution = <12>;
108+
zephyr,input-positive = <MCUX_LPADC_CH14B>;
109+
};
110+
111+
channel@1 { /* A3 */
112+
reg = <1>;
113+
zephyr,gain = "ADC_GAIN_1";
114+
zephyr,reference = "ADC_REF_EXTERNAL0";
115+
zephyr,vref-mv = <3300>;
116+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
117+
zephyr,resolution = <12>;
118+
zephyr,input-positive = <MCUX_LPADC_CH14A>;
119+
};
120+
121+
channel@2 { /* A4 */
122+
reg = <2>;
123+
zephyr,gain = "ADC_GAIN_1";
124+
zephyr,reference = "ADC_REF_EXTERNAL0";
125+
zephyr,vref-mv = <3300>;
126+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
127+
zephyr,resolution = <12>;
128+
zephyr,input-positive = <MCUX_LPADC_CH15B>;
129+
};
130+
131+
channel@3 { /* A5 */
132+
reg = <3>;
133+
zephyr,gain = "ADC_GAIN_1";
134+
zephyr,reference = "ADC_REF_EXTERNAL0";
135+
zephyr,vref-mv = <3300>;
136+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
137+
zephyr,resolution = <12>;
138+
zephyr,input-positive = <MCUX_LPADC_CH15A>;
139+
};
140+
};
141+
142+
/* PWM pin routing for the arduino_pwm connector */
143+
&pinctrl {
144+
pinmux_ctimer0_arduino: pinmux_ctimer0_arduino {
145+
group0 {
146+
pinmux = <CT0_MAT0_PIO0_10>; /* D9 */
147+
slew-rate = "fast";
148+
drive-strength = "low";
149+
};
150+
};
151+
152+
pinmux_ctimer1_arduino: pinmux_ctimer1_arduino {
153+
group0 {
154+
pinmux = <CT1_MAT0_PIO1_2>; /* D6 */
155+
slew-rate = "fast";
156+
drive-strength = "low";
157+
};
158+
};
159+
160+
pinmux_sctimer_arduino: pinmux_sctimer_arduino {
161+
group0 {
162+
pinmux = <SCT0_OUT5_PIO1_23>, /* D3 */
163+
<SCT0_OUT9_PIO1_21>; /* D5 */
164+
slew-rate = "fast";
165+
drive-strength = "low";
166+
};
167+
};
168+
};
169+
170+
ctimer0_pwm: &ctimer0 {
171+
compatible = "nxp,ctimer-pwm";
172+
status = "okay";
173+
clk-source = <1>;
174+
clocks = <&syscon MCUX_CTIMER0_CLK>;
175+
prescaler = <0>;
176+
pinctrl-0 = <&pinmux_ctimer0_arduino>;
177+
pinctrl-names = "default";
178+
#pwm-cells = <3>;
179+
};
180+
181+
ctimer1_pwm: &ctimer1 {
182+
compatible = "nxp,ctimer-pwm";
183+
status = "okay";
184+
clk-source = <1>;
185+
clocks = <&syscon MCUX_CTIMER1_CLK>;
186+
prescaler = <0>;
187+
pinctrl-0 = <&pinmux_ctimer1_arduino>;
188+
pinctrl-names = "default";
189+
#pwm-cells = <3>;
190+
};
191+
192+
&sc_timer {
193+
status = "okay";
194+
pinctrl-0 = <&pinmux_sctimer_arduino>;
195+
pinctrl-names = "default";
196+
};
197+
198+
arduino_spi: &flexcomm1_lpspi1 {};
199+
arduino_i2c: &flexcomm2_lpi2c2 {};
200+
arduino_serial: &flexcomm2_lpuart2 {};

0 commit comments

Comments
 (0)