From 72aa8fec69bb3308ab702045851fa164ce148faa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Jun 2021 15:12:53 +0200 Subject: [PATCH] adding irq abstraction --- .../Boards/NUCLEO-H743ZI/Inc/spiConf.h | 2 +- .../NUCLEO-H743ZI/Inc/stm32h7xx_spi_dma_msp.h | 1 - .../NUCLEO-H743ZI/Src/stm32h7xx_spi_dma_msp.c | 93 ++++++++++--------- fsfw_hal | 2 +- 4 files changed, 52 insertions(+), 46 deletions(-) diff --git a/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/spiConf.h b/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/spiConf.h index eb1a0cf..477bcdf 100644 --- a/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/spiConf.h +++ b/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/spiConf.h @@ -43,6 +43,6 @@ #define SPIx_DMA_RX_IRQHandler DMA2_Stream2_IRQHandler #define SPIx_IRQn SPI1_IRQn -#define SPIx_IRQHandler SPI1_IRQHandler +#define SPIx_IRQHandler SPIx_IRQHandler #endif /* FSFW_HAL_STM32H7_DEVICETEST_SPICONF_H_ */ diff --git a/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/stm32h7xx_spi_dma_msp.h b/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/stm32h7xx_spi_dma_msp.h index 82f0e33..299a686 100644 --- a/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/stm32h7xx_spi_dma_msp.h +++ b/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc/stm32h7xx_spi_dma_msp.h @@ -7,7 +7,6 @@ extern "C" { #endif -void setDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle); #ifdef __cplusplus } diff --git a/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Src/stm32h7xx_spi_dma_msp.c b/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Src/stm32h7xx_spi_dma_msp.c index f283947..24bca6c 100644 --- a/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Src/stm32h7xx_spi_dma_msp.c +++ b/bsp_stm32_freertos/STM32CubeH7/Boards/NUCLEO-H743ZI/Src/stm32h7xx_spi_dma_msp.c @@ -1,5 +1,7 @@ #include "spiConf.h" +#include "fsfw_hal/stm32h7/spi/spiCore.h" + #include "stm32h743xx.h" #include "stm32h7xx_hal_spi.h" #include "stm32h7xx_hal_dma.h" @@ -7,14 +9,6 @@ #include -DMA_HandleTypeDef* hdma_tx = NULL; -DMA_HandleTypeDef* hdma_rx = NULL; -SPI_HandleTypeDef* spi_handle = NULL; - -void setDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle) { - hdma_tx = txHandle; - hdma_rx = rxHandle; -} /** * @brief SPI MSP Initialization @@ -33,8 +27,11 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) printf("HAL_SPI_MspInit: Invalid SPI handle!\n"); return; } - spi_handle = hspi; + assignSpiHandle(hspi); + DMA_HandleTypeDef* hdma_tx = NULL; + DMA_HandleTypeDef* hdma_rx = NULL; + getDmaHandles(&hdma_tx, &hdma_rx); if(hdma_tx == NULL || hdma_rx == NULL) { printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n"); return; @@ -140,6 +137,8 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) { if(hspi->Instance == SPIx) { + + /*##-1- Reset peripherals ##################################################*/ SPIx_FORCE_RESET(); SPIx_RELEASE_RESET(); @@ -152,11 +151,19 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) /* Deconfigure SPI MOSI */ HAL_GPIO_DeInit(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_PIN); - /*##-3- Disable the DMA ####################################################*/ - /* De-Initialize the DMA associated to transmission process */ - HAL_DMA_DeInit(hdma_tx); - /* De-Initialize the DMA associated to reception process */ - HAL_DMA_DeInit(hdma_rx); + DMA_HandleTypeDef* hdma_tx = NULL; + DMA_HandleTypeDef* hdma_rx = NULL; + getDmaHandles(&hdma_tx, &hdma_rx); + if(hdma_tx == NULL || hdma_rx == NULL) { + printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n"); + } + else { + /*##-3- Disable the DMA ####################################################*/ + /* De-Initialize the DMA associated to transmission process */ + HAL_DMA_DeInit(hdma_tx); + /* De-Initialize the DMA associated to reception process */ + HAL_DMA_DeInit(hdma_rx); + } /*##-4- Disable the NVIC for DMA ###########################################*/ HAL_NVIC_DisableIRQ(SPIx_DMA_TX_IRQn); @@ -167,32 +174,32 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) } } -/** - * @brief This function handles DMA Rx interrupt request. - * @param None - * @retval None - */ -void SPIx_DMA_RX_IRQHandler(void) -{ - HAL_DMA_IRQHandler(spi_handle->hdmarx); -} - -/** - * @brief This function handles DMA Tx interrupt request. - * @param None - * @retval None - */ -void SPIx_DMA_TX_IRQHandler(void) -{ - HAL_DMA_IRQHandler(spi_handle->hdmatx); -} - -/** - * @brief This function handles SPIx interrupt request. - * @param None - * @retval None - */ -void SPIx_IRQHandler(void) -{ - HAL_SPI_IRQHandler(spi_handle); -} +///** +// * @brief This function handles DMA Rx interrupt request. +// * @param None +// * @retval None +// */ +//void SPIx_DMA_RX_IRQHandler(void) +//{ +// HAL_DMA_IRQHandler(getSpiHandle()->hdmarx); +//} +// +///** +// * @brief This function handles DMA Tx interrupt request. +// * @param None +// * @retval None +// */ +//void SPIx_DMA_TX_IRQHandler(void) +//{ +// HAL_DMA_IRQHandler(getSpiHandle()->hdmatx); +//} +// +///** +// * @brief This function handles SPIx interrupt request. +// * @param None +// * @retval None +// */ +//void SPIx_IRQHandler(void) +//{ +// HAL_SPI_IRQHandler(getSpiHandle()); +//} diff --git a/fsfw_hal b/fsfw_hal index dc6327b..78a66e1 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit dc6327b909005c968a4794c3d8b2f9ac94ad59e1 +Subproject commit 78a66e1b677ae0daa532db222ecdd0097c01399a