Explorar el Código

Add F0 family support

JocusSoft hace 10 años
padre
commit
93780f00ae
Se han modificado 4 ficheros con 108 adiciones y 89 borrados
  1. 1 88
      README.md
  2. 9 0
      cmake/FindCMSIS.cmake
  3. 1 1
      cmake/gcc_stm32.cmake
  4. 97 0
      cmake/gcc_stm32f0.cmake

+ 1 - 88
README.md

@@ -1,92 +1,5 @@
 # About
 
-This project is used to develop applications for the STM32 - ST's ARM Cortex-M3(4) MCUs. It uses cmake and GCC, along with newlib (libc), STM32CubeMX or ChibiOS.
+This project is used to develop applications for the STM32 - ST's ARM Cortex-Mx MCUs. It uses cmake and GCC, along with newlib (libc), STM32CubeMX or ChibiOS.
 
-## Requirements
 
-* cmake >= 2.8
-* GCC toolchain with newlib (optional).
-* STM32CubeMX package for STM32F1, STM32F2 or STM32F4 families.
-
-## Project contains
-
-* CMake common toolchain file, that configures cmake to use the arm toolchain.
-* CMake toolchain file that can generate a tunable linker script
-* CMake STM32 family-specific toolchain file, that configures family-specific parameters.
-* CMake modules to find and configure CMSIS and STM32HAL components.
-* CMake modules to find and configure ChibiOS components.
-* CMake project template.
-
-## Examples
-
-* `stm32-blinky` - blink LED using timers and PWM.
-* `stm32-newlib` - show date using uart and libc functions from newlib.
-* `stm32-chibios` - blink led using ChibiOS/NIL.
-
-# Usage
-
-First of all you need to configure toolchain and libraries, you can do this by editing `gcc_stm32.cmake` or, preferably, by passing it through the command line.
-
-## Configuration
-
-* `TOOLCHAIN_PREFIX` - where toolchain is located, **default**: `/usr`
-* `TARGET_TRIPLET` - toolchain target triplet, **default**: `arm-none-eabi`
-* `STM32_CHIP` - STM32 device code, e.g. `STM32F407VG` or `STM32F103VG`
-* `STM32_FAMILY` - STM32 family (F0, F1, F4, etc.) currently, F1, F2 and F4 family are supported. **Note:** If `STM32_CHIP` variable is set, `STM32_FAMILY` is optional.
-* `STM32Cube_DIR` - path to STM32CubeMX directory **default**: `/opt/STM32Cube_FW_F1_V1.1.0 /opt/STM32Cube_FW_F2_V1.1.0 /opt/STM32Cube_FW_F4_V1.6.0`
-
-To use the toolchain, you'll need to copy contents of the `cmake` folder into cmake's modules path, or use the `CMAKE_MODULE_PATH` variable.
-
-## Common usage
-
-    cmake -DSTM32_CHIP=<chip> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Debug <path_to_source_dir>
-
-Where `<chip>` is the STM32 chip name (e.g. `STM32F100C8`, `STM32F407IG`).
-
-This command will generate Makefile for project. For a `Release` build, change `CMAKE_BUILD_TYPE`.
-
-The script will try to detect chip parameters automatically from the chip name (type, flash/ram size), or, you can set these directly with these variables:
-
-* `STM32_CHIP_TYPE` - family-dependent chip type. Global variable `STM32_CHIP_TYPES` contains list of valid types for current family (e.g `207xG`)
-* `STM32_FLASH_SIZE` - chip flash size (e.g. 64K)
-* `STM32_RAM_SIZE` - chip RAM size (e.g. 4K)
-
-### Usage with Eclipse CDT:
-
-    cmake -DSTM32_CHIP=<chip> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Debug -G "Eclipse CDT4 - Unix Makefiles" <path_to_source_dir>
-
-## Building
-
-* To build elf file: `make`
-* To build .hex: `make <project name>.hex`
-* To build .bin: `make <project name>.bin`
-
-## Linker script & variables
-
-You can use cmake variables below to tune the generated linker. To specify a custom linker script, set `STM32_LINKER_SCRIPT` (you can still use these variables in your custom script).
-
-* `STM32_FLASH_ORIGIN` - Start address of flash (**default**: 0x08000000)
-* `STM32_RAM_ORIGIN` - Start address of RAM (**default**: 0x20000000)
-* `STM32_FLASH_SIZE` - Flash size (**default**: from chip name)
-* `STM32_RAM_SIZE` - RAM size (**default**: from chip name)
-* `STM32_MIN_STACK_SIZE` - Minimum stack size for error detection at link-time (**default**: 512 bytes)
-* `STM32_MIN_HEAP_SIZE` - Minimum heap size for error detection at link-time (**default**: 0 bytes)
-* `STM32_CCRAM_ORIGIN` - Start address of Core-Coupled RAM (only for F4 family) (**default**: 0x10000000)
-* `STM32_CCRAM_SIZE` - Core-Coupled RAM size (only for F4 family) (**default**: 64 KiB)
-
-## Useful cmake macros
-
-* `STM32_GET_CHIP_TYPE(CHIP CHIP_TYPE)` - gets chip type from chip name.
-* `STM32_GET_CHIP_PARAMETERS(CHIP FLASH_SIZE RAM_SIZE)` - gets chip ram/flash size from chip name.
-* `STM32_SET_FLASH_PARAMS(TARGET ...)` - sets chip flash/ram parameters for target.
-* `STM32_SET_CHIP_DEFINITIONS(TARGET CHIP_TYPE)` - sets chip family and type-specific compiler flags for target.
-* `STM32_SET_TARGET_PROPERTIES(TARGET)` - sets all needed parameters and compiler flags for target.
-* `STM32_GENERATE_LIBRARIES(NAME SOURCES LIBRARIES)` - generates libraries for all chip types in family. Resulting libraries stored in LIBRARIES and have names in ${NAME}_${FAMILY}_${CHIP_TYPE} format.
-
-# ChibiOS Support
-
-This project also supports ChibiOS v3.x.x (both nil and rt kernels).
-
-CMake modules for ChibiOS can find specified ChibiOS components using the COMPONENTS directive.
-
-See project `stm32-chibios` for example usage.

