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

Merge remote-tracking branch 'upstream/master' into garjones/allow_settings_paths_through_env

Robin Mueller 4 лет назад
Родитель
Сommit
46409a84b6

+ 37 - 0
.github/ISSUE_TEMPLATE/bug-report.md

@@ -0,0 +1,37 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**Sources to reproduce**
+Please provide link to repository showing the problem.
+ - Fork this repository
+ - Modify an existing example to show the abnormal behavior
+ - Share the link to the commit in your fork showing the problem
+
+**Steps to reproduce**
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Environment (please complete the following information):**
+ - OS: [e.g. iOS]
+ - Compiler: [e.g. arm-none-eabi-gcc +version]
+ - stm32-cmake: [v2.0 or 86d1dd2 or ...]
+
+**Additional context**
+Add any other context about the problem here.

+ 20 - 0
.github/ISSUE_TEMPLATE/feature_request.md

@@ -0,0 +1,20 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.

+ 1 - 1
.github/workflows/cmake.yml

@@ -1,6 +1,6 @@
 name: Tests
 
-on: [push]
+on: [push, pull_request]
 
 env:
   # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)

+ 26 - 20
README.md

@@ -30,12 +30,14 @@ It uses cmake and GCC, along with newlib (libc), STM32Cube. Supports F0 F1 F2 F3
 * `fetch-cube` ([examples/fetch-cube](examples/fetch-cube)) - example of using FetchContent for fetching STM32Cube from ST's git.
 * `fetch-cmsis-hal` ([examples/fetch-cmsis-hal](examples/fetch-cmsis-hal)) - example of using FetchContent for fetching STM32 CMSIS and HAL from ST's git.
 * `blinky` ([examples/blinky](examples/blinky)) - blink led using STM32 HAL library and SysTick.
+It will compile a project for the `F4` family by default, but you can also compile for the
+`L0` and `F1` family by passing `L0_EXAMPLE=ON` or `F1_EXAMPLE=ON` to the CMake generation call.
 * `freertos` ([examples/freertos](examples/freertos)) - blink led using STM32 HAL library and FreeRTOS.
 
 # Usage
 
-First of all you need to configure toolchain and library pathes using CMake varibles. 
-You can do this by passing values through command line during cmake run or by setting variables inside your CMakeLists.txt
+First of all you need to configure toolchain and library paths using CMake variables. 
+You can do this by passing values through command line during cmake run or by setting variables inside your `CMakeLists.txt`
 
 ## Configuration
 
@@ -45,18 +47,18 @@ You can do this by passing values through command line during cmake run or by se
 
 ## Common usage
 
-First thing that you need to do after toolchain configration in your `CMakeLists.txt` script is to find CMSIS package:
-```
+First thing that you need to do after toolchain configuration in your `CMakeLists.txt` script is to find CMSIS package:
+```cmake
 find_package(CMSIS [CMSIS_version] COMPONENTS STM32F4 REQUIRED)
 ```
 You can specify STM32 family or even specific device (`STM32F407VG`) in `COMPONENTS` or omit `COMPONENTS` totally - in that case stm32-cmake will find ALL sources for ALL families and ALL chips (you'll need ALL STM32Cube packages somewhere).
 
-[CMSIS_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiples STM32 families are requested.
+[CMSIS_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiple STM32 families are requested.
 
 Each STM32 device can be categorized into family and device type groups, for example STM32F407VG is device from `F4` family, with type `F407xx`.
 
-***Note**: Some devices in STM32H7 family has two different cores (Cortex-M7 and Cortex-M4).
-For those device the name used must include the core name e.g STM32H7_M7 and STM32H7_M4.
+***Note**: Some devices in STM32H7 family have two different cores (Cortex-M7 and Cortex-M4).
+For those devices the name used must include the core name e.g STM32H7_M7 and STM32H7_M4.
 
 CMSIS consists of three main components:
 
@@ -65,22 +67,22 @@ CMSIS consists of three main components:
 * Device-specific linker scripts which requires information about memory sizes
 
 stm32-cmake uses modern CMake features notably imported targets and target properties.
-Every CMSIS component is CMake's target (aka library), which defines compiler definitions, compiler flags, include dirs, sources, etc. to build and propagates them as dependencies. So in simple use-case all you need is to link your executable with library `CMSIS::STM32::<device>`:
-```
+Every CMSIS component is CMake's target (aka library), which defines compiler definitions, compiler flags, include dirs, sources, etc. to build and propagate them as dependencies. So in a simple use-case all you need is to link your executable with library `CMSIS::STM32::<device>`:
+```cmake
 add_executable(stm32-template main.c)
 target_link_libraries(stm32-template CMSIS::STM32::F407VG)
 ```
 That will add include directories, startup source, linker script and compiler flags to your executable.
 
