Skip to content

Commit 8b7b803

Browse files
committed
Cypress: Improve mbed_post_build_psoc6_merge_hex()
The CMake macro `mbed_post_build_psoc6_merge_hex()` takes the name of a Cypress target and an optional Cortex-M0 hex image as arguments. The proper way to define and parse optional arguments of a function or macro is `cmake_parse_arguments()`, which allows the caller to indicate what they are passing rather than rely on an argument's relative position within `${ARGN}` which is not rigorous. Also, avoid duplicating the common part of the post build command when the optional argument is passed/not passed.
1 parent e0b103d commit 8b7b803

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYSBSYSKIT_01/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ target_compile_definitions(mbed-cysbsyskit-01
5959
"CY8C624AFNI_S2D43F"
6060
)
6161

62-
mbed_post_build_psoc6_merge_hex("CYSBSYSKIT_01")
62+
mbed_post_build_psoc6_merge_hex(
63+
PSOC6_TARGET
64+
"CYSBSYSKIT_01"
65+
)

targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,35 @@ include(mbed_set_post_build)
66
#
77
# Merge Cortex-M4 HEX and a Cortex-M0 HEX.
88
#
9-
macro(mbed_post_build_psoc6_merge_hex cypress_psoc6_target)
10-
if("${cypress_psoc6_target}" STREQUAL "${MBED_TARGET}")
9+
macro(mbed_post_build_psoc6_merge_hex)
10+
set(prefix "CYPRESS")
11+
set(options)
12+
set(oneValueArgs
13+
PSOC6_TARGET
14+
CORTEX_M0_HEX
15+
)
16+
set(multiValueArgs)
17+
cmake_parse_arguments(
18+
"${prefix}"
19+
"${options}"
20+
"${oneValueArgs}"
21+
"${multipleValueArgs}"
22+
${ARGN}
23+
)
24+
25+
if("${CYPRESS_PSOC6_TARGET}" STREQUAL "${MBED_TARGET}")
1126
function(mbed_post_build_function target)
1227
find_package(Python3)
28+
set(post_build_command
29+
${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PSOC6.py
30+
merge
31+
--elf $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.elf
32+
--m4hex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.hex
33+
)
1334

14-
# Copy ${ARGN} to a variable first as it cannot be used directly with
15-
# the list() command
16-
set (extra_macro_args ${ARGN})
17-
18-
# Get the number of arguments past the last expected argument
19-
list(LENGTH extra_macro_args num_extra_args)
20-
21-
if(${num_extra_args} GREATER 0)
22-
# Get extra argument as `cortex_m0_hex`
23-
list(GET extra_macro_args 0 cortex_m0_hex)
24-
set(post_build_command
25-
${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PSOC6.py
26-
merge
27-
--elf $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.elf
28-
--m4hex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.hex
29-
--m0hex ${cortex_m0_hex}
30-
)
31-
else()
32-
set(post_build_command
33-
${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PSOC6.py
34-
merge
35-
--elf $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.elf
36-
--m4hex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.hex
35+
if(NOT "${CYPRESS_CORTEX_M0_HEX}" STREQUAL "")
36+
list(APPEND post_build_command
37+
--m0hex ${CYPRESS_CORTEX_M0_HEX}
3738
)
3839
endif()
3940

0 commit comments

Comments
 (0)