From 4c546820fdb28bf46fae6606716ae34e2f4ba950 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 31 May 2021 20:40:16 +0200 Subject: [PATCH] added gyrol3gd20h stm32 test file --- stm32h7/CMakeLists.txt | 1 + stm32h7/devicetest/CMakeLists.txt | 3 +++ stm32h7/devicetest/GyroL3GD20H.cpp | 35 ++++++++++++++++++++++++++++++ stm32h7/devicetest/GyroL3GD20H.h | 21 ++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 stm32h7/devicetest/CMakeLists.txt create mode 100644 stm32h7/devicetest/GyroL3GD20H.cpp create mode 100644 stm32h7/devicetest/GyroL3GD20H.h diff --git a/stm32h7/CMakeLists.txt b/stm32h7/CMakeLists.txt index e69de29..9197332 100644 --- a/stm32h7/CMakeLists.txt +++ b/stm32h7/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(devicetest) diff --git a/stm32h7/devicetest/CMakeLists.txt b/stm32h7/devicetest/CMakeLists.txt new file mode 100644 index 0000000..dab7eaf --- /dev/null +++ b/stm32h7/devicetest/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${TARGET_NAME} PRIVATE + GyroL3GD20H.cpp +) \ No newline at end of file diff --git a/stm32h7/devicetest/GyroL3GD20H.cpp b/stm32h7/devicetest/GyroL3GD20H.cpp new file mode 100644 index 0000000..567b8e8 --- /dev/null +++ b/stm32h7/devicetest/GyroL3GD20H.cpp @@ -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; +} diff --git a/stm32h7/devicetest/GyroL3GD20H.h b/stm32h7/devicetest/GyroL3GD20H.h new file mode 100644 index 0000000..29edacb --- /dev/null +++ b/stm32h7/devicetest/GyroL3GD20H.h @@ -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 + +#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_ */