diff --git a/include/sta/devices/stm32/mcu/STM32F407xx.hpp b/include/sta/devices/stm32/mcu/STM32F407xx.hpp index 3a3b61d..bc0fca2 100644 --- a/include/sta/devices/stm32/mcu/STM32F407xx.hpp +++ b/include/sta/devices/stm32/mcu/STM32F407xx.hpp @@ -12,17 +12,24 @@ # error "MCU config incompatible" #endif // STM32F407xx +// If the chip follows the ASEAG design use huart1. +#if defined(STA_STM32_ASEAG) && !defined(STA_STM32_SWD_USART_IDX) +# define STA_STM32_SWD_USART_IDX 1 +#endif + +// The default UART handle for STM32 F407 Nucleos is huart2. +#ifndef STA_STM32_SWD_USART_IDX +# define STA_STM32_SWD_USART_IDX 2 +#endif // STA_STM32_SWD_USART_IDX + + +// Initialize the default config for all STM32 microcontrollers. #include -// uart/CAN setup + #ifdef STA_STM32_ASEAG -# define STA_STM32_USART_HANDLE huart1 -# define STA_STM32_CAN_HANDLE hcan1 -#else -# ifdef STA_STM32_SWD_USART_IDX -# define STA_STM32_USART_HANDLE CONCAT(huart, STA_STM32_SWD_USART_IDX) -# endif // STA_STM32_SWD_USART_IDX -#endif // STA_STM32_SWD_USART_IDX +# define STA_STM32_CAN_HANDLE hcan1 +#endif // STA_STM32_ASEAG /** * @ingroup sta_core_stm32_mcu_stm32f407xx diff --git a/include/sta/devices/stm32/mcu/STM32F411xE.hpp b/include/sta/devices/stm32/mcu/STM32F411xE.hpp index 56608f5..93ae608 100644 --- a/include/sta/devices/stm32/mcu/STM32F411xE.hpp +++ b/include/sta/devices/stm32/mcu/STM32F411xE.hpp @@ -16,18 +16,21 @@ #endif // !STM32F411xE -#include +// If the chip follows the ASEAG design use huart1. +#if defined(STA_STM32_ASEAG) && !defined(STA_STM32_SWD_USART_IDX) +# define STA_STM32_SWD_USART_IDX 1 +#endif -// uart setup -#ifdef STA_STM32_ASEAG -# define STA_STM32_USART_HANDLE huart1 -#else -# ifdef STA_STM32_SWD_USART_IDX -# define STA_STM32_USART_HANDLE huart2 -# endif // STA_STM32_SWD_USART_IDX +// The default UART handle for STM32 F411 Nucleos is huart2. +#ifndef STA_STM32_SWD_USART_IDX +# define STA_STM32_SWD_USART_IDX 2 #endif // STA_STM32_SWD_USART_IDX +// Initialize the default config for all STM32 microcontrollers. +#include + + /** * @ingroup sta_core_stm32_mcu_stm32f411xe * @{ diff --git a/include/sta/devices/stm32/mcu/STM32U5xx.hpp b/include/sta/devices/stm32/mcu/STM32U5xx.hpp new file mode 100644 index 0000000..157d140 --- /dev/null +++ b/include/sta/devices/stm32/mcu/STM32U5xx.hpp @@ -0,0 +1,69 @@ +/** + * @defgroup sta_core_stm32_mcu STM32 MCUs + * @ingroup sta_core_stm32 +*/ + +#ifndef STA_CORE_STM32_MCU_STM32U5A5_HPP +#define STA_CORE_STM32_MCU_STM32U5A5_HPP + +#ifndef STM32_U5xx +# error "MCU config incompatible" +#endif // STM32_YOUR_MCU_xx + +// Add the default uart index for Nucleos using this chip here. +#ifndef STA_STM32_SWD_USART_IDX +# define STA_STM32_SWD_USART_IDX 2 +#endif // STA_STM32_SWD_USART_IDX + +#include + +// Peripheral clock mappings +// + +// TIM to PCLK +/** + * Look up the datasheet for the MCU you are using. There you will find a functional + * diagram, where all timers (e.g. "TIM1") are displayed. They are all connected to a + * "Advanced Peripheral Bus" (APB). Since there are multiple of them (e.g. APB1 and APB2), + * you have to map each timer to the APB it is connected to: + */ +#define STA_STM32_TIM_1_PCLK_IDX 1 +// ... + +// SPI to PCLK +// Do the same for SPI... +#define STA_STM32_SPI_1_PCLK_IDX 2 + +// I2C to PCLK +// Do the same for I2C... +#define STA_STM32_I2C_1_PCLK_IDX 1 + +// USART to PCLK +// Do the same for USART... +#define STA_STM32_USART_1_PCLK_IDX 2 + + +// HAL handle mappings +// + +// TIM to PCLK# +/** + * This section is straightforward. We only map the handles of the different timers + * to the corresponding indices we defined before. For example "htim1" is the handle + * for TIM1 which means that we need the following mapping: + */ +#define STA_STM32_htim1_PCLK_IDX STA_STM32_TIM_1_PCLK_IDX + +// SPI to PCLK +// Do the same for SPI... +#define STA_STM32_hspi1_PCLK_IDX STA_STM32_SPI_1_PCLK_IDX + +// I2C to PCLK +// Do the same for I2C... +#define STA_STM32_hi2c1_PCLK_IDX STA_STM32_I2C_1_PCLK_IDX + +// USART to PCLK +// Do the same for USART... +#define STA_STM32_husart1_PCLK_IDX STA_STM32_USART_1_PCLK_IDX + +#endif // STA_CORE_STM32_MCU_STM32U5A5_HPP diff --git a/include/sta/devices/stm32/mcu/common.hpp b/include/sta/devices/stm32/mcu/common.hpp index 5c809b2..2521987 100644 --- a/include/sta/devices/stm32/mcu/common.hpp +++ b/include/sta/devices/stm32/mcu/common.hpp @@ -5,6 +5,8 @@ #ifndef STA_CORE_STM32_MCU_COMMON_HPP #define STA_CORE_STM32_MCU_COMMON_HPP +#include + // TODO: Are all STM32 MCUs little endian? #define STA_MCU_LITTLE_ENDIAN @@ -14,4 +16,10 @@ #define STA_PLATFORM_STM32 +// Define the USART handle based on the provided USART idx. +#ifdef STA_STM32_SWD_USART_IDX +# define STA_STM32_USART_HANDLE STA_CONCAT(huart, STA_STM32_SWD_USART_IDX) +#endif // STA_STM32_SWD_USART_IDX + + #endif // STA_CORE_STM32_MCU_COMMON_HPP diff --git a/include/sta/devices/stm32/mcu/template.hpp b/include/sta/devices/stm32/mcu/template.hpp index 022529b..d801283 100644 --- a/include/sta/devices/stm32/mcu/template.hpp +++ b/include/sta/devices/stm32/mcu/template.hpp @@ -10,6 +10,11 @@ # error "MCU config incompatible" #endif // STM32_YOUR_MCU_xx +// Add the default uart index for Nucleos using this chip here. +#ifndef STA_STM32_SWD_USART_IDX +# define STA_STM32_SWD_USART_IDX 2 +#endif // STA_STM32_SWD_USART_IDX + #include // Peripheral clock mappings @@ -63,4 +68,4 @@ // Aaaaaaand we're done! -#endif // STA_CORE_STM32_MCU_TEMPLATE_HPP \ No newline at end of file +#endif // STA_CORE_STM32_MCU_TEMPLATE_HPP diff --git a/include/sta/lang.hpp b/include/sta/lang.hpp index 037823f..df8bfdd 100644 --- a/include/sta/lang.hpp +++ b/include/sta/lang.hpp @@ -122,6 +122,26 @@ #endif // !STA_FALLTRHOUGH +/** + * @brief A macro for concatenating preprocessor tokens A and B without expanding them. + * @param A first preprocessor token. + * @param B second preprocessor token. + */ +#ifndef STA_CONCAT_NX +# define STA_CONCAT_NX(A, B) A ## B +#endif // !STA_CONCAT_NX + + +/** + * @brief Macro-expands A and B first and concatenates them afterwards. + * @param A first preprocessor token. + * @param B second preprocessor token. + */ +#ifndef STA_CONCAT +# define STA_CONCAT(A, B) STA_CONCAT_NX(A, B) +#endif // !STA_CONCAT + + /** @} */ #endif // STA_CORE_LANG_HPP diff --git a/include/sta/printf.hpp b/include/sta/printf.hpp index c738424..fcb6bb8 100644 --- a/include/sta/printf.hpp +++ b/include/sta/printf.hpp @@ -3,7 +3,6 @@ * @brief Compatibility layer for different printf implementations. * * Configuration: - * * STA_PRINTF_USE_STDLIB: Use printf implementation from standard library * * STA_PRINTF_USE_MPALAND: Use printf implementation from Marco Paland */ #ifndef STA_CORE_PRINTF_HPP @@ -11,16 +10,11 @@ #include -#if !defined(STA_PRINTF_USE_STDLIB) && !defined(STA_PRINTF_USE_MPALAND) -# error "No printf implementation chosen!" -#endif // !STA_PRINTF_USE_STDLIB && !STA_PRINTF_USE_MPALAND - -#ifdef STA_PRINTF_USE_STDLIB -# include -#endif // STA_PRINTF_USE_STDLIB #ifdef STA_PRINTF_USE_MPALAND # include +#else +# include #endif // STA_PRINTF_USE_MPALAND