Просмотр исходного кода

Add support for CMSIS 3.0.
Release builds uses -flto.

Konstantin Oblaukhov 13 лет назад
Родитель
Сommit
e90f13c06d
4 измененных файлов с 245 добавлено и 8 удалено
  1. 87 0
      cmsis-3.0/CMakeLists.txt
  2. 152 0
      cmsis-3.0/stm32_flash.ld.in
  3. 6 6
      gcc_stm32.cmake
  4. 0 2
      stdperiph/CMakeLists.txt

+ 87 - 0
cmsis-3.0/CMakeLists.txt

@@ -0,0 +1,87 @@
+PROJECT(stm32cmsis)
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+ENABLE_LANGUAGE(ASM)
+
+IF(NOT STM32_StdPeriphLib_DIR)
+    SET(STM32_StdPeriphLib_DIR "/opt/STM32F10x_StdPeriph_Lib_V3.5.0")
+    MESSAGE(STATUS "No STM32_StdPeriphLib_DIR specified, using default: " ${STM32_StdPeriphLib_DIR})
+ENDIF()
+
+IF(NOT CMSIS3_DIR)
+    SET(CMSIS3_DIR "/opt/CMSIS")
+    MESSAGE(STATUS "No CMSIS3_DIR specified, using default: " ${CMSIS3_DIR})
+ENDIF()
+
+INCLUDE_DIRECTORIES(
+    ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/
+    ${CMSIS3_DIR}/CMSIS/Include/
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+SET(CMSIS_SOURCES
+    ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c
+)
+
+SET(STM32_STARTUP_CL ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_cl.s)
+SET(STM32_STARTUP_HD ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_hd.s)
+SET(STM32_STARTUP_HD_VL ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_hd_vl.s)
+SET(STM32_STARTUP_LD ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_ld.s)
+SET(STM32_STARTUP_LD_VL ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_ld_vl.s)
+SET(STM32_STARTUP_MD ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_md.s)
+SET(STM32_STARTUP_MD_VL ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_md_vl.s)
+SET(STM32_STARTUP_XL ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_xl.s)
+
+ADD_LIBRARY(cmsis_cl ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_cl PROPERTIES COMPILE_FLAGS "-DSTM32F10X_CL")
+
+ADD_LIBRARY(cmsis_hd ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_hd PROPERTIES COMPILE_DEFINITIONS "STM32F10X_HD")
+
+ADD_LIBRARY(cmsis_hd_vl ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_hd_vl PROPERTIES COMPILE_DEFINITIONS "STM32F10X_HD_VL")
+
+ADD_LIBRARY(cmsis_ld ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_ld PROPERTIES COMPILE_DEFINITIONS "STM32F10X_LD")
+
+ADD_LIBRARY(cmsis_ld_vl ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_ld_vl PROPERTIES COMPILE_DEFINITIONS "STM32F10X_LD_VL")
+
+ADD_LIBRARY(cmsis_md ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_md PROPERTIES COMPILE_DEFINITIONS "STM32F10X_MD")
+
+ADD_LIBRARY(cmsis_md_vl ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_md_vl PROPERTIES COMPILE_DEFINITIONS "STM32F10X_MD_VL")
+
+ADD_LIBRARY(cmsis_xl ${CMSIS_SOURCES})
+SET_TARGET_PROPERTIES(cmsis_xl PROPERTIES COMPILE_DEFINITIONS "STM32F10X_XL")
+
+INSTALL(TARGETS cmsis_cl cmsis_hd cmsis_hd_vl cmsis_ld cmsis_ld_vl cmsis_md cmsis_md_vl cmsis_xl
+    RUNTIME DESTINATION bin
+    LIBRARY DESTINATION lib
+    ARCHIVE DESTINATION lib
+)
+
+INSTALL(FILES 
+    ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h
+    ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h
+    ${CMSIS3_DIR}/CMSIS/Include/core_cm3.h 
+    ${CMSIS3_DIR}/CMSIS/Include/core_cmFunc.h
+    ${CMSIS3_DIR}/CMSIS/Include/core_cmInstr.h
+    DESTINATION
+    include
+)
+
+INSTALL(FILES 
+    ${STM32_STARTUP_CL}
+    ${STM32_STARTUP_HD}
+    ${STM32_STARTUP_HD_VL}
+    ${STM32_STARTUP_MD}
+    ${STM32_STARTUP_MD_VL}
+    ${STM32_STARTUP_LD}
+    ${STM32_STARTUP_LD_VL}
+    ${STM32_STARTUP_XL}
+    ${CMAKE_CURRENT_SOURCE_DIR}/stm32_flash.ld.in
+    DESTINATION
+    share/cmsis/
+)

+ 152 - 0
cmsis-3.0/stm32_flash.ld.in

@@ -0,0 +1,152 @@
+/*
+*****************************************************************************
+**
+**  Linker script for STM32F10x devices
+**
+**  Set heap size, stack size and stack location according
+**    to application requirements.
+**
+**  Set memory bank area and size if external memory is used.
+**
+*****************************************************************************
+*/
+
+/* Entry Point */
+ENTRY(Reset_Handler)
+
+/* Highest address of the user mode stack */
+_estack = ${STACK_ADDRESS};    /* end of RAM */
+
+/* Generate a link error if heap and stack don't fit into RAM */
+_Min_Heap_Size = ${MIN_HEAP_SIZE};      /* required amount of heap  */
+_Min_Stack_Size = ${MIN_STACK_SIZE}; /* required amount of stack */
+
+/* Specify the memory areas */
+MEMORY
+{
+  FLASH (rx)      : ORIGIN = ${FLASH_ORIGIN}, LENGTH = ${FLASH_SIZE}
+  RAM (xrw)       : ORIGIN = ${RAM_ORIGIN}, LENGTH = ${RAM_SIZE}
+  MEMORY_B1 (rx)  : ORIGIN = ${EXT_RAM_ORIGIN}, LENGTH = ${EXT_RAM_SIZE}
+}
+
+/* Define output sections */
+SECTIONS
+{
+  /* The startup code goes first into FLASH */
+  .isr_vector :
+  {
+    . = ALIGN(4);
+    KEEP(*(.isr_vector)) /* Startup code */
+    . = ALIGN(4);
+  } >FLASH
+
+  /* The program code and other data goes into FLASH */
+  .text :
+  {
+    . = ALIGN(4);
+    *(.text)           /* .text sections (code) */
+    *(.text*)          /* .text* sections (code) */
+    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
+    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
+    *(.glue_7)         /* glue arm to thumb code */
+    *(.glue_7t)        /* glue thumb to arm code */
+
+    KEEP (*(.init))
+    KEEP (*(.fini))
+
+    . = ALIGN(4);
+    _etext = .;        /* define a global symbols at end of code */
+  } >FLASH
+
+
+   .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
+    .ARM : {
+    __exidx_start = .;
+      *(.ARM.exidx*)
+      __exidx_end = .;
+    } >FLASH
+
+  .ARM.attributes : { *(.ARM.attributes) } > FLASH
+
+  .preinit_array     :
+  {
+    PROVIDE_HIDDEN (__preinit_array_start = .);
+    KEEP (*(.preinit_array*))
+    PROVIDE_HIDDEN (__preinit_array_end = .);
+  } >FLASH
+  .init_array :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT(.init_array.*)))
+    KEEP (*(.init_array*))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  } >FLASH
+  .fini_array :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(.fini_array*))
+    KEEP (*(SORT(.fini_array.*)))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  } >FLASH
+
+  /* used by the startup to initialize data */
+  _sidata = .;
+
+  /* Initialized data sections goes into RAM, load LMA copy after code */
+  .data : AT ( _sidata )
+  {
+    . = ALIGN(4);
+    _sdata = .;        /* create a global symbol at data start */
+    *(.data)           /* .data sections */
+    *(.data*)          /* .data* sections */
+
+    . = ALIGN(4);
+    _edata = .;        /* define a global symbol at data end */
+  } >RAM
+
+  /* Uninitialized data section */
+  . = ALIGN(4);
+  .bss :
+  {
+    /* This is used by the startup in order to initialize the .bss secion */
+    _sbss = .;         /* define a global symbol at bss start */
+    __bss_start__ = _sbss;
+    *(.bss)
+    *(.bss*)
+    *(COMMON)
+
+    . = ALIGN(4);
+    _ebss = .;         /* define a global symbol at bss end */
+    __bss_end__ = _ebss;
+  } >RAM
+
+  PROVIDE ( end = _ebss );
+  PROVIDE ( _end = _ebss );
+
+  /* User_heap_stack section, used to check that there is enough RAM left */
+  ._user_heap_stack :
+  {
+    . = ALIGN(4);
+    . = . + _Min_Heap_Size;
+    . = . + _Min_Stack_Size;
+    . = ALIGN(4);
+  } >RAM
+
+  /* MEMORY_bank1 section, code must be located here explicitly            */
+  /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
+  .memory_b1_text :
+  {
+    *(.mb1text)        /* .mb1text sections (code) */
+    *(.mb1text*)       /* .mb1text* sections (code)  */
+    *(.mb1rodata)      /* read-only data (constants) */
+    *(.mb1rodata*)
+  } >MEMORY_B1
+
+  /* Remove information from the standard libraries */
+  /DISCARD/ :
+  {
+    libc.a ( * )
+    libm.a ( * )
+    libgcc.a ( * )
+  }
+}

