From 5cfa9c6390026284cee5a3cc8c5644085ab982a0 Mon Sep 17 00:00:00 2001 From: wdfk-prog <1425075683@qq.com> Date: Sun, 11 Jun 2023 23:06:15 +0800 Subject: [PATCH] =?UTF-8?q?[bsp][stm32][spi]=20=E4=BC=98=E5=8C=96H7=20DMA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9D=9E=E5=AD=97=E8=8A=82=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.c b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.c index ebfebbba42..8424bbf781 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.c +++ b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.c @@ -298,9 +298,13 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE)) { if (device->config.mode & RT_SPI_CS_HIGH) + { rt_pin_write(device->cs_pin, PIN_HIGH); + } else + { rt_pin_write(device->cs_pin, PIN_LOW); + } } LOG_D("%s transfer prepare and start", spi_drv->config->bus_name); @@ -344,7 +348,7 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m if ((spi_drv->spi_dma_flag & SPI_USING_TX_DMA_FLAG) && (send_length >= DMA_TRANS_MIN_LEN)) { #if defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32F7) - if (RT_IS_ALIGN((rt_uint32_t)send_buf, 32)) /* aligned with 32 bytes? */ + if (RT_IS_ALIGN((rt_uint32_t)send_buf, 32) && send_buf != RT_NULL) /* aligned with 32 bytes? */ { p_txrx_buffer = (rt_uint32_t *)send_buf; /* send_buf aligns with 32 bytes, no more operations */ } @@ -357,7 +361,7 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m } rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, dma_aligned_buffer, send_length); #else - if (RT_IS_ALIGN((rt_uint32_t)send_buf, 4)) /* aligned with 4 bytes? */ + if (RT_IS_ALIGN((rt_uint32_t)send_buf, 4) && send_buf != RT_NULL) /* aligned with 4 bytes? */ { p_txrx_buffer = (rt_uint32_t *)send_buf; /* send_buf aligns with 4 bytes, no more operations */ }