summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliYangYang <[email protected]>2023-01-19 11:03:48 +0800
committerGitHub <[email protected]>2023-01-18 22:03:48 -0500
commit63294afc9da6dfe8fd9ce5d28ae883a2d51c744f (patch)
tree805e99e1c06cb28690947470e698864924f05884
parent7ff64c1cfd2c3392f388ed91cd4955a064265c7f (diff)
[stm32][softspi]soft spi attach函数问题解决方案 (#6868)
* [softspi]soft spi attach函数问题解决方案 * 更改函数名
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.c18
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.h2
-rw-r--r--bsp/stm32/stm32f407-atk-explorer/board/ports/soft_spi_flash_init.c3
-rw-r--r--bsp/stm32/stm32f407-atk-explorer/board/ports/touch/drv_xpt2046_init.c2
-rw-r--r--components/drivers/spi/spi-bit-ops.c6
5 files changed, 16 insertions, 15 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.c b/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.c
index a149316387..7e32c24d60 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.c
@@ -30,23 +30,25 @@ static struct stm32_soft_spi_config soft_spi_config[] =
/**
* Attach the spi device to soft SPI bus, this function must be used after initialization.
*/
-rt_err_t rt_hw_soft_spi_device_attach(const char *bus_name, const char *device_name, const char *pin_name)
+rt_err_t rt_hw_softspi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
{
rt_err_t result;
struct rt_spi_device *spi_device;
/* initialize the cs pin && select the slave*/
- rt_base_t cs_pin = rt_pin_get(pin_name);
-
- rt_pin_mode(cs_pin,PIN_MODE_OUTPUT);
- rt_pin_write(cs_pin,PIN_HIGH);
+ if(cs_pin != PIN_NONE)
+ {
+ rt_pin_mode(cs_pin,PIN_MODE_OUTPUT);
+ rt_pin_write(cs_pin,PIN_HIGH);
+ }
/* attach the device to soft spi bus*/
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
RT_ASSERT(spi_device != RT_NULL);
+ spi_device->cs_pin = cs_pin;
- result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
+ result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, RT_NULL);
return result;
}
@@ -208,7 +210,7 @@ static struct rt_spi_bit_ops stm32_soft_spi_ops =
static struct stm32_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];
/* Soft SPI initialization function */
-int rt_soft_spi_init(void)
+int rt_hw_softspi_init(void)
{
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct stm32_soft_spi);
rt_err_t result;
@@ -225,6 +227,6 @@ int rt_soft_spi_init(void)
return RT_EOK;
}
-INIT_BOARD_EXPORT(rt_soft_spi_init);
+INIT_BOARD_EXPORT(rt_hw_softspi_init);
#endif /* defined(RT_USING_SPI) && defined(RT_USING_SPI_BITOPS) && defined(RT_USING_PIN) */
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.h b/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.h
index 01d6411b6c..9f70d61562 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.h
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_soft_spi.h
@@ -50,7 +50,7 @@ struct stm32_soft_spi
}
#endif /* BSP_USING_SOFT_SPI2 */
-rt_err_t rt_hw_soft_spi_device_attach(const char *bus_name, const char *device_name, const char *pin_name);
+rt_err_t rt_hw_softspi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
int rt_soft_spi_init(void);
#endif /* __DRV_SOFT_SPI__ */
diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/soft_spi_flash_init.c b/bsp/stm32/stm32f407-atk-explorer/board/ports/soft_spi_flash_init.c
index 3221c84cc0..93a8e08299 100644
--- a/bsp/stm32/stm32f407-atk-explorer/board/ports/soft_spi_flash_init.c
+++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/soft_spi_flash_init.c
@@ -18,8 +18,7 @@
static int rt_soft_spi_flash_init(void)
{
- __HAL_RCC_GPIOB_CLK_ENABLE();
- rt_hw_soft_spi_device_attach("sspi2", "sspi20", "PB.14");
+ rt_hw_softspi_device_attach("sspi2", "sspi20", GET_PIN(B, 14));
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "sspi20"))
{
diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/touch/drv_xpt2046_init.c b/bsp/stm32/stm32f407-atk-explorer/board/ports/touch/drv_xpt2046_init.c
index 9e599eed9c..40eefad667 100644
--- a/bsp/stm32/stm32f407-atk-explorer/board/ports/touch/drv_xpt2046_init.c
+++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/touch/drv_xpt2046_init.c
@@ -61,7 +61,7 @@ void xpt2046_init_hw(void)
/* Mount the spi device to the spi bus, here is the soft spi,
* if you use other spi, please modify the following */
- rt_hw_soft_spi_device_attach(BSP_XPT2046_SPI_BUS, dev_name, BSP_XPT2046_CS_PIN);
+ rt_hw_softspi_device_attach(BSP_XPT2046_SPI_BUS, dev_name, rt_pin_get(BSP_XPT2046_CS_PIN));
/* configure spi device */
rt_xpt2046_t tc = (rt_xpt2046_t)touch;
diff --git a/components/drivers/spi/spi-bit-ops.c b/components/drivers/spi/spi-bit-ops.c
index 253c471849..eb6df1590a 100644
--- a/components/drivers/spi/spi-bit-ops.c
+++ b/components/drivers/spi/spi-bit-ops.c
@@ -417,7 +417,7 @@ rt_uint32_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *me
struct rt_spi_bit_obj *obj = rt_container_of(device->bus, struct rt_spi_bit_obj, bus);
struct rt_spi_bit_ops *ops = obj->ops;
struct rt_spi_configuration *config = &obj->config;
- rt_base_t cs_pin = (rt_base_t)device->parent.user_data;
+ rt_base_t cs_pin = device->cs_pin;
RT_ASSERT(device != NULL);
RT_ASSERT(message != NULL);
@@ -438,7 +438,7 @@ rt_uint32_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *me
#endif
/* take CS */
- if (message->cs_take)
+ if (message->cs_take && (cs_pin != PIN_NONE))
{
LOG_I("spi take cs\n");
rt_pin_write(cs_pin, PIN_LOW);
@@ -492,7 +492,7 @@ rt_uint32_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *me
}
/* release CS */
- if (message->cs_release)
+ if (message->cs_release && (cs_pin != PIN_NONE))
{
spi_delay(ops);
rt_pin_write(cs_pin, PIN_HIGH);