From 91eca8d573547a68706ac5435c1a99b03d9c950c Mon Sep 17 00:00:00 2001 From: Kai <60053077+kaidegit@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:51:32 +0800 Subject: [PATCH] =?UTF-8?q?[bsp][hc32]=20=E4=BF=AE=E5=A4=8DSPI=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=E7=89=87=E9=80=89=E8=84=9A=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/hc32/libraries/hc32_drivers/drv_spi.c | 24 ++++++++--------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_spi.c b/bsp/hc32/libraries/hc32_drivers/drv_spi.c index b686a4a4a5..1a0acdc74a 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_spi.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_spi.c @@ -496,24 +496,20 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess RT_ASSERT(device != RT_NULL); RT_ASSERT(device->bus != RT_NULL); - RT_ASSERT(device->bus->parent.user_data != RT_NULL); RT_ASSERT(message != RT_NULL); struct hc32_spi *spi_drv = rt_container_of(device->bus, struct hc32_spi, spi_bus); CM_SPI_TypeDef *spi_instance = spi_drv->config->Instance; - struct hc32_hw_spi_cs *cs = device->parent.user_data; - if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS)) + if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE)) { if (device->config.mode & RT_SPI_CS_HIGH) - { - GPIO_SetPins(cs->port, cs->pin); - } + rt_pin_write(device->cs_pin, PIN_HIGH); else - { - GPIO_ResetPins(cs->port, cs->pin); - } + rt_pin_write(device->cs_pin, PIN_LOW); } + + LOG_D("%s transfer prepare and start", spi_drv->config->bus_name); LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d", spi_drv->config->bus_name, (uint32_t)message->send_buf, (uint32_t)message->recv_buf, message->length); @@ -621,16 +617,12 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess /* clear error flag */ SPI_ClearStatus(spi_instance, SPI_FLAG_CLR_ALL); - if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS)) + if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE)) { if (device->config.mode & RT_SPI_CS_HIGH) - { - GPIO_ResetPins(cs->port, cs->pin); - } + rt_pin_write(device->cs_pin, PIN_LOW); else - { - GPIO_SetPins(cs->port, cs->pin); - } + rt_pin_write(device->cs_pin, PIN_HIGH); } return message->length;