-CMSIS creates following targets:
+CMSIS creates the following targets:
 
 * `CMSIS::STM32::<FAMILY>` (e.g. `CMSIS::STM32::F4`) - common includes, compiler flags and defines for family
 * `CMSIS::STM32::<TYPE>` (e.g. `CMSIS::STM32::F407xx`) - common startup source for device type, depends on `CMSIS::STM32::<FAMILY>`
 * `CMSIS::STM32::<DEVICE>` (e.g. `CMSIS::STM32::F407VG`) - linker script for device, depends on `CMSIS::STM32::<TYPE>`
 
-So, if you don't need linker script, you can link only `CMSIS::STM32::<TYPE>` library and provide own script using `stm32_add_linker_script` function
+So, if you don't need linker script, you can link only `CMSIS::STM32::<TYPE>` library and provide your own script using `stm32_add_linker_script` function
 
-***Note**: For H7 family, because of it multi-cores architecture, all H7 targets also have a suffix (::M7 or ::M4).
+***Note**: For H7 family, because of it's multi-core architecture, all H7 targets also have a suffix (::M7 or ::M4).
 For example, targets created for STM32H747BI will look like `CMSIS::STM32::H7::M7`, `CMSIS::STM32::H7::M4`, `CMSIS::STM32::H747BI::M7`, `CMSIS::STM32::H747BI::M4`, etc.*
 
 The GCC C/C++ standard libraries are added by linking the library `STM32::NoSys`. This will add the `--specs=nosys.specs` to compiler and linker flags.
@@ -90,15 +92,15 @@ Keep in mind that when using `STM32::Nano`, by default you cannot use floats in
 ## HAL
 
 STM32 HAL can be used similar to CMSIS.
-```
+```cmake
 find_package(HAL [HAL_version] COMPONENTS STM32F4 REQUIRED)
 set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
 ```
 *`CMAKE_INCLUDE_CURRENT_DIR` here because HAL requires `stm32<family>xx_hal_conf.h` file being in include headers path.*
 
-[HAL_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiples STM32 families are requested.
+[HAL_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiple STM32 families are requested.
 
-HAL module will search all drivers supported by family and create following targets:
+HAL module will search all drivers supported by family and create the following targets:
 
 * `HAL::STM32::<FAMILY>` (e.g. `HAL::STM32::F4`) - common HAL source, depends on `CMSIS::STM32::<FAMILY>`
 * `HAL::STM32::<FAMILY>::<DRIVER>` (e.g. `HAL::STM32::F4::GPIO`) - HAL driver <DRIVER>, depends on `HAL::STM32::<FAMILY>`
@@ -109,7 +111,7 @@ HAL module will search all drivers supported by family and create following targ
 
 Here is typical usage:
 
-```
+```cmake
 add_executable(stm32-blinky-f4 blinky.c stm32f4xx_hal_conf.h)
 target_link_libraries(stm32-blinky-f4 
     HAL::STM32::F4::RCC
@@ -131,27 +133,31 @@ target_link_libraries(stm32-blinky-f4
 
 CMSIS package will generate linker script for your device automatically (target `CMSIS::STM32::<DEVICE>`). To specify a custom linker script, use `stm32_add_linker_script` function.
 
-## Useful cmake function
+## Useful CMake functions
 
 * `stm32_get_chip_info(<chip> [FAMILY <family>] [TYPE <type>] [DEVICE <device>])` - classify device using name, will return device family (into `<family>` variable), type (`<type>`) and canonical name (`<device>`, uppercase without any package codes)
 * `stm32_get_memory_info((CHIP <chip>)|(DEVICE <device> TYPE <type>) [FLASH|RAM|CCRAM|STACK|HEAP] [SIZE <size>] [ORIGIN <origin>])` - get information about device memories (into `<size>` and `<origin>`). Linker script generator uses values from this function
 * `stm32_get_devices_by_family(DEVICES [FAMILY <family>])` - return into `DEVICES` all supported devices by family (or all devices if `<family>` is empty)
+* `stm32_print_size_of_target(<target>)` - Print the application sizes for all formats
+* `stm32_generate_binary_file(<target>)` - Generate the binary file for the given target
+* `stm32_generate_hex_file(<target>)` - Generate the hex file for the given target
 
 # Additional CMake modules
 
-stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in embedded world.
+stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in the embedded world.
 
 ## FreeRTOS
 
 [cmake/FindFreeRTOS](cmake/FindFreeRTOS) - finds FreeRTOS sources in location specified by `FREERTOS_PATH` (*default*: `/opt/FreeRTOS`) variable and format them as `IMPORTED` targets. `FREERTOS_PATH` can be either the path to the whole [FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS) github repo, or the path to FreeRTOS-Kernel (usually located in the subfolder `FreeRTOS` on a downloaded release)
+
 Typical usage:
 
-```
+```cmake
 find_package(FreeRTOS COMPONENTS ARM_CM4F REQUIRED)
 target_link_libraries(... FreeRTOS::ARM_CM4F)
 ```
 
