mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-05 18:21:54 +00:00
Move STM32 implementations into sta-stm32-core repository
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Helper macros for HAL clock queries.
|
||||
*/
|
||||
#ifndef STA_HAL_CLOCKS_HPP
|
||||
#define STA_HAL_CLOCKS_HPP
|
||||
|
||||
/**
|
||||
* @defgroup hal HAL
|
||||
* @brief HAL base implementations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup halBuildConfig Build config
|
||||
* @ingroup hal
|
||||
* @brief Build configuration options.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup halClocks Clocks
|
||||
* @ingroup hal
|
||||
* @brief HAL clock queries.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#include <sta/hal.hpp>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get function returning PCLK frequency.
|
||||
*
|
||||
* @param n Index of peripheral clock
|
||||
*/
|
||||
#define STA_HAL_GET_PCLK_FREQ_FN(n) HAL_RCC_GetPCLK ## n ## Freq
|
||||
|
||||
|
||||
// Internal helper for macro expansion
|
||||
#define _STA_HAL_GET_PCLK_FREQ_FN(n) STA_HAL_GET_PCLK_FREQ_FN(n)
|
||||
// Get instance to PCLK index map macro
|
||||
#define _STA_PCLK_IDX_MAP(type, idx) STA_ ## type ## _ ## idx ## _PCLK_IDX
|
||||
// Get HAL handle to PCLK index map macro
|
||||
#define _STA_HAL_PCLK_IDX_MAP(handle) STA_HAL_ ## handle ## _PCLK_IDX
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get function returning frequency of PCLK used by TIM.
|
||||
*
|
||||
* @param n TIM index
|
||||
*/
|
||||
#define STA_HAL_GET_TIM_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(TIM, n))
|
||||
/**
|
||||
* @brief Get function returning frequency of PCLK used by SPI interface.
|
||||
*
|
||||
* @param n SPI interface index
|
||||
*/
|
||||
#define STA_HAL_GET_SPI_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(SPI, n))
|
||||
/**
|
||||
* @brief Get function returning frequency of PCLK used by I2C interface.
|
||||
*
|
||||
* @param n I2C interface index
|
||||
*/
|
||||
#define STA_HAL_GET_I2C_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(I2C, n))
|
||||
/**
|
||||
* @brief Get function returning frequency of PCLK used by USART interface.
|
||||
*
|
||||
* @param n USART interface index
|
||||
*/
|
||||
#define STA_HAL_GET_USART_PCLK_FREQ_FN(n) _STA_HAL_GET_PCLK_FREQ_FN(_STA_PCLK_IDX_MAP(USART, n))
|
||||
|
||||
/**
|
||||
* @brief Get function returning frequency of PCLK used by HAL instance.
|
||||
*
|
||||
* @param handle Instance handle
|
||||
*/
|
||||
#define STA_HAL_GET_HANDLE_PCLK_FREQ_FN(handle) _STA_HAL_GET_PCLK_FREQ_FN(_STA_HAL_PCLK_IDX_MAP(handle))
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // STA_HAL_CLOCKS_HPP
|
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Delay functions.
|
||||
*/
|
||||
#ifndef STA_HAL_DELAY_HPP
|
||||
#define STA_HAL_DELAY_HPP
|
||||
|
||||
/**
|
||||
* @defgroup halDelay Delay
|
||||
* @ingroup hal
|
||||
* @brief HAL Delay module
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @def STA_HAL_DELAY_ENABLE
|
||||
* @brief Enable module.
|
||||
*
|
||||
* @ingroup halBuildConfig
|
||||
*/
|
||||
# define STA_HAL_DELAY_ENABLE
|
||||
|
||||
/**
|
||||
* @def STA_HAL_DELAY_US_TIM
|
||||
* @brief 1 MHz TIM instance used by sta::delayUs.
|
||||
*
|
||||
* NOTE: TIM time base must be started before use of sta::delayUs by calling sta::initHAL.
|
||||
* When using startup system task this is handled automatically.
|
||||
*
|
||||
* @ingroup halBuildConfig
|
||||
*/
|
||||
# define STA_HAL_DELAY_US_TIM
|
||||
#endif // DOXYGEN
|
||||
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_HAL_DELAY_ENABLE
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Millisecond delay.
|
||||
*
|
||||
* @param ms Milliseconds
|
||||
*
|
||||
* @ingroup halDelay
|
||||
*/
|
||||
void delayMs(uint32_t ms);
|
||||
|
||||
#ifdef STA_HAL_DELAY_US_TIM
|
||||
/**
|
||||
* @brief Microsecond delay.
|
||||
*
|
||||
* @param us Microseconds
|
||||
*
|
||||
* @ingroup halDelay
|
||||
*/
|
||||
void delayUs(uint32_t us);
|
||||
#endif // STA_HAL_DELAY_US_TIM
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_HAL_DELAY_TIM
|
||||
|
||||
#endif // STA_HAL_DELAY_HPP
|
||||
/** @} */
|
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Wrapper for HAL GPIO pins.
|
||||
*/
|
||||
#ifndef STA_HAL_GPIO_PIN_HPP
|
||||
#define STA_HAL_GPIO_PIN_HPP
|
||||
|
||||
/**
|
||||
* @defgroup halGPIO GPIO
|
||||
* @ingroup hal
|
||||
* @brief HAL GPIO module
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @def STA_HAL_GPIO_ENABLE
|
||||
* @brief Enable module.
|
||||
*
|
||||
* @ingroup halBuildConfig
|
||||
*/
|
||||
# define STA_HAL_GPIO_ENABLE
|
||||
#endif // DOXYGEN
|
||||
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_HAL_GPIO_ENABLE
|
||||
|
||||
#include <sta/intf/gpio_pin.hpp>
|
||||
#include <sta/hal.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Container for HAL GPIO Pin objects.
|
||||
*
|
||||
* @ingroup halGPIO
|
||||
*/
|
||||
class HalGpioPin : public GpioPin
|
||||
{
|
||||
public:
|
||||
HalGpioPin(GPIO_TypeDef * port, uint16_t pin);
|
||||
|
||||
void setState(GpioPinState state) override;
|
||||
|
||||
GPIO_TypeDef * getPort() const;
|
||||
uint16_t getPin() const;
|
||||
uint8_t getIndex() const;
|
||||
|
||||
private:
|
||||
GPIO_TypeDef * port_; /**< GPIO port */
|
||||
uint16_t pin_; /**< GPIO pin */
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create HalGpioPin object from pin label.
|
||||
*
|
||||
* @param label Pin label
|
||||
*
|
||||
* @ingroup halGPIO
|
||||
*/
|
||||
#define STA_HAL_GPIO_PIN(label) sta::HalGpioPin{label##_GPIO_Port, label##_Pin}
|
||||
|
||||
|
||||
#endif // STA_HAL_GPIO_ENABLE
|
||||
|
||||
#endif // STA_HAL_GPIO_PIN_HPP
|
@@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Global HAL initialization.
|
||||
*/
|
||||
#ifndef STA_HAL_INIT_HPP
|
||||
#define STA_HAL_INIT_HPP
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Initialize global HAL objects.
|
||||
*
|
||||
* @ingroup hal
|
||||
*/
|
||||
void initHAL();
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_HAL_INIT_HPP
|
@@ -1,134 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Implementations for `SpiInterface` and `SpiDevice` using HAL.
|
||||
*/
|
||||
#ifndef STA_HAL_SPI_HPP
|
||||
#define STA_HAL_SPI_HPP
|
||||
|
||||
/**
|
||||
* @defgroup halSPI SPI
|
||||
* @ingroup hal
|
||||
* @brief HAL SPI module.
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @def STA_HAL_SPI_ENABLE
|
||||
* @brief Enable module.
|
||||
*
|
||||
* Requires **HAL_GPIO** module.
|
||||
*
|
||||
* @ingroup halBuildConfig
|
||||
*/
|
||||
# define STA_HAL_SPI_ENABLE
|
||||
#endif // DOXYGEN
|
||||
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_HAL_SPI_ENABLE
|
||||
|
||||
#ifndef STA_HAL_GPIO_ENABLE
|
||||
#error "HAL GPIO module required"
|
||||
#endif // !STA_HAL_GPIO_ENABLE
|
||||
|
||||
#include <sta/hal.hpp>
|
||||
#include <sta/hal/clocks.hpp>
|
||||
#include <sta/hal/gpio_pin.hpp>
|
||||
#include <sta/intf/spi_device.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @ingroup halSPI
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get peripheral clock frequency.
|
||||
*
|
||||
* @return Clock frequency
|
||||
*/
|
||||
using HalSpiPCLKFreqFn = uint32_t (*)();
|
||||
|
||||
/**
|
||||
* @brief Info related to HAL SPI interface.
|
||||
*/
|
||||
struct HalSpiInterfaceInfo
|
||||
{
|
||||
SPI_HandleTypeDef * handle; /**< Interface handle */
|
||||
HalSpiPCLKFreqFn getPCLKFreq; /**< Getter for peripheral clock used by interface */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Implementation of `SpiInterface` interface using HAL.
|
||||
*/
|
||||
class HalSpiInterface : public SpiInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param info SPI interface info
|
||||
* @param mutex Mutex object for managing access. Pass nullptr for no access control
|
||||
*/
|
||||
HalSpiInterface(const HalSpiInterfaceInfo & info, Mutex * mutex = nullptr);
|
||||
|
||||
void transfer(uint8_t value) override;
|
||||
void transfer16(uint16_t value) override;
|
||||
void transfer(const uint8_t * buffer, size_t size) override;
|
||||
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) override;
|
||||
void receive(uint8_t * buffer, size_t size) override;
|
||||
|
||||
void fill(uint8_t value, size_t count) override;
|
||||
|
||||
const SpiSettings & settings() const override;
|
||||
|
||||
private:
|
||||
HalSpiInterfaceInfo info_; /**< SPI interface info */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Implementation of `SpiDevice` interface using HAL.
|
||||
*/
|
||||
class HalSpiDevice : public SpiDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param intf SPI interface
|
||||
* @param csPin Device CS pin
|
||||
*/
|
||||
HalSpiDevice(SpiInterface * intf, HalGpioPin csPin);
|
||||
|
||||
void select() override;
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
HalGpioPin csPin_; /**< Device CS pin */
|
||||
};
|
||||
|
||||
|
||||
/** @} */
|
||||
} // namespace sta
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get SPI interface info struct for HAL handle.
|
||||
*
|
||||
* Requires STA_HAL_<handle>_PCLK_IDX to be defined for the MCU.
|
||||
* MCU mappings are found in `core` -> sta/mcu/.hpp files.
|
||||
*
|
||||
* Check the MCUs Reference Manual RCC register documentation to see which
|
||||
* peripheral clock is used.
|
||||
*
|
||||
* @param handle SPI interface handle
|
||||
*
|
||||
* @ingroup halSPI
|
||||
*/
|
||||
#define STA_HAL_SPI_INFO(handle) sta::HalSpiInterfaceInfo{&handle, STA_HAL_GET_HANDLE_PCLK_FREQ_FN(handle)}
|
||||
|
||||
|
||||
#endif // STA_HAL_SPI_ENABLE
|
||||
|
||||
#endif // STA_HAL_SPI_HPP
|
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Implementation of UART using HAL.
|
||||
*/
|
||||
#ifndef STA_HAL_UART_HPP
|
||||
#define STA_HAL_UART_HPP
|
||||
|
||||
/**
|
||||
* @defgroup halUART UART
|
||||
* @ingroup hal
|
||||
* @brief HAL UART module.
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @def STA_HAL_UART_ENABLE
|
||||
* @brief Enable module.
|
||||
*
|
||||
* @ingroup halBuildConfig
|
||||
*/
|
||||
# define STA_HAL_UART_ENABLE
|
||||
|
||||
/**
|
||||
* @def STA_HAL_UART_DEBUG_SERIAL
|
||||
* @brief Create global sta::DebugSerial object using this HAL UART instance.
|
||||
*
|
||||
* @ingroup halBuildConfig
|
||||
*/
|
||||
# define STA_HAL_UART_DEBUG_SERIAL
|
||||
#endif // DOXYGEN
|
||||
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_HAL_UART_ENABLE
|
||||
|
||||
#include <sta/hal.hpp>
|
||||
#include <sta/intf/uart.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Implementation of UART interface using HAL.
|
||||
*
|
||||
* @ingroup halUART
|
||||
*/
|
||||
class HalUART : public UART
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param handle UART handle
|
||||
*/
|
||||
HalUART(UART_HandleTypeDef * handle);
|
||||
|
||||
void write(const uint8_t * buffer, size_t size) override;
|
||||
|
||||
private:
|
||||
UART_HandleTypeDef * handle_; /**< UART handle */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_HAL_UART_ENABLE
|
||||
|
||||
#endif // STA_HAL_UART_HPP
|
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* @brief Configuration for STM32F411xE family.
|
||||
*/
|
||||
#ifndef STA_MCU_STM32F411xE_HPP
|
||||
#define STA_MCU_STM32F411xE_HPP
|
||||
|
||||
|
||||
#ifndef STM32F411xE
|
||||
# error "MCU config incompatible"
|
||||
#endif // !STM32F411xE
|
||||
|
||||
|
||||
#include <sta/mcu/stm32base.hpp>
|
||||
|
||||
|
||||
// Peripheral clock mappings
|
||||
//
|
||||
|
||||
// TIM to PCLK
|
||||
#define STA_TIM_1_PCLK_IDX 2
|
||||
#define STA_TIM_2_PCLK_IDX 1
|
||||
#define STA_TIM_3_PCLK_IDX 1
|
||||
#define STA_TIM_4_PCLK_IDX 1
|
||||
#define STA_TIM_5_PCLK_IDX 1
|
||||
#define STA_TIM_9_PCLK_IDX 2
|
||||
#define STA_TIM_10_PCLK_IDX 2
|
||||
#define STA_TIM_11_PCLK_IDX 2
|
||||
|
||||
// SPI to PCLK
|
||||
#define STA_SPI_1_PCLK_IDX 2
|
||||
#define STA_SPI_2_PCLK_IDX 1
|
||||
#define STA_SPI_3_PCLK_IDX 1
|
||||
#define STA_SPI_4_PCLK_IDX 2
|
||||
#define STA_SPI_5_PCLK_IDX 2
|
||||
|
||||
// I2C to PCLK
|
||||
#define STA_I2C_1_PCLK_IDX 1
|
||||
#define STA_I2C_2_PCLK_IDX 1
|
||||
#define STA_I2C_3_PCLK_IDX 1
|
||||
|
||||
// USART to PCLK
|
||||
#define STA_USART_1_PCLK_IDX 2
|
||||
#define STA_USART_2_PCLK_IDX 1
|
||||
#define STA_USART_6_PCLK_IDX 2
|
||||
|
||||
|
||||
// HAL handle mappings
|
||||
//
|
||||
|
||||
#define STA_HAL_htim1_PCLK_IDX STA_TIM_1_PCLK_IDX
|
||||
#define STA_HAL_htim2_PCLK_IDX STA_TIM_2_PCLK_IDX
|
||||
#define STA_HAL_htim3_PCLK_IDX STA_TIM_3_PCLK_IDX
|
||||
#define STA_HAL_htim4_PCLK_IDX STA_TIM_4_PCLK_IDX
|
||||
#define STA_HAL_htim5_PCLK_IDX STA_TIM_5_PCLK_IDX
|
||||
#define STA_HAL_htim9_PCLK_IDX STA_TIM_9_PCLK_IDX
|
||||
#define STA_HAL_htim10_PCLK_IDX STA_TIM_10_PCLK_IDX
|
||||
#define STA_HAL_htim11_PCLK_IDX STA_TIM_11_PCLK_IDX
|
||||
|
||||
// SPI to PCLK
|
||||
#define STA_HAL_hspi1_PCLK_IDX STA_SPI_1_PCLK_IDX
|
||||
#define STA_HAL_hspi2_PCLK_IDX STA_SPI_2_PCLK_IDX
|
||||
#define STA_HAL_hspi3_PCLK_IDX STA_SPI_3_PCLK_IDX
|
||||
#define STA_HAL_hspi4_PCLK_IDX STA_SPI_4_PCLK_IDX
|
||||
#define STA_HAL_hspi5_PCLK_IDX STA_SPI_5_PCLK_IDX
|
||||
|
||||
// I2C to PCLK
|
||||
#define STA_HAL_hi2c1_PCLK_IDX STA_I2C_1_PCLK_IDX
|
||||
#define STA_HAL_hi2c2_PCLK_IDX STA_I2C_2_PCLK_IDX
|
||||
#define STA_HAL_h12c3_PCLK_IDX STA_I2C_3_PCLK_IDX
|
||||
|
||||
// USART to PCLK
|
||||
#define STA_HAL_husart1_PCLK_IDX STA_USART_1_PCLK_IDX
|
||||
#define STA_HAL_husart2_PCLK_IDX STA_USART_2_PCLK_IDX
|
||||
#define STA_HAL_husart6_PCLK_IDX STA_USART_6_PCLK_IDX
|
||||
|
||||
|
||||
#endif // STA_MCU_STM32F411xE_HPP
|
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* @brief Configuration for STM32F413xx family.
|
||||
*/
|
||||
#ifndef STA_MCU_STM32F413xx_HPP
|
||||
#define STA_MCU_STM32F413xx_HPP
|
||||
|
||||
|
||||
#ifndef STM32F413xx
|
||||
# error "MCU config incompatible"
|
||||
#endif // !STM32F413xx
|
||||
|
||||
|
||||
#include <sta/mcu/stm32base.hpp>
|
||||
|
||||
|
||||
#endif // STA_MCU_STM32F413xx_HPP
|
@@ -1,12 +0,0 @@
|
||||
/**
|
||||
* @brief Common configuration for STM32 MCUs
|
||||
*/
|
||||
#ifndef STA_MCU_STM32_BASE_HPP
|
||||
#define STA_MCU_STM32_BASE_HPP
|
||||
|
||||
|
||||
// TODO: Are all STM32 MCUs little endian?
|
||||
#define STA_MCU_LITTLE_ENDIAN
|
||||
|
||||
|
||||
#endif // STA_MCU_STM32_BASE_HPP
|
Reference in New Issue
Block a user