diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/mcu-stm32/CMakeLists.txt | 76 | ||||
-rw-r--r-- | cmake/mcu-stm32/conf/stm32f10x_conf.h | 18 | ||||
-rw-r--r-- | cmake/stm32.toolchain.cmake | 17 |
3 files changed, 109 insertions, 2 deletions
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 diff --git a/cmake/stm32.toolchain.cmake b/cmake/stm32.toolchain.cmake index 05a9090..3d39bce 100644 --- a/cmake/stm32.toolchain.cmake +++ b/cmake/stm32.toolchain.cmake @@ -37,8 +37,21 @@ set(LINKER_FLAGS "-nostdlib -Wl,--gc-sections ${TARGET_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE) -cmake_force_c_compiler("${TOOLCHAIN_ROOT}/bin/${TRIPLE}-gcc" GNU) -cmake_force_cxx_compiler("${TOOLCHAIN_ROOT}/bin/${TRIPLE}-g++" GNU) +# Old style +#cmake_force_c_compiler("${TOOLCHAIN_ROOT}/bin/${TRIPLE}-gcc" GNU) +#cmake_force_cxx_compiler("${TOOLCHAIN_ROOT}/bin/${TRIPLE}-g++" GNU) + +find_program(ARM_CC arm-none-eabi-gcc ${TOOLCHAIN_ROOT}/bin) +find_program(ARM_CXX arm-none-eabi-g++ ${TOOLCHAIN_ROOT}/bin) +find_program(ARM_OBJCOPY arm-none-eabi-objcopy ${TOOLCHAIN_ROOT}/bin) +find_program(ARM_SIZE arm-none-eabi-size ${TOOLCHAIN_ROOT}/bin) +find_program(ARM_NM arm-none-eabi-nm ${TOOLCHAIN_ROOT}/bin) + +# New style, from 3.6 +set(CMAKE_C_COMPILER ${ARM_CC} CACHE FILE "") +set(CMAKE_CXX_COMPILER ${ARM_CXX} CACHE FILE "") +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + # search for programs in the build host directories set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # for libraries and headers in the target directories |