sta-core/README.md
2024-05-28 12:08:23 +02:00

137 lines
3.8 KiB
Markdown

# STA Core library
![pre-release v0.1.0](https://img.shields.io/static/v1?label=pre-release&message=v0.1.0&color=orange&logo=git)
![Standard: C++11](https://img.shields.io/static/v1?label=standard&message=C%2B%2B11&color=blue&logo=cplusplus)
Collection of useful stuff.
# Modules
## Assert
Assertion handling.
Configuration:
* `#define STA_ASSERT_ENABLE`: Enable module
* `#define STA_ASSERT_DISABLE`: Forces module off when defined
* `#define STA_HALT <func_name>`: Override function called after failed asserts
* `DEBUG`: Automatically enables module when defined
* `NDEBUG`: Forces module off when defined
Both `sta::assert_failed` and `sta::assert_halt` provide weak definitions and
can be overridden by the application. `sta::assert_halt` is only called
via the **STA_HALT** macro which can also be provided by the application.
The default implementation of `sta::assert_failed` uses **STA_DEBUG_PRINT** internally
and will not generate any output if the **DEBUG_SERIAL** module is disabled.
## Debug Serial
Debug serial output macros.
Configuration:
* `#define STA_DEBUG_SERIAL_ENABLE`: Enable module
* `#define STA_DEBUG_SERIAL_FORCE`: Ignore debug defines and always enable output
* `DEBUG`: Enables output when defined
* `NDEBUG`: Disables output when defined (overrides DEBUG)
The `sta::DebugSerial` instance must be provided.
## Endian
Endian-ness conversion for multi-byte types.
## Enum Flags
Type for using enum values as combinable flags.
## Lang
Macros related to compiler features. Not actually part of the C/C++ language.
## MCU
Defines specific to different MCUs. Include the appropriate header from `sta/mcu`
for the MCU used by the application in the `<sta/config.hpp>` header.
## Printf
Choose which `printf` implementation is used by STA libraries.
Configuration:
* `#define STA_PRINTF_USE_STDLIB`: Use the stdlib implementation
* `#define STA_PRINTF_USE_MPALAND`: Use the implementation by Marco Paland (thread safe & reentrant)
Format printing floats needs to be manually enabled:
Project Properties > C/C++-Build > Settings > MCU Settings -> "Use float with printf from newlib-nano"
## HAL Delay
HAL based delay functions.
Configuration:
* `#define STA_HAL_DELAY_ENABLE`: Enable module
* `#define STA_HAL_DELAY_US_TIM <tim_handle>`: 1 MHz TIM instance used by `sta::delayUs`
TIM time base must be started before using `sta::delayUs` by calling `sta::initHAL`.
When using the startup system task this is handled automatically.
Steps to enable delayUs:
* Include sta/devices/stm32/delay.hpp in the file where the delayUs function is called
* Enable a timer TIM in .ioc file with the settings: Slave Mode=Disable, Trigger Mode=Disable, Clock Source=Internal Clock, all other channels =Disable)
* Define STA_STM32_DELAY_US_TIM in App/Inc/sta/config.hpp as the timer handle (can be found in Core/Inc/tim.h). For TIM1, this would be htim1
## Interfaces
The intention of these interfaces is to provide an abstraction layer for commonly used
resources. Libraries using these interfaces can be reused on different platforms
by simply implementing the required interfaces for the selected platform.
Interfaces for the following resources are provided:
* GPIO pin
* Mutex
* Signal
* SPI
* UART
* I2C
## HAL implementations
Implementations using the HAL are provided for the following interfaces:
* GpioPin
* SpiInterface, SpiDevice
* UART
To enable these implementations follow the instructions from the individual headers.
## Merge with STM32 Core
The merge with STM32 Core allows seamless usage of the STM32 implementations for the different Interfaces etc.
Notable inclusions:
* CAN
* I2C
* SPI
* UART
## Atomic implementations
Implementations using atomic variables are provided for the following interfaces:
* Mutex
* Signal
To enable these implementations define `STA_ATOMIC_ENABLE` in `<sta/config.hpp>`.