Browse Source

[BUILD] Add support for svd generation with cmake

Used for IDE-based debugging
master
Alberto García Hierro 4 years ago
parent
commit
93723d0ad0
  1. 2
      CMakeLists.txt
  2. 1
      cmake/main.cmake
  3. 3
      cmake/stm32.cmake
  4. 2
      cmake/stm32f3.cmake
  5. 6
      cmake/stm32f4.cmake
  6. 16
      cmake/svd.cmake

2
CMakeLists.txt

@ -41,6 +41,7 @@ set(MAIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(MAIN_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set(MAIN_UTILS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/utils")
set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/main")
set(SVD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dev/svd")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@ -48,6 +49,7 @@ set(FIRMWARE_VERSION ${PROJECT_VERSION})
include(settings)
include(openocd)
include(svd)
include(main)
include(stm32)

1
cmake/main.cmake

@ -54,6 +54,7 @@ function(setup_firmware_target name)
get_property(targets GLOBAL PROPERTY VALID_TARGETS)
set_property(GLOBAL PROPERTY VALID_TARGETS "${targets} ${name}")
setup_openocd(${name})
setup_svd(${name})
endfunction()
function(exclude_from_all target)

3
cmake/stm32.cmake

@ -158,7 +158,7 @@ function(target_stm32 name startup ldscript)
cmake_parse_arguments(
PARSED_ARGS
"DISABLE_MSC" # Boolean arguments
"HSE_MHZ;OPENOCD_TARGET" # Single value arguments
"HSE_MHZ;OPENOCD_TARGET;SVD" # Single value arguments
"DEFINITIONS" # Multi-value arguments
${ARGN} # Start parsing after the known arguments
)
@ -213,6 +213,7 @@ function(target_stm32 name startup ldscript)
endif()
set_property(TARGET ${name} PROPERTY OPENOCD_TARGET ${PARSED_ARGS_OPENOCD_TARGET})
set_property(TARGET ${name} PROPERTY OPENOCD_DEFAULT_INTERFACE stlink)
set_property(TARGET ${name} PROPERTY SVD ${PARSED_ARGS_SVD})
# Generate .hex
# XXX: Generator expressions are not supported for add_custom_command()
# OUTPUT nor BYPRODUCTS, so we can't rely of them. Instead, build the filename

2
cmake/stm32f3.cmake

@ -80,7 +80,7 @@ function(target_stm32f3xx name startup ldscript)
endfunction()
function(target_stm32f303 name)
target_stm32f3xx(${name} startup_stm32f30x_md_gcc.S stm32_flash_f303_256k.ld ${ARGN})
target_stm32f3xx(${name} startup_stm32f30x_md_gcc.S stm32_flash_f303_256k.ld SVD STM32F303 ${ARGN})
target_compile_definitions(${name} PRIVATE ${STM32F303_DEFINITIONS})
setup_firmware_target(${name})
endfunction()

6
cmake/stm32f4.cmake

@ -104,7 +104,7 @@ set(STM32F405_COMPILE_DEFINITIONS
)
function(target_stm32f405 name)
target_stm32f4xx(${name} startup_stm32f40xx.s stm32_flash_f405.ld ${ARGN})
target_stm32f4xx(${name} startup_stm32f40xx.s stm32_flash_f405.ld SVD STM32F405 ${ARGN})
target_sources(${name} PRIVATE ${STM32F4_STDPERIPH_SRC})
target_compile_definitions(${name} PRIVATE ${STM32F405_COMPILE_DEFINITIONS})
setup_firmware_target(${name})
@ -120,7 +120,7 @@ set(STM32F411_COMPILE_DEFINITIONS
)
function(target_stm32f411 name)
target_stm32f4xx(${name} startup_stm32f411xe.s stm32_flash_f411.ld)
target_stm32f4xx(${name} startup_stm32f411xe.s stm32_flash_f411.ld SVD STM32F411 ${ARGN})
target_sources(${name} PRIVATE ${STM32F411_OR_F427_STDPERIPH_SRC})
target_compile_definitions(${name} PRIVATE ${STM32F411_COMPILE_DEFINITIONS})
setup_firmware_target(${name})
@ -131,7 +131,7 @@ set(STM32F427_COMPILE_DEFINITIONS
FLASH_SIZE=1024
)
function(target_stm32f427 name)
target_stm32f4xx(${name} startup_stm32f427xx.s stm32_flash_f427.ld ${ARGN})
target_stm32f4xx(${name} startup_stm32f427xx.s stm32_flash_f427.ld SVD STM32F427 ${ARGN})
target_sources(${name} PRIVATE ${STM32F411_OR_F427_STDPERIPH_SRC})
target_compile_definitions(${name} PRIVATE ${STM32F427_COMPILE_DEFINITIONS})
setup_firmware_target(${name})

16
cmake/svd.cmake

@ -0,0 +1,16 @@
function(setup_svd target_name)
get_property(svd_name TARGET ${target_name} PROPERTY SVD)
set(svd_target_name "svd_${target_name}")
if (svd_name AND NOT svd_name STREQUAL "")
add_custom_target(${svd_target_name}
COMMAND ${CMAKE_COMMAND} -E copy
${SVD_DIR}/${svd_name}.svd
${CMAKE_BINARY_DIR}/svd/${target_name}.svd
)
else()
add_custom_target(${svd_target_name}
cmake -E echo "target ${target_name} does not declare an SVD filename"
COMMAND cmake -E false)
endif()
exclude_from_all(${svd_target_name})
endfunction()
Loading…
Cancel
Save