extended spi core
This commit is contained in:
parent
dc6327b909
commit
21414c3594
@ -2,6 +2,7 @@
|
|||||||
#include "stm32h7xx_spi_dma_msp.h"
|
#include "stm32h7xx_spi_dma_msp.h"
|
||||||
#include "spiConf.h"
|
#include "spiConf.h"
|
||||||
#include "../spi/spiDefinitions.h"
|
#include "../spi/spiDefinitions.h"
|
||||||
|
#include "../spi/spiCore.h"
|
||||||
|
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
@ -21,6 +22,7 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle): spiHandle(spiHandle) {
|
|||||||
ReturnValue_t GyroL3GD20H::initialize() {
|
ReturnValue_t GyroL3GD20H::initialize() {
|
||||||
// Configure the SPI peripheral
|
// Configure the SPI peripheral
|
||||||
spiHandle->Instance = SPI1;
|
spiHandle->Instance = SPI1;
|
||||||
|
uint32_t test = HAL_RCC_GetHCLKFreq();
|
||||||
spiHandle->Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), 3900000);
|
spiHandle->Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), 3900000);
|
||||||
spiHandle->Init.Direction = SPI_DIRECTION_2LINES;
|
spiHandle->Init.Direction = SPI_DIRECTION_2LINES;
|
||||||
spi::assignSpiMode(spi::SpiModes::MODE_3, spiHandle);
|
spi::assignSpiMode(spi::SpiModes::MODE_3, spiHandle);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
target_sources(${TARGET_NAME} PRIVATE
|
target_sources(${TARGET_NAME} PRIVATE
|
||||||
|
spiCore.c
|
||||||
spiDefinitions.cpp
|
spiDefinitions.cpp
|
||||||
)
|
)
|
||||||
|
56
stm32h7/spi/spiCore.c
Normal file
56
stm32h7/spi/spiCore.c
Normal 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
36
stm32h7/spi/spiCore.h
Normal 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_ */
|
Loading…
x
Reference in New Issue
Block a user