Kaynağa Gözat

修复MCXN947开发板arduino接口中的串口无法使用以及串口再配置后无法收到数据的问题.

vandoul 1 gün önce
ebeveyn
işleme
1bcd5c8f16

+ 8 - 1
bsp/nxp/mcx/mcxn/Libraries/drivers/drv_uart.c

@@ -133,6 +133,7 @@ static rt_err_t mcx_configure(struct rt_serial_device *serial, struct serial_con
 {
     struct mcx_uart *uart; /* Serial port hardware structure, calling the structure initialized above */
     lpuart_config_t config;/* It contains basic configuration parameters of the serial port, such as baud rate, data bit, stop bit, and parity check */
+    rt_uint32_t irq_regval;
 
     RT_ASSERT(serial != RT_NULL); /* assert */
     RT_ASSERT(cfg != RT_NULL);
@@ -159,8 +160,14 @@ static rt_err_t mcx_configure(struct rt_serial_device *serial, struct serial_con
 
     config.enableTx     = true;
     config.enableRx     = true;
-
+    
+    irq_regval = LPUART_GetEnabledInterrupts(uart->uart_base);
     LPUART_Init(uart->uart_base, &config, CLOCK_GetFreq(uart->clock_src));
+    if(irq_regval & kLPUART_RxDataRegFullInterruptEnable)
+    {
+        LPUART_EnableInterrupts(uart->uart_base, kLPUART_RxDataRegFullInterruptEnable);
+        EnableIRQ(uart->irqn);
+    }
 
     return RT_EOK;
 }

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

@@ -24,7 +24,7 @@ if GetDepend(['PKG_USING_CJSON']) and GetDepend(['PKG_USING_WEBCLIENT']):
 
 
 CPPPATH = [cwd, cwd + '/MCUX_Config/board']
-CPPDEFINES = ['DEBUG', 'CPU_MCXN947VDF_cm33_core0']
+CPPDEFINES = ['DEBUG', 'CPU_MCXN947VDF_cm33_core0', 'LPFLEXCOMM_INIT_NOT_USED_IN_DRIVER=1']
 
 group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
 

+ 51 - 0
bsp/nxp/mcx/mcxn/frdm-mcxn947/board/board.c

@@ -34,6 +34,57 @@ void SysTick_Handler(void)
     rt_interrupt_leave();
 }
 
+/**
+ * This function will initial the FlexComm mode.
+ * +--------+----------------+--------+--------+--------------+
+ * | Signal | LPSPI          | LPUART | LPI2C  | LPUART+LPI2C |
+ * +--------+----------------+--------+--------+--------------+
+ * |  FC_P0 | SDO/DATA[0]    | RXD    | SDA    | SDA          |
+ * |  FC_P1 | SCK            | TXD    | SCL    | SCL          |
+ * |  FC_P2 | SDI/DATA[1]    | RTS_b  | SCLS   | TXD          |
+ * |  FC_P3 | PCS[0]         | CTS_b  | SDAS   | RXD          |
+ * |  FC_P4 | PCS[3]/DATA[3] | DSR_b  | HREQ_b | CTS_b        |
+ * |  FC_P5 | PCS[2]/DATA[2] | DTR_b  | —      | RTS_b        |
+ * |  FC_P6 | PCS[1]/HREQ    | DCD_b  | —      | HREQ_b       |
+ * +--------+----------------+--------+--------+--------------+
+ */
+void rt_hw_flexcomm_mode_init(void)
+{
+#ifdef BSP_USING_UART2
+    LP_FLEXCOMM_Init(2, LP_FLEXCOMM_PERIPH_LPI2CAndLPUART); /* FLEXCOMM2 used for LPI2C and LPUART */
+#endif
+#ifdef BSP_USING_UART4
+    LP_FLEXCOMM_Init(4, LP_FLEXCOMM_PERIPH_LPUART); /* FLEXCOMM4 used for LPUART */
+#endif
+#ifdef BSP_USING_UART5
+    LP_FLEXCOMM_Init(5, LP_FLEXCOMM_PERIPH_LPUART); /* FLEXCOMM5 used for LPUART */
+#endif
+#ifdef BSP_USING_UART6
+    LP_FLEXCOMM_Init(6, LP_FLEXCOMM_PERIPH_LPUART); /* FLEXCOMM6 used for LPUART */
+    #endif
+#ifdef BSP_USING_SPI1
+    LP_FLEXCOMM_Init(2, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM2 used for LPI2C and LPUART */
+#endif
+#ifdef BSP_USING_SPI3
+    LP_FLEXCOMM_Init(3, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM3 used for LPSPI */
+#endif
+#ifdef BSP_USING_SPI6
+    LP_FLEXCOMM_Init(6, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM6 used for LPSPI */
+#endif
+#ifdef BSP_USING_SPI7
+    LP_FLEXCOMM_Init(7, LP_FLEXCOMM_PERIPH_LPSPI); /* FLEXCOMM7 used for LPSPI */
+#endif
+#ifdef BSP_USING_I2C0
+    LP_FLEXCOMM_Init(0, LP_FLEXCOMM_PERIPH_LPI2C); /* FLEXCOMM0 used for LPI2C */
+#endif
+#ifdef BSP_USING_I2C1
+    LP_FLEXCOMM_Init(1, LP_FLEXCOMM_PERIPH_LPI2C); /* FLEXCOMM1 used for LPI2C */
+#endif
+#ifdef BSP_USING_I2C2
+    LP_FLEXCOMM_Init(2, LP_FLEXCOMM_PERIPH_LPI2C); /* FLEXCOMM2 used for LPI2C */
+#endif
+}
+
 /**
  * This function will initial board.
  */