+ 6 - 6
gcc_stm32.cmake

@@ -31,15 +31,15 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -gstabs+" CACHE INTERNAL "c debug compiler flags
 SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -gstabs+" CACHE INTERNAL "cxx debug compiler flags")
 SET(CMAKE_ASM_FLAGS_DEBUG "-g -gstabs+" CACHE INTERNAL "asm debug compiler flags")
 
-SET(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "c release compiler flags")
-SET(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "cxx release compiler flags")
+SET(CMAKE_C_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "c release compiler flags")
+SET(CMAKE_CXX_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "cxx release compiler flags")
 SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")
 
-SET(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m3" CACHE INTERNAL "exe link flags")
-SET(CMAKE_MODULE_LINKER_FLAGS "-L${TOOLCHAIN_LIB_DIR}" CACHE INTERNAL "module link flags")
-SET(CMAKE_SHARED_LINKER_FLAGS "-L${TOOLCHAIN_LIB_DIR}" CACHE INTERNAL "shared link flags")
+SET(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m3 -flto" CACHE INTERNAL "exe link flags")
+SET(CMAKE_MODULE_LINKER_FLAGS "-L${TOOLCHAIN_LIB_DIR} -mthumb -mcpu=cortex-m3 -flto" CACHE INTERNAL "module link flags")
+SET(CMAKE_SHARED_LINKER_FLAGS "-L${TOOLCHAIN_LIB_DIR} -mthumb -mcpu=cortex-m3 -flto" CACHE INTERNAL "shared link flags")
 
 SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${TARGET_TRIPLET} CACHE INTERNAL "cross root directory")
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE INTERNAL "")
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE INTERNAL "")
-SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "")
+SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "")

+ 0 - 2
stdperiph/CMakeLists.txt

@@ -9,8 +9,6 @@ IF(NOT STM32_StdPeriphLib_DIR)
 ENDIF()
 
 INCLUDE_DIRECTORIES(
-    ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/
-    ${STM32_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/CoreSupport/
     ${STM32_StdPeriphLib_DIR}/Libraries/STM32F10x_StdPeriph_Driver/inc/
     ${CMAKE_CURRENT_SOURCE_DIR}
 )