+ 9 - 0
cmake/FindCMSIS.cmake

@@ -48,6 +48,15 @@ ELSEIF(STM32_FAMILY STREQUAL "F4")
     LIST(APPEND CMSIS_COMMON_HEADERS core_cm4.h)
     SET(CMSIS_DEVICE_HEADERS stm32f4xx.h system_stm32f4xx.h)
     SET(CMSIS_DEVICE_SOURCES system_stm32f4xx.c)
+ELSEIF(STM32_FAMILY STREQUAL "F0")
+    IF(NOT STM32Cube_DIR)
+        SET(STM32Cube_DIR "/opt/STM32Cube_FW_F0_V1.4.0")
+        MESSAGE(STATUS "No STM32Cube_DIR specified, using default: " ${STM32Cube_DIR})
+    ENDIF()
+
+    LIST(APPEND CMSIS_COMMON_HEADERS core_cm3.h)
+    SET(CMSIS_DEVICE_HEADERS stm32f0xx.h system_stm32f0xx.h)
+    SET(CMSIS_DEVICE_SOURCES system_stm32f0xx.c)
 ENDIF()
 
 IF(NOT CMSIS_STARTUP_SOURCE)

+ 1 - 1
cmake/gcc_stm32.cmake

@@ -1,6 +1,6 @@
 INCLUDE(CMakeForceCompiler)
 
-SET(STM32_SUPPORTED_FAMILIES F1 F2 F4 CACHE INTERNAL "stm32 supported families")
+SET(STM32_SUPPORTED_FAMILIES F0 F1 F2 F4 CACHE INTERNAL "stm32 supported families")
 
 IF(NOT TOOLCHAIN_PREFIX)
      SET(TOOLCHAIN_PREFIX "/usr")

+ 97 - 0
cmake/gcc_stm32f0.cmake

