From 7f89aea2016ebde61b02914abc7984df50537f29 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 25 Jan 2017 22:02:09 +0100 Subject: o Improving the mcu-stm32 cmake library a bit. Starting on a USB example. --- cmake/mcu-stm32/CMakeLists.txt | 76 +++++++++++++++++++++++++++++++++++ cmake/mcu-stm32/conf/stm32f10x_conf.h | 18 +++++++++ 2 files changed, 94 insertions(+) create mode 100644 cmake/mcu-stm32/CMakeLists.txt create mode 100644 cmake/mcu-stm32/conf/stm32f10x_conf.h (limited to 'cmake/mcu-stm32') diff --git a/cmake/mcu-stm32/CMakeLists.txt b/cmake/mcu-stm32/CMakeLists.txt new file mode 100644 index 0000000..424d3ab --- /dev/null +++ b/cmake/mcu-stm32/CMakeLists.txt @@ -0,0 +1,76 @@ +set(MCU_BASEDIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "foo" FORCE) + +if (POLICY CMP0057) + cmake_policy(SET CMP0057 NEW) +else () + # We need IN_LIST + message(FATAL_ERROR "CMake 3.3+ is required") +endif () + +function(mcu_stm32_add_library) + set(options) + set(oneValueArgs TARGET DEVICE DEFAULT_ASSERT_PARAM DEFINES_VAR) + set(multiValueArgs PARTS) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # TODO: validate the device + + add_library(${ARG_TARGET} + ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/CoreSupport/core_cm3.c + ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c + ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/misc.c + ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c + ) + list(REMOVE_ITEM ARG_PARTS RCC) + + set(EXPORT_DEFINES ${ARG_DEVICE} + USE_STDPERIPH_DRIVER) + + target_include_directories(${ARG_TARGET} PUBLIC + ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/CoreSupport + ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x + ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/inc + ) + + if (NOT DEFINED ARG_DEFAULT_ASSERT_PARAM) + set(ARG_DEFAULT_ASSERT_PARAM TRUE) + endif () + + if (ARG_DEFAULT_ASSERT_PARAM) + target_include_directories(${ARG_TARGET} PUBLIC ${MCU_BASEDIR}/conf) + endif () + + if (DMA IN_LIST ARG_PARTS) + list(REMOVE_ITEM ARG_PARTS DMA) + target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c) + endif () + + if (GPIO IN_LIST ARG_PARTS) + list(REMOVE_ITEM ARG_PARTS GPIO) + target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c) + endif () + + if (SPI IN_LIST ARG_PARTS) + list(REMOVE_ITEM ARG_PARTS SPI) + target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c) + endif () + + if (USART IN_LIST ARG_PARTS) + list(REMOVE_ITEM ARG_PARTS USART) + target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c) + endif () + + list(LENGTH ARG_PARTS l) + if (${l} GREATER 0) + message(FATAL_ERROR "Unknown parts: ${ARG_PARTS}") + endif () + + if (DEFINES_VAR) + set(" ${DEFINES_FROM_MCU_STM32} " ${EXPORT_DEFINES} PARENT_SCOPE) + endif () + + # Set all the defines we want the consumers to use on these objects too + target_compile_definitions(${ARG_TARGET} PUBLIC + ${EXPORT_DEFINES}) + +endfunction() diff --git a/cmake/mcu-stm32/conf/stm32f10x_conf.h b/cmake/mcu-stm32/conf/stm32f10x_conf.h new file mode 100644 index 0000000..c8f4a4d --- /dev/null +++ b/cmake/mcu-stm32/conf/stm32f10x_conf.h @@ -0,0 +1,18 @@ +#ifndef __STM32F10x_CONF_H +#define __STM32F10x_CONF_H + +#ifdef USE_FULL_ASSERT +#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) + +#ifdef __cplusplus +extern "C" { +#endif + void assert_failed(uint8_t* file, uint32_t line); +#ifdef __cplusplus +} +#endif +#else +#define assert_param(expr) ((void)0) +#endif + +#endif -- cgit v1.2.3