Skip to content

Commit 3fbd23b

Browse files
authored
nxp bsp support: frdm-mcxa346 (#10625)
* update nxp mcxa driver to support frdm-mcxa346 * update NXP bsp README * update frdm-mcxa346 project
1 parent 0ef17c9 commit 3fbd23b

File tree

16 files changed

+1118
-277
lines changed

16 files changed

+1118
-277
lines changed

bsp/nxp/README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
1-
# NXP BSP 说明
1+
# NXP BSP 支持说明
22

3-
存放RT-Thread NXP BSP目录,目前支持MCX系列,之前一些老的IC支持(如LPC/Kinetis/I.MXRT)会逐步放到此目录下
3+
NXP 系列 BSP 目前支持情况如下表所示:
44

5-
| BSP 文件夹名称 | 开发板名称 |
6-
|:------------------------- |:-------------------------- |
7-
| mcxn | frdm-mcxn947 |
8-
| mcxa | frdm-mcxa153 |
5+
| **BSP 文件夹名称** | **开发板名称** |
6+
|:------------------------------------------------ |:----------------------------------- |
7+
| **MCXN 系列** | |
8+
| [frdm-mcxn947](mcx/mcxn/frdm-mcxn947) | NXP 官方 FRDM-MCXN947 开发板 |
9+
| [frdm-mcxn236](mcx/mcxn/frdm-mcxn236) | NXP 官方 FRDM-MCXN236 开发板 |
10+
| **MCXA 系列** | |
11+
| [frdm-mcxa153](mcx/mcxa/frdm-mcxa153) | NXP 官方 FRDM-MCXA153 开发板 |
12+
| [frdm-mcxa156](mcx/mcxa/frdm-mcxa156) | NXP 官方 FRDM-MCXA156 开发板 |
13+
| [frdm-mcxa346](mcx/mcxa/frdm-mcxa346) | NXP 官方 FRDM-MCXA346 开发板 |
14+
| [frdm-mcxa344](mcx/mcxa/frdm-mcxa344) | NXP 官方 FRDM-MCXA344 开发板 |
15+
| **MCXC 系列** | |
16+
| [frdm-mcxc444](mcx/mcxc/frdm-mcxc444) | NXP 官方 FRDM-MCXC444 开发板 |
17+
| **LPC 系列** | |
18+
| [lpc43xx](lpc/lpc43xx) | NXP LPC43xx 系列开发板 |
19+
| [lpc55sxx](lpc/lpc55sxx) | NXP LPC55Sxx 系列开发板 |
20+
| [lpc176x](lpc/lpc176x) | NXP LPC176x 系列开发板 |
21+
| [lpc178x](lpc/lpc178x) | NXP LPC178x 系列开发板 |
22+
| [lpc408x](lpc/lpc408x) | NXP LPC408x 系列开发板 |
23+
| [lpc824](lpc/lpc824) | NXP LPC824 开发板 |
24+
| [lpc1114](lpc/lpc1114) | NXP LPC1114 开发板 |
25+
| [lpc2148](lpc/lpc2148) | NXP LPC2148 开发板 |
26+
| [lpc2478](lpc/lpc2478) | NXP LPC2478 开发板 |
27+
| [lpc5410x](lpc/lpc5410x) | NXP LPC5410x 系列开发板 |
28+
| [lpc54114-lite](lpc/lpc54114-lite) | NXP LPC54114-Lite 开发板 |
29+
| [lpc54608-lpcxpresso](lpc/lpc54608-lpcxpresso) | NXP 官方 LPC54608-LPCXpresso 开发板 |
30+
31+
另外,我们还提供了一些热门开发板的上手说明:
32+
33+
* [NXP FRDM-MCXN947上手指南](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/tutorial/quick-start/frdm_mcxn947/quick-start)
34+
* [NXP FRDM-MCXA156上手指南](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/tutorial/quick-start/frdm_mcxa156/quick-start)
35+
36+
## 注意事项
37+
38+
- MCX 系列是 NXP 最新推出的 MCU 系列,具有高性能和低功耗特性
39+
- 部分老旧系列(LPC/Kinetis/i.MX RT)正在逐步迁移和更新中
40+
- 建议优先选择 MCX 系列进行新项目开发
41+
- 各系列 BSP 的具体支持功能请参考对应目录下的 README 文档

bsp/nxp/mcx/mcxa/Libraries/drivers/drv_adc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "fsl_lpadc.h"
1515
#include "fsl_spc.h"
1616

17+
#define DBG_TAG "drv.adc"
18+
#define DBG_LVL DBG_INFO
19+
#include <rtdbg.h>
20+
1721
#ifdef RT_USING_ADC
1822

1923
#define DEFAULT_HW_AVG (kLPADC_HardwareAverageCount4)

bsp/nxp/mcx/mcxa/Libraries/drivers/drv_i2c.c

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@
1616

1717
#ifdef RT_USING_I2C
1818

19+
#define DBG_TAG "drv.i2c"
20+
#define DBG_LVL DBG_INFO
21+
#include <rtdbg.h>
22+
1923
enum
2024
{
2125
#ifdef BSP_USING_I2C0
2226
I2C0_INDEX,
2327
#endif
28+
#ifdef BSP_USING_I2C1
29+
I2C1_INDEX,
30+
#endif
31+
#ifdef BSP_USING_I2C2
32+
I2C2_INDEX,
33+
#endif
34+
#ifdef BSP_USING_I2C3
35+
I2C3_INDEX,
36+
#endif
2437
};
2538

2639

27-
#define i2c_dbg rt_kprintf
28-
2940
struct lpc_i2c_bus
3041
{
3142
struct rt_i2c_bus_device parent;
@@ -44,12 +55,58 @@ struct lpc_i2c_bus lpc_obj[] =
4455
{
4556
.I2C = LPI2C0,
4657
.baud = 100000U,
58+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
59+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C0,
60+
#else
4761
.clock_attach_id = kFRO12M_to_LPI2C0,
62+
#endif
4863
.clock_div_name = kCLOCK_DivLPI2C0,
4964
.clock_src = kCLOCK_Fro12M,
5065
.name = "i2c0",
5166
},
5267
#endif
68+
#ifdef BSP_USING_I2C1
69+
{
70+
.I2C = LPI2C1,
71+
.baud = 100000U,
72+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
73+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C1,
74+
#else
75+
.clock_attach_id = kFRO12M_to_LPI2C1,
76+
#endif
77+
.clock_div_name = kCLOCK_DivLPI2C1,
78+
.clock_src = kCLOCK_Fro12M,
79+
.name = "i2c1",
80+
},
81+
#endif
82+
#ifdef BSP_USING_I2C2
83+
{
84+
.I2C = LPI2C2,
85+
.baud = 100000U,
86+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
87+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C2,
88+
#else
89+
.clock_attach_id = kFRO12M_to_LPI2C2,
90+
#endif
91+
.clock_div_name = kCLOCK_DivLPI2C2,
92+
.clock_src = kCLOCK_Fro12M,
93+
.name = "i2c2",
94+
},
95+
#endif
96+
#ifdef BSP_USING_I2C3
97+
{
98+
.I2C = LPI2C3,
99+
.baud = 100000U,
100+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
101+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C3,
102+
#else
103+
.clock_attach_id = kFRO12M_to_LPI2C3,
104+
#endif
105+
.clock_div_name = kCLOCK_DivLPI2C3,
106+
.clock_src = kCLOCK_Fro12M,
107+
.name = "i2c3",
108+
},
109+
#endif
53110
};
54111

55112
static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
@@ -80,7 +137,7 @@ static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
80137

81138
if (LPI2C_MasterTransferBlocking(lpc_i2c->I2C, &xfer) != kStatus_Success)
82139
{
83-
i2c_dbg("i2c bus read failed!\n");
140+
LOG_D("i2c bus read failed!\n");
84141
return i;
85142
}
86143
}
@@ -99,7 +156,7 @@ static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
99156

