From 3c32e0168d1ebbac5d6e5749eaf804fc268dd460 Mon Sep 17 00:00:00 2001 From: liukangcc Date: Mon, 11 Oct 2021 17:12:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[drv=5Fspi.c]=20=E4=BF=AE=E5=A4=8D=20stm32?= =?UTF-8?q?=20drv=5Fspi.c=E6=96=87=E4=BB=B6=E4=B8=AD=E7=9A=84=20spixfer=20?= =?UTF-8?q?=E6=9C=AA=E5=AE=9E=E7=8E=B0=E7=89=87=E9=80=89=E4=B8=BA=E9=AB=98?= =?UTF-8?q?=E7=94=B5=E5=B9=B3=E7=9A=84=20spi=20=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_spi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c index 4e98218c90..4cbf4cf194 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c @@ -293,7 +293,10 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS)) { - HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET); + if(device->config.mode & RT_SPI_CS_HIGH) + HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET); + else + HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET); } LOG_D("%s transfer prepare and start", spi_drv->config->bus_name); @@ -387,7 +390,10 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS)) { - HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET); + if(device->config.mode & RT_SPI_CS_HIGH) + HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET); + else + HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET); } return message->length; From 93792b2c8493c262246de4407ba2ad1c66ef52c3 Mon Sep 17 00:00:00 2001 From: LiuKang <44889940+liukangcc@users.noreply.github.com> Date: Mon, 11 Oct 2021 17:45:37 +0800 Subject: [PATCH 2/2] Update drv_spi.c --- bsp/stm32/libraries/HAL_Drivers/drv_spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c index 4cbf4cf194..9b5dcc0885 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c @@ -293,9 +293,9 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS)) { - if(device->config.mode & RT_SPI_CS_HIGH) + if (device->config.mode & RT_SPI_CS_HIGH) HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET); - else + else HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET); } @@ -390,7 +390,7 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS)) { - if(device->config.mode & RT_SPI_CS_HIGH) + if (device->config.mode & RT_SPI_CS_HIGH) HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET); else HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET);