From 93361c31f07030631934d3950123022a76066867 Mon Sep 17 00:00:00 2001 From: Yaochenger <75192526+Yaochenger@users.noreply.github.com> Date: Fri, 7 Apr 2023 18:56:51 +0800 Subject: [PATCH] =?UTF-8?q?[RT1060][SPI]=E5=AE=8C=E5=96=84SPI=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E5=AE=8C=E5=96=84SPI=E5=AF=B9RW007=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20(#7193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [RT1060][SPI]添加SPI支持,并完善RW007支持 --- bsp/imxrt/imxrt1060-nxp-evk/board/Kconfig | 36 +++++++++++++++++++++++ bsp/imxrt/imxrt1060-nxp-evk/board/board.c | 18 ++++++++++++ bsp/imxrt/libraries/drivers/drv_spi.c | 8 ++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/bsp/imxrt/imxrt1060-nxp-evk/board/Kconfig b/bsp/imxrt/imxrt1060-nxp-evk/board/Kconfig index 6dbbb2f124..637d4ce744 100644 --- a/bsp/imxrt/imxrt1060-nxp-evk/board/Kconfig +++ b/bsp/imxrt/imxrt1060-nxp-evk/board/Kconfig @@ -164,6 +164,10 @@ endmenu menu "On-chip Peripheral Drivers" + config BSP_USING_DMA + bool "Enable DMA" + default n + config BSP_USING_GPIO bool "Enable GPIO" select RT_USING_PIN @@ -254,6 +258,38 @@ menu "On-chip Peripheral Drivers" default n endif + menuconfig BSP_USING_SPI + bool "Enable SPI" + select RT_USING_SPI + select RT_USING_PIN + default n + + if BSP_USING_SPI + config BSP_USING_SPI1 + bool "Enable SPI1" + default n + + config BSP_USING_BLOCKING_SPI + bool "Enable SPI Polling xfer" + default n + + config BSP_SPI1_USING_DMA + bool "Enable SPI1 DMA xfer" + depends on BSP_USING_SPI1 + select BSP_USING_DMA + default n + + config BSP_SPI1_RX_DMA_CHANNEL + depends on BSP_SPI1_USING_DMA + int "Set SPI1 RX DMA channel (0-32)" + default 0 + + config BSP_SPI1_TX_DMA_CHANNEL + depends on BSP_SPI1_USING_DMA + int "Set SPI1 TX DMA channel (0-32)" + default 1 + endif + config BSP_USING_PXP bool "Enable PXP" default n diff --git a/bsp/imxrt/imxrt1060-nxp-evk/board/board.c b/bsp/imxrt/imxrt1060-nxp-evk/board/board.c index 6c203ba5d9..7789888922 100644 --- a/bsp/imxrt/imxrt1060-nxp-evk/board/board.c +++ b/bsp/imxrt/imxrt1060-nxp-evk/board/board.c @@ -211,6 +211,20 @@ void imxrt_dma_init(void) } #endif +#ifdef BSP_USING_SPI +void imxrt_spi_pins_init(void) { + CLOCK_EnableClock(kCLOCK_Iomuxc); + + IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_00_LPSPI1_SCK, 0U); + IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_02_LPSPI1_SDO, 0U); + IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_03_LPSPI1_SDI, 0U); + + IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_00_LPSPI1_SCK,0x10B0); + IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_02_LPSPI1_SDO,0x10B0); + IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_03_LPSPI1_SDI,0x10B0); +} +#endif + #ifdef BSP_USING_LPUART void imxrt_uart_pins_init(void) { @@ -1211,6 +1225,10 @@ void rt_hw_board_init() rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); #endif +#ifdef BSP_USING_SPI + imxrt_spi_pins_init(); +#endif + #ifdef RT_USING_COMPONENTS_INIT rt_components_board_init(); #endif diff --git a/bsp/imxrt/libraries/drivers/drv_spi.c b/bsp/imxrt/libraries/drivers/drv_spi.c index 3c1ad39888..b53e45a0b5 100644 --- a/bsp/imxrt/libraries/drivers/drv_spi.c +++ b/bsp/imxrt/libraries/drivers/drv_spi.c @@ -246,6 +246,7 @@ static void lpspi_normal_config(struct imxrt_spi *spi) static void lpspi_dma_config(struct imxrt_spi *spi) { +#ifdef BSP_USING_DMA RT_ASSERT(spi != RT_NULL); DMAMUX_SetSource(DMAMUX, spi->dma->rx_channel, spi->dma->rx_request); @@ -264,6 +265,7 @@ static void lpspi_dma_config(struct imxrt_spi *spi) &spi->dma->tx_edma); LOG_D("%s dma config done\n", spi->bus_name); +#endif } static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg) @@ -362,13 +364,16 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * { #ifdef BSP_USING_BLOCKING_SPI status = LPSPI_MasterTransferBlocking(spi->base, &transfer); + rt_sem_release(spi->xfer_sem); #else status = LPSPI_MasterTransferNonBlocking(spi->base, &spi->spi_normal, &transfer); #endif } else { +#ifdef BSP_USING_DMA status = LPSPI_MasterTransferEDMA(spi->base,&spi->dma->spi_edma,&transfer); +#endif } rt_sem_take(spi->xfer_sem, RT_WAITING_FOREVER); @@ -404,7 +409,7 @@ int rt_hw_spi_bus_init(void) lpspis[i].spi_bus.parent.user_data = &lpspis[i]; ret = rt_spi_bus_register(&lpspis[i].spi_bus, lpspis[i].bus_name, &imxrt_spi_ops); - +#ifndef BSP_USING_BLOCKING_SPI if(RT_TRUE == lpspis[i].dma_flag) { lpspi_dma_config(&lpspis[i]); @@ -413,6 +418,7 @@ int rt_hw_spi_bus_init(void) { lpspi_normal_config(&lpspis[i]); } +#endif char sem_name[RT_NAME_MAX]; rt_sprintf(sem_name, "%s_s", lpspis[i].bus_name); lpspis[i].xfer_sem = rt_sem_create(sem_name, 0, RT_IPC_FLAG_PRIO);