100157
if (LPI2C_MasterTransferBlocking(lpc_i2c->I2C, &xfer) != kStatus_Success)
101158
{
102-
i2c_dbg("i2c bus write failed!\n");
159+
LOG_D("i2c bus write failed!\n");
103160
return i;
104161
}
105162
}

bsp/nxp/mcx/mcxa/Libraries/drivers/drv_pin.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@
1717

1818
#ifdef RT_USING_PIN
1919

20+
#define DBG_TAG "drv.pin"
21+
#define DBG_LVL DBG_INFO
22+
#include <rtdbg.h>
2023

2124
#define GET_GPIO_PORT(x) ((x) / 32)
2225
#define GET_GPIO_PIN(x) ((x) % 32)
2326

2427
static struct rt_pin_ops mcx_pin_ops;
2528

26-
static GPIO_Type *GPIO_TYPE_TBL[] = {GPIO0, GPIO1, GPIO2, GPIO3};
27-
static PORT_Type *PORT_TYPE_TBL[] = {PORT0, PORT1, PORT2, PORT3};
28-
static IRQn_Type IRQ_TYPE_TBL[] = {GPIO0_IRQn, GPIO1_IRQn, GPIO2_IRQn, GPIO3_IRQn};
29+
static GPIO_Type *GPIO_TYPE_TBL[] = GPIO_BASE_PTRS;
30+
static PORT_Type *PORT_TYPE_TBL[] = PORT_BASE_PTRS;
31+
static IRQn_Type IRQ_TYPE_TBL[] = GPIO_IRQS;
2932

3033

3134
#define PIN2GPIO(x) GPIO_TYPE_TBL[GET_GPIO_PORT(x)]
3235
#define PIN2PORT(x) PORT_TYPE_TBL[GET_GPIO_PORT(x)]
3336
#define PIN2IRQ(x) IRQ_TYPE_TBL[GET_GPIO_PORT(x)]
3437

35-
struct rt_pin_irq_hdr pin_irq_hdr_tab[32*4] = {0};
38+
struct rt_pin_irq_hdr pin_irq_hdr_tab[32*5] = {0};
3639

3740
static void mcx_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode)
3841
{
@@ -143,6 +146,11 @@ void GPIO3_IRQHandler(void)
143146
pin_irq_handler(3);
144147
}
145148

149+
void GPIO4_IRQHandler(void)
150+
{
151+
pin_irq_handler(4);
152+
}
153+
146154

147155
static rt_err_t mcx_pin_attach_irq(struct rt_device *device, rt_base_t pin, rt_uint8_t mode, void (*hdr)(void *args), void *args)
148156
{

0 commit comments

Comments
 (0)