-Following FreeRTOS ports supported: `ARM_CM0`, `ARM_CM3`, `ARM_CM4F`, `ARM_CM7`.
+The following FreeRTOS ports are supported: `ARM_CM0`, `ARM_CM3`, `ARM_CM4F`, `ARM_CM7`.
 
 Other FreeRTOS libraries:
 

+ 3 - 3
cmake/FindBSP.cmake

@@ -326,13 +326,13 @@ foreach(COMP ${BSP_FIND_COMPONENTS})
         target_link_libraries(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE BSP::STM32::${FAMILY}${CORE_C} CMSIS::STM32::${FAMILY}${CORE_C})
         target_include_directories(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE "${BSP_${FAMILY}_PATH}/Components/${BCOMP}")
         
-        find_file(BSP_${BOARD_CANONICAL}_${COMP}_SOURCE
+        find_file(BSP_${BOARD_CANONICAL}_${BCOMP}_SOURCE
             NAMES ${BCOMP}.c
             PATHS "${BSP_${FAMILY}_PATH}/Components/${BCOMP}"
             NO_DEFAULT_PATH
         )
-        if (BSP_${BOARD_CANONICAL}_${COMP}_SOURCE)
-            target_sources(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE "${BSP_${BOARD_CANONICAL}_${COMP}_SOURCE}")
+        if (BSP_${BOARD_CANONICAL}_${BCOMP}_SOURCE)
+            target_sources(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE "${BSP_${BOARD_CANONICAL}_${BCOMP}_SOURCE}")
         endif()
     endforeach()
     

+ 16 - 2
cmake/FindFreeRTOS.cmake

@@ -19,9 +19,14 @@ endif()
 find_path(FreeRTOS_COMMON_INCLUDE
     NAMES FreeRTOS.h
     PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS" 
-    PATH_SUFFIXES  "Source/include"
+    PATH_SUFFIXES  "Source/include" "include"
     NO_DEFAULT_PATH
 )
+
+if(NOT FreeRTOS_COMMON_INCLUDE)
+    message(WARNING "FreeRTOS common include path not found, build might fail")
+endif()
+
 list(APPEND FreeRTOS_INCLUDE_DIRS "${FreeRTOS_COMMON_INCLUDE}")
 
 find_path(FreeRTOS_SOURCE_DIR
@@ -76,9 +81,18 @@ foreach(PORT ${FreeRTOS_FIND_COMPONENTS})
     find_path(FreeRTOS_${PORT}_PATH
         NAMES portmacro.h
         PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS" 
-        PATH_SUFFIXES "Source/portable/GCC/${PORT}"  "Source/portable/GCC/${PORT}/r0p1"
+        PATH_SUFFIXES
+            "portable/GCC/${PORT}/r0p1"
+            "portable/GCC/${PORT}"
+            "Source/portable/GCC/${PORT}"
+            "Source/portable/GCC/${PORT}/r0p1"
         NO_DEFAULT_PATH
     )
+
+    if(NOT FreeRTOS_${PORT}_PATH)
+        message(WARNING "FreeRTOS port path not found, build might fail")
+    endif()
+
     list(APPEND FreeRTOS_INCLUDE_DIRS "${FreeRTOS_${PORT}_PATH}")
     
     find_file(FreeRTOS_${PORT}_SOURCE

+ 53 - 5
cmake/stm32/common.cmake

@@ -11,10 +11,16 @@ endforeach()
 list(REMOVE_DUPLICATES STM32_SUPPORTED_FAMILIES_SHORT_NAME)
 
 if(NOT STM32_TOOLCHAIN_PATH)
-     set(STM32_TOOLCHAIN_PATH "/usr")
-     message(STATUS "No STM32_TOOLCHAIN_PATH specified, using default: " ${STM32_TOOLCHAIN_PATH})
-else()
-     file(TO_CMAKE_PATH "${STM32_TOOLCHAIN_PATH}" STM32_TOOLCHAIN_PATH)
+    if(NOT CMAKE_C_COMPILER)
+        set(STM32_TOOLCHAIN_PATH "/usr")
+        message(STATUS "No STM32_TOOLCHAIN_PATH specified, using default: " ${STM32_TOOLCHAIN_PATH})
+    else()
+        # keep only directory of compiler
+        get_filename_component(STM32_TOOLCHAIN_PATH ${CMAKE_C_COMPILER} DIRECTORY)
+        # remove the last /bin directory
+        get_filename_component(STM32_TOOLCHAIN_PATH ${STM32_TOOLCHAIN_PATH} DIRECTORY)
+    endif()
+    file(TO_CMAKE_PATH "${STM32_TOOLCHAIN_PATH}" STM32_TOOLCHAIN_PATH)
 endif()
 
 if(NOT STM32_TARGET_TRIPLET)
@@ -36,6 +42,34 @@ find_program(CMAKE_SIZE NAMES ${STM32_TARGET_TRIPLET}-size PATHS ${TOOLCHAIN_BIN
 find_program(CMAKE_DEBUGGER NAMES ${STM32_TARGET_TRIPLET}-gdb PATHS ${TOOLCHAIN_BIN_PATH} NO_DEFAULT_PATH)
 find_program(CMAKE_CPPFILT NAMES ${STM32_TARGET_TRIPLET}-c++filt PATHS ${TOOLCHAIN_BIN_PATH} NO_DEFAULT_PATH)
 
+function(stm32_print_size_of_target TARGET)
+    add_custom_target(${TARGET}_always_display_size
+        ALL COMMAND ${CMAKE_SIZE} ${TARGET}${CMAKE_EXECUTABLE_SUFFIX_C}
+        COMMENT "Target Sizes: "
+        DEPENDS ${TARGET}
+    )
+endfunction()
+
+function(stm32_generate_binary_file TARGET)
+    add_custom_command(
+        TARGET ${TARGET}
+        POST_BUILD
+        COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}${CMAKE_EXECUTABLE_SUFFIX_C} ${TARGET}.bin
+        BYPRODUCTS ${TARGET}.bin
+        COMMENT "Generating binary file ${CMAKE_PROJECT_NAME}.bin"
+    )
+endfunction()
+
+function(stm32_generate_hex_file TARGET)
+    add_custom_command(
+        TARGET ${TARGET}
+        POST_BUILD
+        COMMAND ${CMAKE_OBJCOPY} -O ihex ${TARGET}${CMAKE_EXECUTABLE_SUFFIX_C} ${TARGET}.hex
+        BYPRODUCTS ${TARGET}.hex
+        COMMENT "Generating hex file ${CMAKE_PROJECT_NAME}.hex"
+    )
+endfunction()
+
 function(stm32_get_chip_type FAMILY DEVICE TYPE)
     set(INDEX 0)
     foreach(C_TYPE ${STM32_${FAMILY}_TYPES})
@@ -222,6 +256,21 @@ endfunction()
 function(stm32_add_linker_script TARGET VISIBILITY SCRIPT)
     get_filename_component(SCRIPT "${SCRIPT}" ABSOLUTE)
     target_link_options(${TARGET} ${VISIBILITY} -T "${SCRIPT}")
+
+    get_target_property(TARGET_TYPE ${TARGET} TYPE)
+    if(TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
+        set(INTERFACE_PREFIX "INTERFACE_")
+    endif()
+
+    get_target_property(LINK_DEPENDS ${TARGET} ${INTERFACE_PREFIX}LINK_DEPENDS)
+    if(LINK_DEPENDS)
+        list(APPEND LINK_DEPENDS "${SCRIPT}")        
+    else()
+        set(LINK_DEPENDS "${SCRIPT}")
+    endif()
+
+
+    set_target_properties(${TARGET} PROPERTIES ${INTERFACE_PREFIX}LINK_DEPENDS "${LINK_DEPENDS}")
 endfunction()
 
 if(NOT (TARGET STM32::NoSys))
@@ -259,4 +308,3 @@ include(stm32/l1)
 include(stm32/l4)
 include(stm32/l5)
 
-

+ 3 - 0
examples/blinky-ll/CMakeLists.txt

@@ -15,6 +15,7 @@ target_link_libraries(stm32-blinky-f4
     CMSIS::STM32::F407VG
     STM32::NoSys 
 )
+stm32_print_size_of_target(stm32-blinky-f4)
 
 # STM32VL-Discovery
 add_executable(stm32-blinky-f1 blinky.c)
@@ -24,6 +25,7 @@ target_link_libraries(stm32-blinky-f1
     CMSIS::STM32::F100RB
     STM32::NoSys
 )
+stm32_print_size_of_target(stm32-blinky-f1)
 
 # STM32L0538-Discovery
 add_executable(stm32-blinky-l0 blinky.c)
@@ -33,3 +35,4 @@ target_link_libraries(stm32-blinky-l0
     CMSIS::STM32::L053C8
     STM32::NoSys
 )
+stm32_print_size_of_target(stm32-blinky-l0)

+ 60 - 27
examples/blinky/CMakeLists.txt

@@ -4,9 +4,33 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/stm32_gcc.cmake
 project(stm32-blinky C ASM)
 set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
 
-find_package(CMSIS COMPONENTS STM32L0 STM32F1 STM32F4 REQUIRED)
-find_package(HAL COMPONENTS STM32L0 STM32F1 STM32F4 RCC GPIO CORTEX REQUIRED)
-# Find all drivers:
+# Configure here which STM32 target(s) to build
+option(BLINKY_F4_EXAMPLE "Compile F4 example" ON)
+option(BLINKY_F1_EXAMPLE "Compile F1 example" OFF)
+option(BLINKY_L0_EXAMPLE "Compile L0 example" OFF)
+
+set(HAL_COMP_LIST RCC GPIO CORTEX)
+set(CMSIS_COMP_LIST "")
+
+if(BLINKY_F4_EXAMPLE)
+    list(APPEND CMSIS_COMP_LIST STM32F4)
+    list(APPEND HAL_COMP_LIST STM32F4)
+endif()
+
+if(BLINKY_F1_EXAMPLE)
+    list(APPEND CMSIS_COMP_LIST STM32F1)
+    list(APPEND HAL_COMP_LIST STM32F1)
+endif()
+
+if(BLINKY_L0_EXAMPLE)
+    list(APPEND CMSIS_COMP_LIST STM32L0)
+    list(APPEND HAL_COMP_LIST STM32L0)
+endif()
+
+find_package(CMSIS COMPONENTS "${CMSIS_COMP_LIST}" REQUIRED)
+find_package(HAL COMPONENTS "${HAL_COMP_LIST}" REQUIRED)
+
+# Find all device specific drivers:
 #find_package(HAL COMPONENTS STM32L0 STM32F1 STM32F4 REQUIRED)
 # Find drivers for all families:
 #find_package(HAL COMPONENTS RCC GPIO CORTEX REQUIRED)
@@ -16,31 +40,40 @@ find_package(HAL COMPONENTS STM32L0 STM32F1 STM32F4 RCC GPIO CORTEX REQUIRED)
 #find_package(HAL REQUIRED)
 
 # STM32F4-Discovery
-add_executable(stm32-blinky-f4 blinky.c stm32f4xx_hal_conf.h)
-target_link_libraries(stm32-blinky-f4 
-    HAL::STM32::F4::RCC
-    HAL::STM32::F4::GPIO
-    HAL::STM32::F4::CORTEX
-    CMSIS::STM32::F407VG
-    STM32::NoSys 
-)
+if(BLINKY_F4_EXAMPLE)
+    add_executable(stm32-blinky-f4 blinky.c stm32f4xx_hal_conf.h)
+    target_link_libraries(stm32-blinky-f4
+        HAL::STM32::F4::RCC
+        HAL::STM32::F4::GPIO
+        HAL::STM32::F4::CORTEX
+        CMSIS::STM32::F407VG
+        STM32::NoSys
+    )
+    stm32_print_size_of_target(stm32-blinky-f4)
+endif()
 
 # STM32VL-Discovery
-add_executable(stm32-blinky-f1 blinky.c stm32f1xx_hal_conf.h)
-target_link_libraries(stm32-blinky-f1 
-    HAL::STM32::F1::RCC
-    HAL::STM32::F1::GPIO
-    HAL::STM32::F1::CORTEX
-    CMSIS::STM32::F100RB
-    STM32::NoSys
-)
+if(BLINKY_F1_EXAMPLE)
+    add_executable(stm32-blinky-f1 blinky.c stm32f1xx_hal_conf.h)
+    target_link_libraries(stm32-blinky-f1
+        HAL::STM32::F1::RCC
+        HAL::STM32::F1::GPIO
+        HAL::STM32::F1::CORTEX
+        CMSIS::STM32::F100RB
+        STM32::NoSys
+    )
+    stm32_print_size_of_target(stm32-blinky-f1)
+endif()
 
 # STM32L0538-Discovery
-add_executable(stm32-blinky-l0 blinky.c stm32l0xx_hal_conf.h)
-target_link_libraries(stm32-blinky-l0
-    HAL::STM32::L0::RCC
-    HAL::STM32::L0::GPIO
-    HAL::STM32::L0::CORTEX
-    CMSIS::STM32::L053C8
-    STM32::NoSys
-)
+if(BLINKY_L0_EXAMPLE)
+    add_executable(stm32-blinky-l0 blinky.c stm32l0xx_hal_conf.h)
+    target_link_libraries(stm32-blinky-l0
+        HAL::STM32::L0::RCC
+        HAL::STM32::L0::GPIO
+        HAL::STM32::L0::CORTEX
+        CMSIS::STM32::L053C8
+        STM32::NoSys
+    )
+    stm32_print_size_of_target(stm32-blinky-l0)
+endif()

+ 1 - 0
examples/custom-linker-script/CMakeLists.txt

@@ -12,3 +12,4 @@ set(PROJECT_SOURCES
 add_executable(stm32-custom-linker-script ${PROJECT_SOURCES})
 target_link_libraries(stm32-custom-linker-script CMSIS::STM32::F407xx STM32::NoSys)
 stm32_add_linker_script(stm32-custom-linker-script PRIVATE F407VG.ld)
+stm32_print_size_of_target(stm32-custom-linker-script)

+ 2 - 0
examples/fetch-cmsis-hal/CMakeLists.txt

@@ -15,6 +15,8 @@ set(PROJECT_SOURCES
 
 add_executable(stm32-fetch-f4 ${PROJECT_SOURCES})
 target_link_libraries(stm32-fetch-f4 CMSIS::STM32::F407VG STM32::NoSys)
+stm32_print_size_of_target(stm32-fetch-f4)
 
 add_executable(stm32-fetch-l0 ${PROJECT_SOURCES})
 target_link_libraries(stm32-fetch-l0 CMSIS::STM32::L053C8 STM32::NoSys)
+stm32_print_size_of_target(stm32-fetch-l0)

+ 2 - 0
examples/fetch-cube/CMakeLists.txt

@@ -13,6 +13,8 @@ set(PROJECT_SOURCES
 
 add_executable(stm32-fetch-f4 ${PROJECT_SOURCES})
 target_link_libraries(stm32-fetch-f4 CMSIS::STM32::F407VG STM32::NoSys)
+stm32_print_size_of_target(stm32-fetch-f4)
 
 add_executable(stm32-fetch-l0 ${PROJECT_SOURCES})
 target_link_libraries(stm32-fetch-l0 CMSIS::STM32::L053C8 STM32::NoSys)
+stm32_print_size_of_target(stm32-fetch-l0)

+ 1 - 0
examples/freertos/CMakeLists.txt

@@ -24,3 +24,4 @@ target_link_libraries(stm32-freertos PRIVATE
     CMSIS::STM32::F407VG 
     STM32::NoSys
 )
+stm32_print_size_of_target(stm32-freertos)

+ 2 - 0
examples/multi-core/CMakeLists.txt

@@ -21,6 +21,7 @@ target_link_libraries(m7core PRIVATE
     CMSIS::STM32::H757VG::M7
     STM32::NoSys
     )
+stm32_print_size_of_target(m7core)
 
 target_link_libraries(m4core PRIVATE
     HAL::STM32::H7::M4::RCC
@@ -29,3 +30,4 @@ target_link_libraries(m4core PRIVATE
     CMSIS::STM32::H757VG::M4
     STM32::NoSys
     )
+stm32_print_size_of_target(m4core)

+ 1 - 0
examples/template/CMakeLists.txt

@@ -15,3 +15,4 @@ set(PROJECT_SOURCES
 
 add_executable(stm32-template ${PROJECT_SOURCES})
 target_link_libraries(stm32-template CMSIS::STM32::F407VG STM32::NoSys)
+stm32_print_size_of_target(stm32-template)