Skip to content

Commit 91eca8d

Browse files
kaidegitmysterywolf
authored andcommitted
[bsp][hc32] 修复SPI驱动的片选脚获取方式
1 parent e83b8fd commit 91eca8d

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

bsp/hc32/libraries/hc32_drivers/drv_spi.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -496,24 +496,20 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess
496496

497497
RT_ASSERT(device != RT_NULL);
498498
RT_ASSERT(device->bus != RT_NULL);
499-
RT_ASSERT(device->bus->parent.user_data != RT_NULL);
500499
RT_ASSERT(message != RT_NULL);
501500

502501
struct hc32_spi *spi_drv = rt_container_of(device->bus, struct hc32_spi, spi_bus);
503502
CM_SPI_TypeDef *spi_instance = spi_drv->config->Instance;
504-
struct hc32_hw_spi_cs *cs = device->parent.user_data;
505503

506-
if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS))
504+
if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
507505
{
508506
if (device->config.mode & RT_SPI_CS_HIGH)
509-
{
510-
GPIO_SetPins(cs->port, cs->pin);
511-
}
507+
rt_pin_write(device->cs_pin, PIN_HIGH);
512508
else
513-
{
514-
GPIO_ResetPins(cs->port, cs->pin);
515-
}
509+
rt_pin_write(device->cs_pin, PIN_LOW);
516510
}
511+
512+
LOG_D("%s transfer prepare and start", spi_drv->config->bus_name);
517513
LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d", spi_drv->config->bus_name,
518514
(uint32_t)message->send_buf, (uint32_t)message->recv_buf, message->length);
519515

@@ -621,16 +617,12 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess
621617
/* clear error flag */
622618
SPI_ClearStatus(spi_instance, SPI_FLAG_CLR_ALL);
623619

624-
if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS))
620+
if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
625621
{
626622
if (device->config.mode & RT_SPI_CS_HIGH)
627-
{
628-
GPIO_ResetPins(cs->port, cs->pin);
629-
}
623+
rt_pin_write(device->cs_pin, PIN_LOW);
630624
else
631-
{
632-
GPIO_SetPins(cs->port, cs->pin);
633-
}
625+
rt_pin_write(device->cs_pin, PIN_HIGH);
634626
}
635627

636628
return message->length;

0 commit comments

Comments
 (0)