Skip to content

Commit 1bcd5c8

Browse files
authored
修复MCXN947开发板arduino接口中的串口无法使用以及串口再配置后无法收到数据的问题.
1 parent 4e5c1cf commit 1bcd5c8

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

bsp/nxp/mcx/mcxn/Libraries/drivers/drv_uart.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static rt_err_t mcx_configure(struct rt_serial_device *serial, struct serial_con
133133
{
134134
struct mcx_uart *uart; /* Serial port hardware structure, calling the structure initialized above */
135135
lpuart_config_t config;/* It contains basic configuration parameters of the serial port, such as baud rate, data bit, stop bit, and parity check */
136+
rt_uint32_t irq_regval;
136137

137138
RT_ASSERT(serial != RT_NULL); /* assert */
138139
RT_ASSERT(cfg != RT_NULL);
@@ -159,8 +160,14 @@ static rt_err_t mcx_configure(struct rt_serial_device *serial, struct serial_con
159160

160161
config.enableTx = true;
161162
config.enableRx = true;
162-
163+
164+
irq_regval = LPUART_GetEnabledInterrupts(uart->uart_base);
163165
LPUART_Init(uart->uart_base, &config, CLOCK_GetFreq(uart->clock_src));
166+
if(irq_regval & kLPUART_RxDataRegFullInterruptEnable)
167+
{
168+
LPUART_EnableInterrupts(uart->uart_base, kLPUART_RxDataRegFullInterruptEnable);
169+
EnableIRQ(uart->irqn);
170+
}
164171

165172
return RT_EOK;
166173
}

bsp/nxp/mcx/mcxn/frdm-mcxn947/board/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if GetDepend(['PKG_USING_CJSON']) and GetDepend(['PKG_USING_WEBCLIENT']):
2424

2525

2626
CPPPATH = [cwd, cwd + '/MCUX_Config/board']
27-
CPPDEFINES = ['DEBUG', 'CPU_MCXN947VDF_cm33_core0']
27+
CPPDEFINES = ['DEBUG', 'CPU_MCXN947VDF_cm33_core0', 'LPFLEXCOMM_INIT_NOT_USED_IN_DRIVER=1']
2828

2929
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
3030

bsp/nxp/mcx/mcxn/frdm-mcxn947/board/board.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,57 @@ void SysTick_Handler(void)
3434
rt_interrupt_leave();
3535
}
3636

37+
/**
38+
* This function will initial the FlexComm mode.
39+
* +--------+----------------+--------+--------+--------------+
40+
* | Signal | LPSPI | LPUART | LPI2C | LPUART+LPI2C |
41+
* +--------+----------------+--------+--------+--------------+
42+
* | FC_P0 | SDO/DATA[0] | RXD | SDA | SDA |
43+
* | FC_P1 | SCK | TXD | SCL | SCL |
44+
* | FC_P2 | SDI/DATA[1] | RTS_b | SCLS | TXD |
45+
* | FC_P3 | PCS[0] | CTS_b | SDAS | RXD |
46+
* | FC_P4 | PCS[3]/DATA[3] | DSR_b | HREQ_b | CTS_b |
47+
* | FC_P5 | PCS[2]/DATA[2] | DTR_b | — | RTS_b |
48+
* | FC_P6 | PCS[1]/HREQ | DCD_b | — | HREQ_b |
49+
* +--------+----------------+--------+--------+--------------+
50+
*/
51+
void rt_hw_flexcomm_mode_init(void)
52+
{
53+
#ifdef BSP_USING_UART2
54+
LP_FLEXCOMM_Init(2, LP_FLEXCOMM_PERIPH_LPI2CAndLPUART); /* FLEXCOMM2 used for LPI2C and LPUART */
55+
#endif
56+
#ifdef BSP_USING_UART4
57+
LP_FLEXCOMM_Init(4, LP_FLEXCOMM_PERIPH_LPUART); /* FLEXCOMM4 used for LPUART */
58+
#endif
59+
#ifdef BSP_USING_UART5
60+
LP_FLEXCOMM_Init(5, LP_FLEXCOMM_PERIPH_LPUART); /* FLEXCOMM5 used for LPUART */
61+
#endif
62+
#ifdef BSP_USING_UART6
63+
LP_FLEXCOMM_Init(6, LP_FLEXCOMM_PERIPH_LPUART); /* FLEXCOMM6 used for LPUART */
64+
#endif
65+
#ifdef BSP_USING_SPI1
66+
LP_FLEXCOMM_Init(2, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM2 used for LPI2C and LPUART */
67+
#endif
68+
#ifdef BSP_USING_SPI3
69+
LP_FLEXCOMM_Init(3, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM3 used for LPSPI */
70+
#endif
71+
#ifdef BSP_USING_SPI6
72+
LP_FLEXCOMM_Init(6, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM6 used for LPSPI */
73+
#endif
74+
#ifdef BSP_USING_SPI7
75+
LP_FLEXCOMM_Init(7, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM7 used for LPSPI */
76+
#endif
77+
#ifdef BSP_USING_I2C0
78+
LP_FLEXCOMM_Init(0, LP_FLEXCOMM_PERIPH_LPI2C); /* FLEXCOMM0 used for LPI2C */
79+
#endif
80+
#ifdef BSP_USING_I2C1
81+
LP_FLEXCOMM_Init(1, LP_FLEXCOMM_PERIPH_LPI2C); /* FLEXCOMM1 used for LPI2C */
82+
#endif
83+
#ifdef BSP_USING_I2C2
84+
LP_FLEXCOMM_Init(2, LP_FLEXCOMM_PERIPH_LPI2C); /* FLEXCOMM2 used for LPI2C */
85+
#endif
86+
}
87+
3788
/**
3889
* This function will initial board.
3990
*/

0 commit comments

Comments
 (0)