@@ -0,0 +1,97 @@
+SET(CMAKE_C_FLAGS "-mthumb -fno-builtin -mcpu=cortex-m0 -Wall -std=gnu99 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize" CACHE INTERNAL "c compiler flags")
+SET(CMAKE_CXX_FLAGS "-mthumb -fno-builtin -mcpu=cortex-m0 -Wall -std=c++11 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize" CACHE INTERNAL "cxx compiler flags")
+SET(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m0 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections -mthumb -mcpu=cortex-m0 -mabi=aapcs" CACHE INTERNAL "executable linker flags")
+SET(CMAKE_MODULE_LINKER_FLAGS "-mthumb -mcpu=cortex-m0 -mabi=aapcs" CACHE INTERNAL "module linker flags")
+SET(CMAKE_SHARED_LINKER_FLAGS "-mthumb -mcpu=cortex-m0 -mabi=aapcs" CACHE INTERNAL "shared linker flags")
+
+SET(STM32_CHIP_TYPES 030xC 031x6 038x6 042x6 048x6 051x8 058x8 070xB 071xB 072xB 078xB 091xC 098xC CACHE INTERNAL "stm32f0 chip types")
+SET(STM32_CODES "030.[468C]" "031.[46]" "038.6" "042.[46]" "048.6" "051.[468]" "058.8" "070.[6B]" "071.[8B]" "072.[8B]" "078.B" "091.[BC]" "098.C")
+
+MACRO(STM32_GET_CHIP_TYPE CHIP CHIP_TYPE)
+    STRING(REGEX REPLACE "^[sS][tT][mM]32[fF]((03[018].[468C])|(04[28].[46])|(05[18].[468])|(07[0128].[68B])|(09[18].[BC])).+$" "\\1" STM32_CODE ${CHIP})
+    SET(INDEX 0)
+    FOREACH(C_TYPE ${STM32_CHIP_TYPES})
+        LIST(GET STM32_CODES ${INDEX} CHIP_TYPE_REGEXP)
+        IF(STM32_CODE MATCHES ${CHIP_TYPE_REGEXP})
+            SET(RESULT_TYPE ${C_TYPE})
+        ENDIF()
+        MATH(EXPR INDEX "${INDEX}+1")
+    ENDFOREACH()
+    SET(${CHIP_TYPE} ${RESULT_TYPE})
+ENDMACRO()
+
+MACRO(STM32_GET_CHIP_PARAMETERS CHIP FLASH_SIZE RAM_SIZE)
+    STRING(REGEX REPLACE "^[sS][tT][mM]32[fF](0[34579][0128]).[468BC]" "\\1" STM32_CODE ${CHIP})
+    STRING(REGEX REPLACE "^[sS][tT][mM]32[fF]0[34579][0128].([468BC])" "\\1" STM32_SIZE_CODE ${CHIP})
+
+    IF(STM32_SIZE_CODE STREQUAL "4")
+        SET(FLASH "16K")
+    ELSEIF(STM32_SIZE_CODE STREQUAL "6")
+        SET(FLASH "32K")
+    ELSEIF(STM32_SIZE_CODE STREQUAL "8")
+        SET(FLASH "64K")
+    ELSEIF(STM32_SIZE_CODE STREQUAL "B")
+        SET(FLASH "128K")
+    ELSEIF(STM32_SIZE_CODE STREQUAL "C")
+        SET(FLASH "256K")
+    ENDIF()
+
+    STM32_GET_CHIP_TYPE(${CHIP} TYPE)
+
+    IF(${TYPE} STREQUAL 030xC)
+        IF((STM32_SIZE_CODE STREQUAL "4") OR (STM32_SIZE_CODE STREQUAL "6"))
+            SET(RAM "4K")
+	ELSEIF(STM32_SIZE_CODE STREQUAL "8")
+	    SET(RAM "8K")
+        ELSE()
+            SET(RAM "32K")
+        ENDIF()
+    ELSEIF(${TYPE} STREQUAL 031x6)
+            SET(RAM "4K")
+    ELSEIF(${TYPE} STREQUAL 038x6)
+            SET(RAM "4K")
+    ELSEIF(${TYPE} STREQUAL 042x6)
+            SET(RAM "6K")
+    ELSEIF(${TYPE} STREQUAL 048x6)
+            SET(RAM "6K")
+    ELSEIF(${TYPE} STREQUAL 051x8)
+            SET(RAM "8K")
+    ELSEIF(${TYPE} STREQUAL 058x8)
+            SET(RAM "8K")
+    ELSEIF(${TYPE} STREQUAL 070xB)
+        IF(STM32_SIZE_CODE STREQUAL "6")
+            SET(RAM "6K")
+        ELSE()
+            SET(RAM "16K")
+        ENDIF()
+    ELSEIF(${TYPE} STREQUAL 071xB)
+            SET(RAM "16K")
+    ELSEIF(${TYPE} STREQUAL 072xB)
+            SET(RAM "16K")
+    ELSEIF(${TYPE} STREQUAL 078xB)
+            SET(RAM "16K")
+    ELSEIF(${TYPE} STREQUAL 091xC)
+            SET(RAM "32K")
+    ELSEIF(${TYPE} STREQUAL 098xC)
+            SET(RAM "32K")
+    ENDIF()
+
+    SET(${FLASH_SIZE} ${FLASH})
+    SET(${RAM_SIZE} ${RAM})
+ENDMACRO()
+
+FUNCTION(STM32_SET_CHIP_DEFINITIONS TARGET CHIP_TYPE)
+    LIST(FIND STM32_CHIP_TYPES ${CHIP_TYPE} TYPE_INDEX)
+    IF(TYPE_INDEX EQUAL -1)
+        MESSAGE(FATAL_ERROR "Invalid/unsupported STM32F0 chip type: ${CHIP_TYPE}")
+    ENDIF()
+    GET_TARGET_PROPERTY(TARGET_DEFS ${TARGET} COMPILE_DEFINITIONS)
+    IF(TARGET_DEFS)
+        SET(TARGET_DEFS "STM32F0;STM32F${CHIP_TYPE};${TARGET_DEFS}")
+    ELSE()
+        SET(TARGET_DEFS "STM32F0;STM32F${CHIP_TYPE}")
+    ENDIF()
+    SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_DEFINITIONS "${TARGET_DEFS}")
+ENDFUNCTION()