improve flash target

This commit is contained in:
hathach 2023-05-19 16:27:07 +07:00
parent 270136e84a
commit 49d8d27770
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
5 changed files with 219 additions and 216 deletions

View File

@ -227,14 +227,19 @@ endif
# Jlink Interface # Jlink Interface
JLINK_IF ?= swd JLINK_IF ?= swd
# Jlink script
define jlink_script
halt
loadfile $^
r
go
exit
endef
export jlink_script
# Flash using jlink # Flash using jlink
flash-jlink: $(BUILD)/$(PROJECT).hex flash-jlink: $(BUILD)/$(PROJECT).hex
@echo halt > $(BUILD)/$(BOARD).jlink @echo "$$jlink_script" > $(BUILD)/$(BOARD).jlink
@echo r >> $(BUILD)/$(BOARD).jlink
@echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
@echo r >> $(BUILD)/$(BOARD).jlink
@echo go >> $(BUILD)/$(BOARD).jlink
@echo exit >> $(BUILD)/$(BOARD).jlink
$(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink
# Flash STM32 MCU using stlink with STM32 Cube Programmer CLI # Flash STM32 MCU using stlink with STM32 Cube Programmer CLI

View File

@ -1,22 +1,25 @@
if (NOT TARGET _family_support_marker) if (TARGET _family_support_marker)
add_library(_family_support_marker INTERFACE) return()
endif ()
include(CMakePrintHelpers) add_library(_family_support_marker INTERFACE)
# Default to gcc include(CMakePrintHelpers)
if(NOT DEFINED TOOLCHAIN)
# Default to gcc
if(NOT DEFINED TOOLCHAIN)
set(TOOLCHAIN gcc) set(TOOLCHAIN gcc)
endif() endif()
if (NOT FAMILY) if (NOT FAMILY)
message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line") message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line")
endif() endif()
if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)
message(FATAL_ERROR "Family '${FAMILY}' is not known/supported") message(FATAL_ERROR "Family '${FAMILY}' is not known/supported")
endif() endif()
function(family_filter RESULT DIR) function(family_filter RESULT DIR)
get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if (EXISTS "${DIR}/only.txt") if (EXISTS "${DIR}/only.txt")
@ -64,29 +67,29 @@ if (NOT TARGET _family_support_marker)
endif() endif()
endfunction() endfunction()
function(family_add_subdirectory DIR) function(family_add_subdirectory DIR)
family_filter(SHOULD_ADD "${DIR}") family_filter(SHOULD_ADD "${DIR}")
if (SHOULD_ADD) if (SHOULD_ADD)
add_subdirectory(${DIR}) add_subdirectory(${DIR})
endif() endif()
endfunction() endfunction()
function(family_get_project_name OUTPUT_NAME DIR) function(family_get_project_name OUTPUT_NAME DIR)
get_filename_component(SHORT_NAME ${DIR} NAME) get_filename_component(SHORT_NAME ${DIR} NAME)
set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE)
endfunction() endfunction()
function(family_initialize_project PROJECT DIR) function(family_initialize_project PROJECT DIR)
family_filter(ALLOWED "${DIR}") family_filter(ALLOWED "${DIR}")
if (NOT ALLOWED) if (NOT ALLOWED)
get_filename_component(SHORT_NAME ${DIR} NAME) get_filename_component(SHORT_NAME ${DIR} NAME)
message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}")
endif() endif()
endfunction() endfunction()
function(family_add_default_example_warnings TARGET) function(family_add_default_example_warnings TARGET)
target_compile_options(${TARGET} PUBLIC target_compile_options(${TARGET} PUBLIC
-Wall -Wall
-Wextra -Wextra
@ -111,6 +114,10 @@ if (NOT TARGET _family_support_marker)
) )
if (CMAKE_C_COMPILER_ID STREQUAL "GNU") if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
endif()
# GCC 10 # GCC 10
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
target_compile_options(${TARGET} PUBLIC -Wconversion) target_compile_options(${TARGET} PUBLIC -Wconversion)
@ -126,24 +133,73 @@ if (NOT TARGET _family_support_marker)
target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing) target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing)
endif() endif()
endif() endif()
endfunction() endfunction()
# configure an executable target to link to tinyusb in device mode, and add the board implementation # Add flash jlink target
function(family_configure_device_example TARGET) function(family_flash_jlink TARGET)
if (NOT DEFINED JLINKEXE)
set(JLINKEXE JLinkExe)
endif ()
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}>
r
go
exit"
)
add_custom_target(${TARGET}-jlink
DEPENDS ${TARGET}
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
)
endfunction()
# Add flash pycod target
function(family_flash_pyocd TARGET)
if (NOT DEFINED PYOC)
set(PYOCD pyocd)
endif ()
add_custom_target(${TARGET}-pyocd
DEPENDS ${TARGET}
COMMAND ${PYOCD} flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
)
endfunction()
# Add flash using NXP's LinkServer (redserver)
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
function(family_flash_nxplink TARGET)
if (NOT DEFINED LINKSERVER)
set(LINKSERVER LinkServer)
endif ()
# LinkServer has a bug that can only execute with full path otherwise it throws:
# realpath error: No such file or directory
execute_process(COMMAND which ${LINKSERVER} OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(${TARGET}-nxplink
DEPENDS ${TARGET}
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
)
endfunction()
# configure an executable target to link to tinyusb in device mode, and add the board implementation
function(family_configure_device_example TARGET)
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
endfunction() endfunction()
# configure an executable target to link to tinyusb in host mode, and add the board implementation # configure an executable target to link to tinyusb in host mode, and add the board implementation
function(family_configure_host_example TARGET) function(family_configure_host_example TARGET)
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
endfunction() endfunction()
include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)
if (NOT FAMILY_MCUS) if (NOT FAMILY_MCUS)
set(FAMILY_MCUS ${FAMILY}) set(FAMILY_MCUS ${FAMILY})
endif()
# save it in case of re-inclusion
set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "")
endif() endif()
# save it in case of re-inclusion
set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "")

