extended spi core

This commit is contained in:
Robin Müller 2021-06-03 14:38:34 +02:00
parent dc6327b909
commit 21414c3594
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 95 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "stm32h7xx_spi_dma_msp.h"
#include "spiConf.h"
#include "../spi/spiDefinitions.h"
#include "../spi/spiCore.h"
#include "fsfw/tasks/TaskFactory.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
@ -21,6 +22,7 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle): spiHandle(spiHandle) {
ReturnValue_t GyroL3GD20H::initialize() {
// Configure the SPI peripheral
spiHandle->Instance = SPI1;
uint32_t test = HAL_RCC_GetHCLKFreq();
spiHandle->Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), 3900000);
spiHandle->Init.Direction = SPI_DIRECTION_2LINES;
spi::assignSpiMode(spi::SpiModes::MODE_3, spiHandle);

View File

@ -1,3 +1,4 @@
target_sources(${TARGET_NAME} PRIVATE
spiCore.c
spiDefinitions.cpp
)

56
stm32h7/spi/spiCore.c Normal file
View File

@ -0,0 +1,56 @@
#include "spiCore.h"
SPI_HandleTypeDef* spiHandle = NULL;
DMA_HandleTypeDef* hdma_tx = NULL;
DMA_HandleTypeDef* hdma_rx = NULL;
void setDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle) {
hdma_tx = txHandle;
hdma_rx = rxHandle;
}
void getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHandle) {
*txHandle = hdma_tx;
*rxHandle = hdma_rx;
}
void assignSpiHandle(SPI_HandleTypeDef *spiHandle_) {
if(spiHandle_ == NULL) {
return;
}
spiHandle = spiHandle_;
}
SPI_HandleTypeDef* getSpiHandle() {
return spiHandle;
}
/**
* @brief This function handles DMA Rx interrupt request.
* @param None
* @retval None
*/
void SPIx_DMA_RX_IRQHandler(void)
{
HAL_DMA_IRQHandler(spiHandle->hdmarx);
}
/**
* @brief This function handles DMA Tx interrupt request.
* @param None
* @retval None
*/
void SPIx_DMA_TX_IRQHandler(void)
{
HAL_DMA_IRQHandler(spiHandle->hdmatx);
}
/**
* @brief This function handles SPIx interrupt request.
* @param None
* @retval None
*/
void SPIx_IRQHandler(void)
{
HAL_SPI_IRQHandler(spiHandle);
}

36
stm32h7/spi/spiCore.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef FSFW_HAL_STM32H7_SPI_SPICORE_H_
#define FSFW_HAL_STM32H7_SPI_SPICORE_H_
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_dma.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Assign DMA handles. Required to use DMA for SPI transfers.
* @param txHandle
* @param rxHandle
*/
void setDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle);
void getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHandle);
/**
* Assign SPI handle. Needs to be done before using the SPI
* @param spiHandle
*/
void assignSpiHandle(SPI_HandleTypeDef *spiHandle);
/**
* Get the assigned SPI handle.
* @return
*/
SPI_HandleTypeDef* getSpiHandle();
#ifdef __cplusplus
}
#endif
#endif /* FSFW_HAL_STM32H7_SPI_SPICORE_H_ */