Merge pull request 'STM32 SPI Updates' (#518) from mueller/stm32-spi-updates into development
Reviewed-on: fsfw/fsfw#518
This commit is contained in:
commit
9a38106b57
25
hal/src/fsfw_hal/stm32h7/definitions.h
Normal file
25
hal/src/fsfw_hal/stm32h7/definitions.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_
|
||||||
|
#define FSFW_HAL_STM32H7_DEFINITIONS_H_
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include "stm32h7xx.h"
|
||||||
|
|
||||||
|
namespace stm32h7 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Typedef for STM32 GPIO pair where the first entry is the port used (e.g. GPIOA)
|
||||||
|
* and the second entry is the pin number
|
||||||
|
*/
|
||||||
|
struct GpioCfg {
|
||||||
|
GpioCfg(): port(nullptr), pin(0), altFnc(0) {};
|
||||||
|
|
||||||
|
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0):
|
||||||
|
port(port), pin(pin), altFnc(altFnc) {};
|
||||||
|
GPIO_TypeDef* port;
|
||||||
|
uint16_t pin;
|
||||||
|
uint8_t altFnc;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* #ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ */
|
@ -4,7 +4,7 @@
|
|||||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h"
|
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||||
|
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
@ -33,20 +33,20 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transf
|
|||||||
mspCfg = new spi::MspDmaConfigStruct();
|
mspCfg = new spi::MspDmaConfigStruct();
|
||||||
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct*>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct*>(mspCfg);
|
||||||
spi::setDmaHandles(txDmaHandle, rxDmaHandle);
|
spi::setDmaHandles(txDmaHandle, rxDmaHandle);
|
||||||
spi::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
|
stm32h7::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
|
||||||
IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS);
|
IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS);
|
||||||
spi::setSpiDmaMspFunctions(typedCfg);
|
spi::setSpiDmaMspFunctions(typedCfg);
|
||||||
}
|
}
|
||||||
else if(transferMode == spi::TransferModes::INTERRUPT) {
|
else if(transferMode == spi::TransferModes::INTERRUPT) {
|
||||||
mspCfg = new spi::MspIrqConfigStruct();
|
mspCfg = new spi::MspIrqConfigStruct();
|
||||||
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct*>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct*>(mspCfg);
|
||||||
spi::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
|
stm32h7::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
|
||||||
spi::setSpiIrqMspFunctions(typedCfg);
|
spi::setSpiIrqMspFunctions(typedCfg);
|
||||||
}
|
}
|
||||||
else if(transferMode == spi::TransferModes::POLLING) {
|
else if(transferMode == spi::TransferModes::POLLING) {
|
||||||
mspCfg = new spi::MspPollingConfigStruct();
|
mspCfg = new spi::MspPollingConfigStruct();
|
||||||
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct*>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct*>(mspCfg);
|
||||||
spi::h743zi::standardPollingCfg(*typedCfg);
|
stm32h7::h743zi::standardPollingCfg(*typedCfg);
|
||||||
spi::setSpiPollingMspFunctions(typedCfg);
|
spi::setSpiPollingMspFunctions(typedCfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,5 +5,5 @@ target_sources(${LIB_FSFW_NAME} PRIVATE
|
|||||||
mspInit.cpp
|
mspInit.cpp
|
||||||
SpiCookie.cpp
|
SpiCookie.cpp
|
||||||
SpiComIF.cpp
|
SpiComIF.cpp
|
||||||
stm32h743ziSpi.cpp
|
stm32h743zi.cpp
|
||||||
)
|
)
|
||||||
|
@ -138,12 +138,14 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
spi::setSpiDmaMspFunctions(typedCfg);
|
spi::setSpiDmaMspFunctions(typedCfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio::initializeGpioClock(gpioPort);
|
if(gpioPort != nullptr) {
|
||||||
GPIO_InitTypeDef chipSelect = {};
|
gpio::initializeGpioClock(gpioPort);
|
||||||
chipSelect.Pin = gpioPin;
|
GPIO_InitTypeDef chipSelect = {};
|
||||||
chipSelect.Mode = GPIO_MODE_OUTPUT_PP;
|
chipSelect.Pin = gpioPin;
|
||||||
HAL_GPIO_Init(gpioPort, &chipSelect);
|
chipSelect.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
HAL_GPIO_Init(gpioPort, &chipSelect);
|
||||||
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||||
|
}
|
||||||
|
|
||||||
if(HAL_SPI_Init(&spiHandle) != HAL_OK) {
|
if(HAL_SPI_Init(&spiHandle) != HAL_OK) {
|
||||||
sif::printWarning("SpiComIF::initialize: Error initializing SPI\n");
|
sif::printWarning("SpiComIF::initialize: Error initializing SPI\n");
|
||||||
@ -259,10 +261,15 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
|||||||
return returnval;
|
return returnval;
|
||||||
}
|
}
|
||||||
spiCookie.setTransferState(spi::TransferStates::WAIT);
|
spiCookie.setTransferState(spi::TransferStates::WAIT);
|
||||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
if(gpioPort != nullptr) {
|
||||||
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t*>(sendData),
|
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t*>(sendData),
|
||||||
recvPtr, sendLen, defaultPollingTimeout);
|
recvPtr, sendLen, defaultPollingTimeout);
|
||||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
if(gpioPort != nullptr) {
|
||||||
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||||
|
}
|
||||||
spiSemaphore->release();
|
spiSemaphore->release();
|
||||||
switch(result) {
|
switch(result) {
|
||||||
case(HAL_OK): {
|
case(HAL_OK): {
|
||||||
@ -392,8 +399,10 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef&
|
|||||||
// The SPI handle is passed to the default SPI callback as a void argument. This callback
|
// The SPI handle is passed to the default SPI callback as a void argument. This callback
|
||||||
// is different from the user callbacks specified above!
|
// is different from the user callbacks specified above!
|
||||||
spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast<void*>(&spiHandle));
|
spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast<void*>(&spiHandle));
|
||||||
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
if(spiCookie.getChipSelectGpioPort() != nullptr) {
|
||||||
GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
||||||
|
GPIO_PIN_RESET);
|
||||||
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,9 +435,12 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt
|
|||||||
|
|
||||||
spiCookie->setTransferState(targetState);
|
spiCookie->setTransferState(targetState);
|
||||||
|
|
||||||
// Pull CS pin high again
|
if(spiCookie->getChipSelectGpioPort() != nullptr) {
|
||||||
HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(),
|
// Pull CS pin high again
|
||||||
GPIO_PIN_SET);
|
HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(),
|
||||||
|
GPIO_PIN_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined FSFW_OSAL_FREERTOS
|
#if defined FSFW_OSAL_FREERTOS
|
||||||
// Release the task semaphore
|
// Release the task semaphore
|
||||||
|
@ -60,7 +60,6 @@ public:
|
|||||||
void addDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle);
|
void addDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle);
|
||||||
|
|
||||||
ReturnValue_t initialize() override;
|
ReturnValue_t initialize() override;
|
||||||
protected:
|
|
||||||
|
|
||||||
// DeviceCommunicationIF overrides
|
// DeviceCommunicationIF overrides
|
||||||
virtual ReturnValue_t initializeInterface(CookieIF * cookie) override;
|
virtual ReturnValue_t initializeInterface(CookieIF * cookie) override;
|
||||||
@ -72,7 +71,7 @@ protected:
|
|||||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
||||||
uint8_t **buffer, size_t *size) override;
|
uint8_t **buffer, size_t *size) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
|
||||||
struct SpiInstance {
|
struct SpiInstance {
|
||||||
SpiInstance(size_t maxRecvSize): replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
SpiInstance(size_t maxRecvSize): replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
||||||
uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize):
|
size_t maxRecvSize, stm32h7::GpioCfg csGpio):
|
||||||
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
|
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
|
||||||
transferMode(transferMode), chipSelectGpioPin(chipSelectGpioPin),
|
transferMode(transferMode), csGpio(csGpio),
|
||||||
chipSelectGpioPort(chipSelectGpioPort), mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
|
mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
|
||||||
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||||
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||||
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
|
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||||
@ -24,11 +24,11 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t SpiCookie::getChipSelectGpioPin() const {
|
uint16_t SpiCookie::getChipSelectGpioPin() const {
|
||||||
return chipSelectGpioPin;
|
return csGpio.pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
|
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
|
||||||
return chipSelectGpioPort;
|
return csGpio.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
address_t SpiCookie::getDeviceAddress() const {
|
address_t SpiCookie::getDeviceAddress() const {
|
||||||
|
@ -3,11 +3,14 @@
|
|||||||
|
|
||||||
#include "spiDefinitions.h"
|
#include "spiDefinitions.h"
|
||||||
#include "mspInit.h"
|
#include "mspInit.h"
|
||||||
|
#include "../definitions.h"
|
||||||
|
|
||||||
#include "fsfw/devicehandlers/CookieIF.h"
|
#include "fsfw/devicehandlers/CookieIF.h"
|
||||||
|
|
||||||
#include "stm32h743xx.h"
|
#include "stm32h743xx.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SPI cookie implementation for the STM32H7 device family
|
* @brief SPI cookie implementation for the STM32H7 device family
|
||||||
* @details
|
* @details
|
||||||
@ -18,6 +21,7 @@
|
|||||||
class SpiCookie: public CookieIF {
|
class SpiCookie: public CookieIF {
|
||||||
friend class SpiComIF;
|
friend class SpiComIF;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows construction of a SPI cookie for a connected SPI device
|
* Allows construction of a SPI cookie for a connected SPI device
|
||||||
* @param deviceAddress
|
* @param deviceAddress
|
||||||
@ -32,10 +36,11 @@ public:
|
|||||||
* definitions supplied in the MCU header file! (e.g. GPIO_PIN_X)
|
* definitions supplied in the MCU header file! (e.g. GPIO_PIN_X)
|
||||||
* @param chipSelectGpioPort GPIO port (e.g. GPIOA)
|
* @param chipSelectGpioPort GPIO port (e.g. GPIOA)
|
||||||
* @param maxRecvSize Maximum expected receive size. Chose as small as possible.
|
* @param maxRecvSize Maximum expected receive size. Chose as small as possible.
|
||||||
|
* @param csGpio Optional CS GPIO definition.
|
||||||
*/
|
*/
|
||||||
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
||||||
uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize);
|
size_t maxRecvSize, stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
|
||||||
|
|
||||||
uint16_t getChipSelectGpioPin() const;
|
uint16_t getChipSelectGpioPin() const;
|
||||||
GPIO_TypeDef* getChipSelectGpioPort();
|
GPIO_TypeDef* getChipSelectGpioPort();
|
||||||
@ -55,8 +60,8 @@ private:
|
|||||||
spi::SpiModes spiMode;
|
spi::SpiModes spiMode;
|
||||||
spi::TransferModes transferMode;
|
spi::TransferModes transferMode;
|
||||||
volatile spi::TransferStates transferState = spi::TransferStates::IDLE;
|
volatile spi::TransferStates transferState = spi::TransferStates::IDLE;
|
||||||
uint16_t chipSelectGpioPin;
|
stm32h7::GpioCfg csGpio;
|
||||||
GPIO_TypeDef* chipSelectGpioPort;
|
|
||||||
// The MSP configuration is cached here. Be careful when using this, it is automatically
|
// The MSP configuration is cached here. Be careful when using this, it is automatically
|
||||||
// deleted by the SPI communication interface if it is not required anymore!
|
// deleted by the SPI communication interface if it is not required anymore!
|
||||||
spi::MspCfgBase* mspCfg = nullptr;
|
spi::MspCfgBase* mspCfg = nullptr;
|
||||||
|
@ -118,40 +118,40 @@ void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
GPIO_InitTypeDef GPIO_InitStruct = {};
|
GPIO_InitTypeDef GPIO_InitStruct = {};
|
||||||
/*##-1- Enable peripherals and GPIO Clocks #################################*/
|
/*##-1- Enable peripherals and GPIO Clocks #################################*/
|
||||||
/* Enable GPIO TX/RX clock */
|
/* Enable GPIO TX/RX clock */
|
||||||
cfg->setupMacroWrapper();
|
cfg->setupCb();
|
||||||
|
|
||||||
/*##-2- Configure peripheral GPIO ##########################################*/
|
/*##-2- Configure peripheral GPIO ##########################################*/
|
||||||
/* SPI SCK GPIO pin configuration */
|
/* SPI SCK GPIO pin configuration */
|
||||||
GPIO_InitStruct.Pin = cfg->sckPin;
|
GPIO_InitStruct.Pin = cfg->sck.pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
GPIO_InitStruct.Alternate = cfg->sckAlternateFunction;
|
GPIO_InitStruct.Alternate = cfg->sck.altFnc;
|
||||||
HAL_GPIO_Init(cfg->sckPort, &GPIO_InitStruct);
|
HAL_GPIO_Init(cfg->sck.port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* SPI MISO GPIO pin configuration */
|
/* SPI MISO GPIO pin configuration */
|
||||||
GPIO_InitStruct.Pin = cfg->misoPin;
|
GPIO_InitStruct.Pin = cfg->miso.pin;
|
||||||
GPIO_InitStruct.Alternate = cfg->misoAlternateFunction;
|
GPIO_InitStruct.Alternate = cfg->miso.altFnc;
|
||||||
HAL_GPIO_Init(cfg->misoPort, &GPIO_InitStruct);
|
HAL_GPIO_Init(cfg->miso.port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* SPI MOSI GPIO pin configuration */
|
/* SPI MOSI GPIO pin configuration */
|
||||||
GPIO_InitStruct.Pin = cfg->mosiPin;
|
GPIO_InitStruct.Pin = cfg->mosi.pin;
|
||||||
GPIO_InitStruct.Alternate = cfg->mosiAlternateFunction;
|
GPIO_InitStruct.Alternate = cfg->mosi.altFnc;
|
||||||
HAL_GPIO_Init(cfg->mosiPort, &GPIO_InitStruct);
|
HAL_GPIO_Init(cfg->mosi.port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
void spi::halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||||
auto cfg = reinterpret_cast<MspPollingConfigStruct*>(cfgBase);
|
auto cfg = reinterpret_cast<MspPollingConfigStruct*>(cfgBase);
|
||||||
// Reset peripherals
|
// Reset peripherals
|
||||||
cfg->cleanUpMacroWrapper();
|
cfg->cleanupCb();
|
||||||
|
|
||||||
// Disable peripherals and GPIO Clocks
|
// Disable peripherals and GPIO Clocks
|
||||||
/* Configure SPI SCK as alternate function */
|
/* Configure SPI SCK as alternate function */
|
||||||
HAL_GPIO_DeInit(cfg->sckPort, cfg->sckPin);
|
HAL_GPIO_DeInit(cfg->sck.port, cfg->sck.pin);
|
||||||
/* Configure SPI MISO as alternate function */
|
/* Configure SPI MISO as alternate function */
|
||||||
HAL_GPIO_DeInit(cfg->misoPort, cfg->misoPin);
|
HAL_GPIO_DeInit(cfg->miso.port, cfg->miso.pin);
|
||||||
/* Configure SPI MOSI as alternate function */
|
/* Configure SPI MOSI as alternate function */
|
||||||
HAL_GPIO_DeInit(cfg->mosiPort, cfg->mosiPin);
|
HAL_GPIO_DeInit(cfg->mosi.port, cfg->mosi.pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
||||||
|
|
||||||
#include "spiDefinitions.h"
|
#include "spiDefinitions.h"
|
||||||
|
#include "../definitions.h"
|
||||||
#include "../dma.h"
|
#include "../dma.h"
|
||||||
|
|
||||||
#include "stm32h7xx_hal_spi.h"
|
#include "stm32h7xx_hal_spi.h"
|
||||||
@ -12,6 +13,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using mspCb = void (*) (void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the
|
* @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the
|
||||||
* SPI peripheral. This configuration is required for the SPI communication to work.
|
* SPI peripheral. This configuration is required for the SPI communication to work.
|
||||||
@ -19,27 +22,37 @@ extern "C" {
|
|||||||
namespace spi {
|
namespace spi {
|
||||||
|
|
||||||
struct MspCfgBase {
|
struct MspCfgBase {
|
||||||
|
MspCfgBase();
|
||||||
|
MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||||
|
sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb),
|
||||||
|
setupCb(setupCb) {}
|
||||||
|
|
||||||
virtual ~MspCfgBase() = default;
|
virtual ~MspCfgBase() = default;
|
||||||
|
|
||||||
void (* cleanUpMacroWrapper) (void) = nullptr;
|
stm32h7::GpioCfg sck;
|
||||||
void (* setupMacroWrapper) (void) = nullptr;
|
stm32h7::GpioCfg mosi;
|
||||||
|
stm32h7::GpioCfg miso;
|
||||||
|
|
||||||
GPIO_TypeDef* sckPort = nullptr;
|
mspCb cleanupCb = nullptr;
|
||||||
uint32_t sckPin = 0;
|
mspCb setupCb = nullptr;
|
||||||
uint8_t sckAlternateFunction = 0;
|
|
||||||
GPIO_TypeDef* mosiPort = nullptr;
|
|
||||||
uint32_t mosiPin = 0;
|
|
||||||
uint8_t mosiAlternateFunction = 0;
|
|
||||||
GPIO_TypeDef* misoPort = nullptr;
|
|
||||||
uint32_t misoPin = 0;
|
|
||||||
uint8_t misoAlternateFunction = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MspPollingConfigStruct: public MspCfgBase {};
|
struct MspPollingConfigStruct: public MspCfgBase {
|
||||||
|
MspPollingConfigStruct(): MspCfgBase() {};
|
||||||
|
MspPollingConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||||
|
MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||||
|
};
|
||||||
|
|
||||||
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
||||||
argument */
|
argument */
|
||||||
struct MspIrqConfigStruct: public MspPollingConfigStruct {
|
struct MspIrqConfigStruct: public MspPollingConfigStruct {
|
||||||
|
MspIrqConfigStruct(): MspPollingConfigStruct() {};
|
||||||
|
MspIrqConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||||
|
MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||||
|
|
||||||
SpiBus spiBus = SpiBus::SPI_1;
|
SpiBus spiBus = SpiBus::SPI_1;
|
||||||
user_handler_t spiIrqHandler = nullptr;
|
user_handler_t spiIrqHandler = nullptr;
|
||||||
user_args_t spiUserArgs = nullptr;
|
user_args_t spiUserArgs = nullptr;
|
||||||
@ -53,11 +66,16 @@ struct MspIrqConfigStruct: public MspPollingConfigStruct {
|
|||||||
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
||||||
argument */
|
argument */
|
||||||
struct MspDmaConfigStruct: public MspIrqConfigStruct {
|
struct MspDmaConfigStruct: public MspIrqConfigStruct {
|
||||||
|
MspDmaConfigStruct(): MspIrqConfigStruct() {};
|
||||||
|
MspDmaConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||||
|
MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||||
void (* dmaClkEnableWrapper) (void) = nullptr;
|
void (* dmaClkEnableWrapper) (void) = nullptr;
|
||||||
dma::DMAIndexes txDmaIndex;
|
|
||||||
dma::DMAIndexes rxDmaIndex;
|
dma::DMAIndexes txDmaIndex = dma::DMAIndexes::DMA_1;
|
||||||
dma::DMAStreams txDmaStream;
|
dma::DMAIndexes rxDmaIndex = dma::DMAIndexes::DMA_1;
|
||||||
dma::DMAStreams rxDmaStream;
|
dma::DMAStreams txDmaStream = dma::DMAStreams::STREAM_0;
|
||||||
|
dma::DMAStreams rxDmaStream = dma::DMAStreams::STREAM_0;
|
||||||
IRQn_Type txDmaIrqNumber = DMA1_Stream0_IRQn;
|
IRQn_Type txDmaIrqNumber = DMA1_Stream0_IRQn;
|
||||||
IRQn_Type rxDmaIrqNumber = DMA1_Stream1_IRQn;
|
IRQn_Type rxDmaIrqNumber = DMA1_Stream1_IRQn;
|
||||||
// Priorities for NVIC
|
// Priorities for NVIC
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h"
|
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||||
|
|
||||||
@ -22,27 +22,27 @@ void spiDmaClockEnableWrapper() {
|
|||||||
__HAL_RCC_DMA2_CLK_ENABLE();
|
__HAL_RCC_DMA2_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::h743zi::standardPollingCfg(MspPollingConfigStruct& cfg) {
|
void stm32h7::h743zi::standardPollingCfg(spi::MspPollingConfigStruct& cfg) {
|
||||||
cfg.setupMacroWrapper = &spiSetupWrapper;
|
cfg.setupCb = &spiSetupWrapper;
|
||||||
cfg.cleanUpMacroWrapper = &spiCleanUpWrapper;
|
cfg.cleanupCb = &spiCleanUpWrapper;
|
||||||
cfg.sckPort = GPIOA;
|
cfg.sck.port = GPIOA;
|
||||||
cfg.sckPin = GPIO_PIN_5;
|
cfg.sck.pin = GPIO_PIN_5;
|
||||||
cfg.misoPort = GPIOA;
|
cfg.miso.port = GPIOA;
|
||||||
cfg.misoPin = GPIO_PIN_6;
|
cfg.miso.pin = GPIO_PIN_6;
|
||||||
cfg.mosiPort = GPIOA;
|
cfg.mosi.port = GPIOA;
|
||||||
cfg.mosiPin = GPIO_PIN_7;
|
cfg.mosi.pin = GPIO_PIN_7;
|
||||||
cfg.sckAlternateFunction = GPIO_AF5_SPI1;
|
cfg.sck.altFnc = GPIO_AF5_SPI1;
|
||||||
cfg.mosiAlternateFunction = GPIO_AF5_SPI1;
|
cfg.mosi.altFnc = GPIO_AF5_SPI1;
|
||||||
cfg.misoAlternateFunction = GPIO_AF5_SPI1;
|
cfg.miso.altFnc = GPIO_AF5_SPI1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
void stm32h7::h743zi::standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||||
IrqPriorities spiSubprio) {
|
IrqPriorities spiSubprio) {
|
||||||
// High, but works on FreeRTOS as well (priorities range from 0 to 15)
|
// High, but works on FreeRTOS as well (priorities range from 0 to 15)
|
||||||
cfg.preEmptPriority = spiIrqPrio;
|
cfg.preEmptPriority = spiIrqPrio;
|
||||||
cfg.subpriority = spiSubprio;
|
cfg.subpriority = spiSubprio;
|
||||||
cfg.spiIrqNumber = SPI1_IRQn;
|
cfg.spiIrqNumber = SPI1_IRQn;
|
||||||
cfg.spiBus = SpiBus::SPI_1;
|
cfg.spiBus = spi::SpiBus::SPI_1;
|
||||||
user_handler_t spiUserHandler = nullptr;
|
user_handler_t spiUserHandler = nullptr;
|
||||||
user_args_t spiUserArgs = nullptr;
|
user_args_t spiUserArgs = nullptr;
|
||||||
getSpiUserHandler(spi::SpiBus::SPI_1, &spiUserHandler, &spiUserArgs);
|
getSpiUserHandler(spi::SpiBus::SPI_1, &spiUserHandler, &spiUserArgs);
|
||||||
@ -55,7 +55,7 @@ void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities sp
|
|||||||
standardPollingCfg(cfg);
|
standardPollingCfg(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::h743zi::standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
void stm32h7::h743zi::standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||||
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio,
|
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio,
|
||||||
IrqPriorities txSubprio, IrqPriorities rxSubprio) {
|
IrqPriorities txSubprio, IrqPriorities rxSubprio) {
|
||||||
cfg.dmaClkEnableWrapper = &spiDmaClockEnableWrapper;
|
cfg.dmaClkEnableWrapper = &spiDmaClockEnableWrapper;
|
@ -3,21 +3,20 @@
|
|||||||
|
|
||||||
#include "mspInit.h"
|
#include "mspInit.h"
|
||||||
|
|
||||||
namespace spi {
|
namespace stm32h7 {
|
||||||
|
|
||||||
namespace h743zi {
|
namespace h743zi {
|
||||||
|
|
||||||
void standardPollingCfg(MspPollingConfigStruct& cfg);
|
void standardPollingCfg(spi::MspPollingConfigStruct& cfg);
|
||||||
void standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
void standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||||
IrqPriorities spiSubprio = HIGHEST);
|
IrqPriorities spiSubprio = HIGHEST);
|
||||||
void standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
void standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||||
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio,
|
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio,
|
||||||
IrqPriorities spiSubprio = HIGHEST, IrqPriorities txSubPrio = HIGHEST,
|
IrqPriorities spiSubprio = HIGHEST, IrqPriorities txSubPrio = HIGHEST,
|
||||||
IrqPriorities rxSubprio = HIGHEST);
|
IrqPriorities rxSubprio = HIGHEST);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ */
|
#endif /* FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ */
|
Loading…
Reference in New Issue
Block a user