aboutsummaryrefslogtreecommitdiff
path: root/cmake/mcu-stm32
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-01-25 22:02:09 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2017-01-25 22:02:09 +0100
commit7f89aea2016ebde61b02914abc7984df50537f29 (patch)
treef21117d11242e26aeb880058f07263431adf869d /cmake/mcu-stm32
parent8a3fedbcb8fc58dae8b43db3cae39688ec0332ef (diff)
downloadstm32f103-playground-7f89aea2016ebde61b02914abc7984df50537f29.tar.gz
stm32f103-playground-7f89aea2016ebde61b02914abc7984df50537f29.tar.bz2
stm32f103-playground-7f89aea2016ebde61b02914abc7984df50537f29.tar.xz
stm32f103-playground-7f89aea2016ebde61b02914abc7984df50537f29.zip
o Improving the mcu-stm32 cmake library a bit. Starting on a USB example.
Diffstat (limited to 'cmake/mcu-stm32')
-rw-r--r--cmake/mcu-stm32/CMakeLists.txt76
-rw-r--r--cmake/mcu-stm32/conf/stm32f10x_conf.h18
2 files changed, 94 insertions, 0 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