diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_qspi.c b/bsp/stm32/libraries/HAL_Drivers/drv_qspi.c index c4d61a47c1..900da17abf 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_qspi.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_qspi.c @@ -20,11 +20,6 @@ #if defined(BSP_USING_QSPI) -struct stm32_hw_spi_cs -{ - uint16_t pin; -}; - struct stm32_qspi_bus { QSPI_HandleTypeDef QSPI_Handler; @@ -209,18 +204,15 @@ static rt_uint32_t qspixfer(struct rt_spi_device *device, struct rt_spi_message struct rt_qspi_message *qspi_message = (struct rt_qspi_message *)message; struct stm32_qspi_bus *qspi_bus = device->bus->parent.user_data; -#ifdef BSP_QSPI_USING_SOFTCS - struct stm32_hw_spi_cs *cs = device->parent.user_data; -#endif const rt_uint8_t *sndb = message->send_buf; rt_uint8_t *rcvb = message->recv_buf; rt_int32_t length = message->length; #ifdef BSP_QSPI_USING_SOFTCS - if (message->cs_take) + if (message->cs_take && (device->parent.cs_pin != PIN_NONE)) { - rt_pin_write(cs->pin, 0); + rt_pin_write(device->parent.cs_pin, PIN_LOW); } #endif @@ -270,9 +262,9 @@ static rt_uint32_t qspixfer(struct rt_spi_device *device, struct rt_spi_message __exit: #ifdef BSP_QSPI_USING_SOFTCS - if (message->cs_release) + if (message->cs_release && (device->parent.cs_pin != PIN_NONE)) { - rt_pin_write(cs->pin, 1); + rt_pin_write(device->parent.cs_pin, PIN_HIGH); } #endif return len; @@ -305,17 +297,16 @@ static int stm32_qspi_register_bus(struct stm32_qspi_bus *qspi_bus, const char * /** * @brief This function attach device to QSPI bus. * @param device_name QSPI device name - * @param pin QSPI cs pin number + * @param cs_pin QSPI cs pin number * @param data_line_width QSPI data lines width, such as 1, 2, 4 * @param enter_qspi_mode Callback function that lets FLASH enter QSPI mode * @param exit_qspi_mode Callback function that lets FLASH exit QSPI mode * @retval 0 : success * -1 : failed */ -rt_err_t stm32_qspi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin, rt_uint8_t data_line_width, void (*enter_qspi_mode)(), void (*exit_qspi_mode)()) +rt_err_t rt_hw_qspi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin, rt_uint8_t data_line_width, void (*enter_qspi_mode)(), void (*exit_qspi_mode)()) { struct rt_qspi_device *qspi_device = RT_NULL; - struct stm32_hw_spi_cs *cs_pin = RT_NULL; rt_err_t result = RT_EOK; RT_ASSERT(bus_name != RT_NULL); @@ -329,25 +320,21 @@ rt_err_t stm32_qspi_bus_attach_device(const char *bus_name, const char *device_n result = RT_ENOMEM; goto __exit; } - cs_pin = (struct stm32_hw_spi_cs *)rt_malloc(sizeof(struct stm32_hw_spi_cs)); - if (qspi_device == RT_NULL) - { - LOG_E("no memory, qspi bus attach device failed!"); - result = RT_ENOMEM; - goto __exit; - } qspi_device->enter_qspi_mode = enter_qspi_mode; qspi_device->exit_qspi_mode = exit_qspi_mode; qspi_device->config.qspi_dl_width = data_line_width; + qspi_device->parent.cs_pin = cs_pin; - cs_pin->pin = pin; #ifdef BSP_QSPI_USING_SOFTCS - rt_pin_mode(pin, PIN_MODE_OUTPUT); - rt_pin_write(pin, 1); + if(cs_pin != PIN_NONE) + { + rt_pin_mode(cs_pin, PIN_MODE_OUTPUT); + rt_pin_write(cs_pin, PIN_HIGH); + } #endif - result = rt_spi_bus_attach_device(&qspi_device->parent, device_name, bus_name, (void *)cs_pin); + result = rt_spi_bus_attach_device(&qspi_device->parent, device_name, bus_name, RT_NULL); __exit: if (result != RT_EOK) @@ -356,11 +343,6 @@ __exit: { rt_free(qspi_device); } - - if (cs_pin) - { - rt_free(cs_pin); - } } return result; diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_qspi.h b/bsp/stm32/libraries/HAL_Drivers/drv_qspi.h index f0c35c7c8d..6e5009e908 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_qspi.h +++ b/bsp/stm32/libraries/HAL_Drivers/drv_qspi.h @@ -17,7 +17,7 @@ extern "C" { #endif -rt_err_t stm32_qspi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin, rt_uint8_t data_line_width, void (*enter_qspi_mode)(), void (*exit_qspi_mode)()); +rt_err_t rt_hw_qspi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin, rt_uint8_t data_line_width, void (*enter_qspi_mode)(), void (*exit_qspi_mode)()); #ifdef __cplusplus } diff --git a/bsp/stm32/stm32f469-st-disco/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32f469-st-disco/board/ports/drv_qspi_flash.c index ff1b11e34c..fe963373e2 100644 --- a/bsp/stm32/stm32f469-st-disco/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32f469-st-disco/board/ports/drv_qspi_flash.c @@ -63,7 +63,7 @@ void n25qxxa_enter_qspi_mode(struct rt_qspi_device *device) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, n25qxxa_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, n25qxxa_enter_qspi_mode, RT_NULL); /* init n25qxx */ if (RT_NULL == rt_sfud_flash_probe(FAL_USING_NOR_FLASH_DEV_NAME, "qspi10")) diff --git a/bsp/stm32/stm32f746-st-disco/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32f746-st-disco/board/ports/drv_qspi_flash.c index 4e37f4ec2f..795f8a06a1 100644 --- a/bsp/stm32/stm32f746-st-disco/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32f746-st-disco/board/ports/drv_qspi_flash.c @@ -62,7 +62,7 @@ void n25qxx_enter_qspi_mode(struct rt_qspi_device *device) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, n25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, n25qxx_enter_qspi_mode, RT_NULL); /* init n25q128 */ if (RT_NULL == rt_sfud_flash_probe("n25q128", "qspi10")) diff --git a/bsp/stm32/stm32f767-atk-apollo/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32f767-atk-apollo/board/ports/drv_qspi_flash.c index 72e589aea4..da7ed4fc36 100644 --- a/bsp/stm32/stm32f767-atk-apollo/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32f767-atk-apollo/board/ports/drv_qspi_flash.c @@ -62,7 +62,7 @@ void w25qxx_enter_qspi_mode(struct rt_qspi_device *device) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); /* init W25Q256 */ if (RT_NULL == rt_sfud_flash_probe("W25Q256", "qspi10")) diff --git a/bsp/stm32/stm32f767-fire-challenger-v1/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32f767-fire-challenger-v1/board/ports/drv_qspi_flash.c index a3091fd2eb..21c015dc89 100644 --- a/bsp/stm32/stm32f767-fire-challenger-v1/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32f767-fire-challenger-v1/board/ports/drv_qspi_flash.c @@ -62,7 +62,7 @@ void w25qxx_enter_qspi_mode(struct rt_qspi_device *device) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); /* init w25q128 */ if (RT_NULL == rt_sfud_flash_probe("W25Q128", "qspi10")) diff --git a/bsp/stm32/stm32h743-atk-apollo/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32h743-atk-apollo/board/ports/drv_qspi_flash.c index 72e589aea4..da7ed4fc36 100644 --- a/bsp/stm32/stm32h743-atk-apollo/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32h743-atk-apollo/board/ports/drv_qspi_flash.c @@ -62,7 +62,7 @@ void w25qxx_enter_qspi_mode(struct rt_qspi_device *device) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); /* init W25Q256 */ if (RT_NULL == rt_sfud_flash_probe("W25Q256", "qspi10")) diff --git a/bsp/stm32/stm32h743-openmv-h7plus/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32h743-openmv-h7plus/board/ports/drv_qspi_flash.c index cf853fc086..2b5bf84449 100644 --- a/bsp/stm32/stm32h743-openmv-h7plus/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32h743-openmv-h7plus/board/ports/drv_qspi_flash.c @@ -65,7 +65,7 @@ void w25qxx_enter_qspi_mode(struct rt_qspi_device *device) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); /* init W25Q256 */ if (RT_NULL == rt_sfud_flash_probe("W25Q256", "qspi10")) diff --git a/bsp/stm32/stm32h750-artpi/board/port/drv_qspi_flash.c b/bsp/stm32/stm32h750-artpi/board/port/drv_qspi_flash.c index e262ce3656..5fc97b214e 100644 --- a/bsp/stm32/stm32h750-artpi/board/port/drv_qspi_flash.c +++ b/bsp/stm32/stm32h750-artpi/board/port/drv_qspi_flash.c @@ -60,7 +60,7 @@ static int rt_qspi_flash_init(void) { extern rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const char *spi_dev_name); - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); if (RT_NULL == rt_sfud_flash_probe("norflash1", "qspi10")) { return -RT_ERROR; diff --git a/bsp/stm32/stm32h750-weact-ministm32h7xx/board/port/drv_qspi_flash.c b/bsp/stm32/stm32h750-weact-ministm32h7xx/board/port/drv_qspi_flash.c index ab9fc32813..9390301b78 100644 --- a/bsp/stm32/stm32h750-weact-ministm32h7xx/board/port/drv_qspi_flash.c +++ b/bsp/stm32/stm32h750-weact-ministm32h7xx/board/port/drv_qspi_flash.c @@ -159,7 +159,7 @@ static int rt_qspi_flash_init(void) { extern rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const char *spi_dev_name); - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); if (RT_NULL == rt_sfud_flash_probe(FAL_USING_NOR_FLASH_2_DEV_NAME, "qspi10")) { LOG_E("Failed to probe flash device "FAL_USING_NOR_FLASH_2_DEV_NAME); diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c index 2342b3c669..417f0880e2 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c @@ -62,7 +62,7 @@ void w25qxx_enter_qspi_mode(struct rt_qspi_device *device) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, w25qxx_enter_qspi_mode, RT_NULL); /* init w25q128 */ if (RT_NULL == rt_sfud_flash_probe("W25Q128", "qspi10")) diff --git a/bsp/stm32/stm32mp157a-st-ev1/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32mp157a-st-ev1/board/ports/drv_qspi_flash.c index 7f716c1dae..9834669aa1 100644 --- a/bsp/stm32/stm32mp157a-st-ev1/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32mp157a-st-ev1/board/ports/drv_qspi_flash.c @@ -166,7 +166,7 @@ void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi) static int rt_hw_qspi_flash_with_sfud_init(void) { - stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, RT_NULL, RT_NULL); + rt_hw_qspi_device_attach("qspi1", "qspi10", RT_NULL, 4, RT_NULL, RT_NULL); /* init MX25L51245G */ if (RT_NULL == rt_sfud_flash_probe("MX25L51245G", "qspi10")) {