added gyrol3gd20h stm32 test file

This commit is contained in:
Robin Müller 2021-05-31 20:40:16 +02:00
parent 4ba4e45789
commit 4c546820fd
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1 @@
add_subdirectory(devicetest)

View File

@ -0,0 +1,3 @@
target_sources(${TARGET_NAME} PRIVATE
GyroL3GD20H.cpp
)

View File

@ -0,0 +1,35 @@
#include "GyroL3GD20H.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "stm32h7xx_nucleo.h"
#include "stm32h7xx_hal_spi.h"
uint8_t ALIGN_32BYTES(GyroL3GD20H::recvBuffer[recvBufferSize]);
GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle): spiHandle(spiHandle) {
}
ReturnValue_t GyroL3GD20H::performOperation() {
/*##-1- Configure the SPI peripheral #######################################*/
/* Set the SPI parameters */
spiHandle->Instance = SPI1;
spiHandle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
spiHandle->Init.Direction = SPI_DIRECTION_2LINES;
spiHandle->Init.CLKPhase = SPI_PHASE_1EDGE;
spiHandle->Init.CLKPolarity = SPI_POLARITY_LOW;
spiHandle->Init.DataSize = SPI_DATASIZE_8BIT;
spiHandle->Init.FirstBit = SPI_FIRSTBIT_MSB;
spiHandle->Init.TIMode = SPI_TIMODE_DISABLE;
spiHandle->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
spiHandle->Init.CRCPolynomial = 7;
spiHandle->Init.CRCLength = SPI_CRC_LENGTH_8BIT;
spiHandle->Init.NSS = SPI_NSS_SOFT;
spiHandle->Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
/* Recommended setting to avoid glitches */
spiHandle->Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;
spiHandle->Init.Mode = SPI_MODE_MASTER;
if(HAL_SPI_Init(spiHandle) != HAL_OK) {
sif::printWarning("Error initializing SPI\n");
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,21 @@
#ifndef FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
#define FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_spi.h"
#include <cstdint>
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
class GyroL3GD20H {
public:
GyroL3GD20H(SPI_HandleTypeDef* spiHandle);
ReturnValue_t performOperation();
private:
SPI_HandleTypeDef* spiHandle;
static constexpr size_t recvBufferSize = 32 * 10;
static uint8_t recvBuffer[recvBufferSize];
};
#endif /* FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_ */