View File

@ -132,37 +132,9 @@ function(family_configure_target TARGET)
) )
#---------- Flash ---------- #---------- Flash ----------
# Flash using pyocd family_flash_jlink(${TARGET})
add_custom_target(${TARGET}-pyocd family_flash_nxplink(${TARGET})
DEPENDS ${TARGET} family_flash_pyocd(${TARGET})
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
)
# Flash using NXP LinkServer (redlink)
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
# LinkServer has a bug that can only execute with full path otherwise it throws:
# realpath error: No such file or directory
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(${TARGET}-nxplink
DEPENDS ${TARGET}
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
)
# Flash using jlink
set(JLINKEXE JLinkExe)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}>
r
go
exit"
)
add_custom_target(${TARGET}-jlink
DEPENDS ${TARGET}
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
)
endfunction() endfunction()

View File

@ -128,20 +128,9 @@ function(family_configure_target TARGET)
) )
#---------- Flash ---------- #---------- Flash ----------
# Flash using pyocd family_flash_jlink(${TARGET})
add_custom_target(${TARGET}-pyocd family_flash_nxplink(${TARGET})
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}> family_flash_pyocd(${TARGET})
)
# Flash using NXP LinkServer (redlink)
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
# LinkServer has a bug that can only execute with full path otherwise it throws:
# realpath error: No such file or directory
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(${TARGET}-nxplink
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
)
endfunction() endfunction()

View File

@ -132,26 +132,7 @@ function(family_configure_target TARGET)
) )
#---------- Flash ---------- #---------- Flash ----------
# Flash using pyocd family_flash_jlink(${TARGET})
add_custom_target(${TARGET}-pyocd
DEPENDS ${TARGET}
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
)
# Flash using jlink
set(JLINKEXE JLinkExe)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}>
r
go
exit"
)
add_custom_target(${TARGET}-jlink
DEPENDS ${TARGET}
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
)
endfunction() endfunction()