summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBreederBai <[email protected]>2022-10-18 03:52:03 +0800
committerGitHub <[email protected]>2022-10-17 15:52:03 -0400
commit3a9152c5fee95776ff29454b42bbf79d002edee7 (patch)
treebd8e64a510e6978190fe94fafb207aaa11688e5c
parentb617a6abd256c32bb4feb91bdddb202d3c989c93 (diff)
[bsp/stm32] 将spi DMA传输更改为阻塞线程方式 (#6513)
* [bsp/stm32] 将spi DMA传输更改为阻塞线程方式 * Update bsp/stm32/libraries/HAL_Drivers/drv_spi.h Co-authored-by: Man, Jianting (Meco) <[email protected]>
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_spi.c31
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_spi.h3
2 files changed, 33 insertions, 1 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c
index 9c3a2b4993..bf4fac3c10 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c
@@ -411,7 +411,15 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
/* For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
- while (HAL_SPI_GetState(spi_handle) != HAL_SPI_STATE_READY);
+ if (spi_drv->spi_dma_flag & (SPI_USING_TX_DMA_FLAG | SPI_USING_RX_DMA_FLAG))
+ {
+ /* blocking the thread,and the other tasks can run */
+ rt_completion_wait(&spi_drv->cpt, RT_WAITING_FOREVER);
+ }
+ else
+ {
+ while (HAL_SPI_GetState(spi_handle) != HAL_SPI_STATE_READY);
+ }
}
if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS))
@@ -537,6 +545,9 @@ static int rt_hw_spi_bus_init(void)
}
}
+ /* initialize completion object */
+ rt_completion_init(&spi_bus_obj[i].cpt);
+
result = rt_spi_bus_register(&spi_bus_obj[i].spi_bus, spi_config[i].bus_name, &stm_spi_ops);
RT_ASSERT(result == RT_EOK);
@@ -938,6 +949,24 @@ static void stm32_get_dma_info(void)
#endif
}
+void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
+{
+ struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
+ rt_completion_done(&spi_drv->cpt);
+}
+
+void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
+{
+ struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
+ rt_completion_done(&spi_drv->cpt);
+}
+
+void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
+{
+ struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
+ rt_completion_done(&spi_drv->cpt);
+}
+
#if defined(SOC_SERIES_STM32F0)
void SPI1_DMA_RX_TX_IRQHandler(void)
{
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_spi.h b/bsp/stm32/libraries/HAL_Drivers/drv_spi.h
index 65f752fc8a..bdb5e29ecd 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_spi.h
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_spi.h
@@ -16,6 +16,7 @@
#include <rthw.h>
#include <drv_common.h>
#include "drv_dma.h"
+#include <ipc/completion.h>
#ifdef __cplusplus
extern "C" {
@@ -66,6 +67,8 @@ struct stm32_spi
rt_uint8_t spi_dma_flag;
struct rt_spi_bus spi_bus;
+
+ struct rt_completion cpt;
};
#endif /*__DRV_SPI_H__ */