diff --git a/bsp/nxp/mcx/mcxa/Libraries/drivers/drv_pin.h b/bsp/nxp/mcx/mcxa/Libraries/drivers/drv_pin.h index 8b0fa056ae9..14745d6581d 100644 --- a/bsp/nxp/mcx/mcxa/Libraries/drivers/drv_pin.h +++ b/bsp/nxp/mcx/mcxa/Libraries/drivers/drv_pin.h @@ -16,7 +16,7 @@ #include #include - +#define GET_PINS(PORTx, PINx) (32 * PORTx + PINx) extern int rt_hw_pin_init(void); #endif /* __DRV_PIN_H__ */ diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/.cl/attachconfig/RTduino.attach b/bsp/nxp/mcx/mcxa/frdm-mcxa346/.cl/attachconfig/RTduino.attach new file mode 100644 index 00000000000..b546b5f2c7a --- /dev/null +++ b/bsp/nxp/mcx/mcxa/frdm-mcxa346/.cl/attachconfig/RTduino.attach @@ -0,0 +1,14 @@ +CONFIG_PKG_USING_RTDUINO=y +CONFIG_PKG_RTDUINO_PATH="/packages/arduino/RTduino" +CONFIG_RTDUINO_THREAD_SIZE=2048 +CONFIG_RTDUINO_THREAD_PRIO=30 +CONFIG_RTDUINO_SUPPORT_HIGH_PRECISION_MICROS=y +CONFIG_PKG_USING_RTDUINO_LATEST_VERSION=y +CONFIG_PKG_RTDUINO_VER="latest" +CONFIG_BSP_USING_I2C=y +CONFIG_BSP_USING_I2C3=y +CONFIG_BSP_USING_SPI=y +CONFIG_BSP_USING_SPI1=y +CONFIG_BSP_USING_ADC=y +CONFIG_BSP_USING_PWM=y +CONFIG_BSP_USING_ARDUINO=y \ No newline at end of file diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/SConscript b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/SConscript index f11833c8d8d..b214b5a3f1d 100644 --- a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/SConscript +++ b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/SConscript @@ -7,6 +7,9 @@ src = Glob('*.c') group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) +if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']): + src += ['arduino_main.cpp'] + list = os.listdir(cwd) for item in list: if os.path.isfile(os.path.join(cwd, item, 'SConscript')): diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_main.cpp b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_main.cpp new file mode 100644 index 00000000000..c195831a77a --- /dev/null +++ b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_main.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-12-08 westcity-yolo first version + * + */ + +#include + +void setup(void) +{ + /* put your setup code here, to run once: */ + Serial.begin(); + Serial.println("Hello RTduino!"); +} + +void loop(void) +{ + /* put your main code here, to run repeatedly: */ + delay(1000); +} \ No newline at end of file diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/RTduino-peripherals.png b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/RTduino-peripherals.png new file mode 100644 index 00000000000..3e3e41a6c46 Binary files /dev/null and b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/RTduino-peripherals.png differ diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/SConscript b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/SConscript new file mode 100644 index 00000000000..da85e053c37 --- /dev/null +++ b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/SConscript @@ -0,0 +1,9 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') + Glob('*.cpp') +inc = [cwd] + +group = DefineGroup('RTduino-pinout', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc) + +Return('group') diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/frdm-mcxa346-pinout1.jpg b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/frdm-mcxa346-pinout1.jpg new file mode 100644 index 00000000000..0c8fbc1043c Binary files /dev/null and b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/frdm-mcxa346-pinout1.jpg differ diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/frdm-mcxa346-pinout2.jpg b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/frdm-mcxa346-pinout2.jpg new file mode 100644 index 00000000000..b282d62ccd1 Binary files /dev/null and b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/frdm-mcxa346-pinout2.jpg differ diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/pins_arduino.c b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/pins_arduino.c new file mode 100644 index 00000000000..b040b77cdbc --- /dev/null +++ b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/pins_arduino.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-12-08 westcity-yolo first version + * + */ + +#include +#include +#include +#include "pins_arduino.h" + +/* + * {Arduino Pin, RT-Thread Pin [, Device Name, Channel]} + * [] means optional + * Digital pins must NOT give the device name and channel. + * Analog pins MUST give the device name and channel(ADC, PWM or DAC). + * Arduino Pin must keep in sequence. + */ +const pin_map_t pin_map_table[]= +{ + {D0, GET_PINS(2,3), "uart2"}, /* Serial2-RX */ + {D1, GET_PINS(2,2), "uart2"}, /* Serial2-TX */ + {D2, GET_PINS(3,31)}, + {D3, GET_PINS(3,14), "pwm1", 1}, /* PWM */ + {D4, GET_PINS(4,7)}, + {D5, GET_PINS(3,1), "pwm0", 0}, /* PWM */ + {D6, GET_PINS(3,17), "pwm1", 0}, /* PWM */ + {D7, GET_PINS(3,22)}, + {D8, GET_PINS(4,3)}, + {D9, GET_PINS(3,13), "pwm1", 2}, /* PWM */ + {D10, GET_PINS(3,11),"spi1"}, /* SPI-SS */ + {D11, GET_PINS(3,8), "spi1"}, /* SPI-SDO */ + {D12, GET_PINS(3,9), "spi1"}, /* SPI-SDI */ + {D13, GET_PINS(3,10),"spi1"}, /* SPI-SCK */ + {D18, GET_PINS(1,8),"i2c2"}, /* I2C-SDA (Wire) */ + {D19, GET_PINS(1,9),"i2c2"}, /* I2C-SCL (Wire) */ + {A0, GET_PINS(1,14),"adc1", 12}, /* ADC */ + {A1, GET_PINS(2,5), "adc1", 1}, /* ADC */ + {A2, GET_PINS(2,7),"adc0", 7}, /* ADC */ + {A3, GET_PINS(3,30),"adc1", 21}, + {A4, GET_PINS(1,0),"i2c1"}, /* I2C-SDA (Wire) */ + {A5, GET_PINS(1,1),"i2c1"}, /* I2C-SCL (Wire) */ + +}; \ No newline at end of file diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/pins_arduino.h b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/pins_arduino.h new file mode 100644 index 00000000000..afb824ddf97 --- /dev/null +++ b/bsp/nxp/mcx/mcxa/frdm-mcxa346/applications/arduino_pinout/pins_arduino.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-12-08 westcity-yolo first version + * + */ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + + + +/* pins alias. Must keep in sequence */ +#define D0 (0) +#define D1 (1) +#define D2 (2) +#define D3 (3) +#define D4 (4) +#define D5 (5) +#define D6 (6) +#define D7 (7) +#define D8 (8) +#define D9 (9) +#define D10 (10) +#define D11 (11) +#define D12 (12) +#define D13 (13) +#define D18 (14) +#define D19 (15) + +#define A0 (16) +#define A1 (17) +#define A2 (18) +#define A3 (19) +#define A4 (20) +#define A5 (21) +#define A6 (22) +#define A7 (23) + +#define RTDUINO_PIN_MAX_LIMIT A7 /* pin number max limit check */ + +#define F_CPU 180000000L /* CPU:180MHz */ + +/* i2c2 : P(,1_8-SDA P(,1_9-SCL */ +#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c2" + +/* Serial2 : P(,2_2-TX P(,2_3-RX */ +#define RTDUINO_SERIAL2_DEVICE_NAME "uart2" + +/* spi1 : P(,3_8-SDO P(,3_9-SDI P(,3_10-SCK P(,3_11-SS */ + +#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi1" + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/bsp/nxp/mcx/mcxa/frdm-mcxa346/board/Kconfig b/bsp/nxp/mcx/mcxa/frdm-mcxa346/board/Kconfig index b4fbf9377c0..aefe7b556db 100644 --- a/bsp/nxp/mcx/mcxa/frdm-mcxa346/board/Kconfig +++ b/bsp/nxp/mcx/mcxa/frdm-mcxa346/board/Kconfig @@ -123,6 +123,24 @@ menu "On-chip Peripheral Drivers" endif endmenu +menu "Onboard Peripheral Drivers" + config BSP_USING_ARDUINO + bool "Compatible with Arduino Ecosystem (RTduino)" + select PKG_USING_RTDUINO + select BSP_USING_UART2 + select BSP_USING_GPIO + select BSP_USING_PWM + select BSP_USING_ADC + select BSP_USING_ADC0 + select BSP_USING_ADC1 + select BSP_USING_I2C + select BSP_USING_I2C1 + select BSP_USING_I2C2 + select BSP_USING_SPI + select BSP_USING_SPI1 + default n + endmenu + menu "Board extended module Drivers" menuconfig BSP_USING_RW007