summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblta <[email protected]>2022-04-26 13:26:28 +0800
committerGitHub <[email protected]>2022-04-26 13:26:28 +0800
commitd52ad69d6ff6abc3aa3d020996618f94b3343778 (patch)
tree633ea3ba946fe98b28093cb172cfe1dbcf5c69cf
parent7f1157e0de32f16e749267a676f6dd767fd454a9 (diff)
[BSP] judge the SPI instances before operating (#5874)
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_spi.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c
index 3d5b92f16e..6f021bd9a7 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_spi.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_spi.c
@@ -155,16 +155,31 @@ static rt_err_t stm32_spi_init(struct stm32_spi *spi_drv, struct rt_spi_configur
/* normal series */
#else
- /* SPI2 and SPI3 on APB1 */
- if(spi_drv->config->Instance == SPI2 || spi_drv->config->Instance == SPI3)
- {
- SPI_APB_CLOCK = HAL_RCC_GetPCLK1Freq();
- }
/* SPI1, SPI4 and SPI5 on APB2 */
- else if(spi_drv->config->Instance == SPI1 || spi_drv->config->Instance == SPI4 || spi_drv->config->Instance == SPI5)
+ if(spi_drv->config->Instance == SPI1
+ #ifdef SPI4
+ || spi_drv->config->Instance == SPI4
+ #endif
+ #ifdef SPI5
+ || spi_drv->config->Instance == SPI5
+ #endif
+ )
{
SPI_APB_CLOCK = HAL_RCC_GetPCLK2Freq();
}
+
+ /* SPI2 and SPI3 on APB1 */
+ #ifdef SPI2
+ else if(spi_drv->config->Instance == SPI2
+ #ifdef SPI3
+ || spi_drv->config->Instance == SPI3
+ #endif
+ )
+ {
+ SPI_APB_CLOCK = HAL_RCC_GetPCLK1Freq();
+ }
+ #endif
+
/* SPI6 get the input clk from APB4(such as on STM32H7). However, there is no HAL_RCC_GetPCLK4Freq api provided.
APB4 has same prescale factor as APB1 from HPRE Clock by default in CubeMx, so we assign APB1 to it.
if you change the default prescale factor of APB4, please modify SPI_APB_CLOCK accordingly.