Skip to content

Commit 3c32e01

Browse files
committed
[drv_spi.c] 修复 stm32 drv_spi.c文件中的 spixfer 未实现片选为高电平的 spi 设备
1 parent 24f2ce6 commit 3c32e01

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_spi.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,10 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
293293

294294
if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS))
295295
{
296-
HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET);
296+
if(device->config.mode & RT_SPI_CS_HIGH)
297+
HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET);
298+
else
299+
HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET);
297300
}
298301

299302
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 *
387390

388391
if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS))
389392
{
390-
HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET);
393+
if(device->config.mode & RT_SPI_CS_HIGH)
394+
HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_RESET);
395+
else
396+
HAL_GPIO_WritePin(cs->GPIOx, cs->GPIO_Pin, GPIO_PIN_SET);
391397
}
392398

393399
return message->length;

0 commit comments

Comments
 (0)