Add default upload method configuration for each target, make greentea tests use cmake upload methods

pull/15339/head
Jamie Smith 2022-05-08 13:40:04 -07:00 committed by Jay Sridharan
parent 8e17855e46
commit 3976df728c
12 changed files with 184 additions and 89 deletions

View File

@ -85,9 +85,13 @@ endif()
# Create project and find compilers (if not already found)
project(mbed-os LANGUAGES C CXX ASM)
# Add all paths to the list files within Mbed OS
# Add all paths to the module files within Mbed OS
list(APPEND CMAKE_MODULE_PATH
"${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_Cypress/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NXP/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NUVOTON/scripts/"
${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts
${mbed-os_SOURCE_DIR}/targets/TARGET_Cypress/scripts
${mbed-os_SOURCE_DIR}/targets/TARGET_NXP/scripts
${mbed-os_SOURCE_DIR}/targets/TARGET_NUVOTON/scripts/
${mbed-os_SOURCE_DIR}/tools/cmake/upload_methods
)
add_subdirectory(extern)
@ -209,6 +213,9 @@ if(NOT MBED_IS_NATIVE_BUILD)
string(REPLACE "_" "-" MBED_TARGET_CMAKE_NAME ${MBED_TARGET_CMAKE_NAME})
string(PREPEND MBED_TARGET_CMAKE_NAME "mbed-")
# Load upload method if one is set up
include(UploadMethodManager)
endif()
if(MBED_IS_NATIVE_BUILD)

View File

@ -0,0 +1,47 @@
# Mbed OS upload method configuration file for target NUCLEO_F429ZI.
# To change any of these parameters from their default values, set them in your build script between where you
# include app.cmake and where you add mbed os as a subdirectory.
# Notes:
# 1. Using the JLINK upload method with your dev board requires converting its ST-LINK into a J-Link. See here for details: https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/
# General config parameters
# -------------------------------------------------------------
set(UPLOAD_METHOD_DEFAULT MBED)
# Config options for MBED
# -------------------------------------------------------------
set(MBED_UPLOAD_ENABLED TRUE)
set(MBED_RESET_BAUDRATE 115200)
# Config options for JLINK
# -------------------------------------------------------------
set(JLINK_UPLOAD_ENABLED TRUE)
set(JLINK_CPU_NAME STM32F429ZI)
set(JLINK_CLOCK_SPEED 4000)
set(JLINK_UPLOAD_INTERFACE SWD)
# Config options for PYOCD
# -------------------------------------------------------------
set(PYOCD_UPLOAD_ENABLED TRUE)
set(PYOCD_TARGET_NAME stm32f429xi)
set(PYOCD_CLOCK_SPEED 4000k)
# Config options for OPENOCD
# -------------------------------------------------------------
set(OPENOCD_UPLOAD_ENABLED TRUE)
set(OPENOCD_CHIP_CONFIG_COMMANDS
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/stm32f429-disco.cfg
-c "gdb_memory_map disable" # prevents OpenOCD crash on GDB connect
)
# Config options for STM32Cube
# -------------------------------------------------------------
set(STM32CUBE_UPLOAD_ENABLED TRUE)
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
set(STM32CUBE_GDBSERVER_ARGS --swd)

View File

@ -0,0 +1,48 @@
# Mbed OS upload method configuration file for target NUCLEO_F429ZI.
# To change any of these parameters from their default values, set them in your build script between where you
# include app.cmake and where you add mbed os as a subdirectory.
# Notes:
# 1. Using the JLINK upload method with your dev board requires converting its ST-LINK into a J-Link. See here for details: https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/
# 2. Using pyocd with this device requires installing a pack: `pyocd pack -i STM32L4xx_DFP`
# General config parameters
# -------------------------------------------------------------
set(UPLOAD_METHOD_DEFAULT MBED)
# Config options for MBED
# -------------------------------------------------------------
set(MBED_UPLOAD_ENABLED TRUE)
set(MBED_RESET_BAUDRATE 115200)
# Config options for JLINK
# -------------------------------------------------------------
set(JLINK_UPLOAD_ENABLED TRUE)
set(JLINK_CPU_NAME STM32L452RE)
set(JLINK_CLOCK_SPEED 4000)
set(JLINK_UPLOAD_INTERFACE SWD)
# Config options for PYOCD
# -------------------------------------------------------------
set(PYOCD_UPLOAD_ENABLED TRUE)
set(PYOCD_TARGET_NAME stm32l452retxp) # The nucleo board carries the -P version of the chip with SMPS support
set(PYOCD_CLOCK_SPEED 4000k)
# Config options for OPENOCD
# -------------------------------------------------------------
set(OPENOCD_UPLOAD_ENABLED TRUE)
set(OPENOCD_CHIP_CONFIG_COMMANDS
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/stm32l452re.cfg
-c "gdb_memory_map disable" # prevents OpenOCD crash on GDB connect
)
# Config options for STM32Cube
# -------------------------------------------------------------
set(STM32CUBE_UPLOAD_ENABLED TRUE)
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
set(STM32CUBE_GDBSERVER_ARGS --swd)

View File

@ -0,0 +1,3 @@
## Upload Method Configuration
This folder contains upload method configuration scripts for each Mbed target.
The build system will attempt to load `${MBED_TARGET}.cmake` in this folder when setting up for a given Mbed target.

View File

@ -0,0 +1,17 @@
# OpenOCD config file for the STM32F429ZI
# Originally from: https://gist.github.com/nathantsoi/82021c774f33eb2bfb600da4bf0dfab3
# openocd -f stm32f429-disco.cfg -c "program FILE_NAME.elf verify reset exit"
# for: http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090
interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V2"
# stm32f429 discovery 0483:374b
hla_vid_pid 0x0483 0x374b
transport select hla_swd
source [find target/stm32f4x.cfg]
reset_config srst_only

View File

@ -0,0 +1,14 @@
# OpenOCD config file for the STM32L452RE
interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V2"
# ST-LINK V2.1 0483:374b
hla_vid_pid 0x0483 0x374b
transport select hla_swd
source [find target/stm32l4x.cfg]
reset_config srst_only

View File

@ -1,63 +0,0 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# Edit this file to configure the upload methods for your processor.
# See here for documentation about these options: https://github.com/USCRPL/mbed-cmake/wiki/Upload-Methods
# General config options
# -------------------------------------------------------------
set(UPLOAD_METHOD_DEFAULT MBED)
# use a higher numbered port to allow use without root on Linux/Mac
set(GDB_PORT 23331)
# Config options for MBED
# -------------------------------------------------------------
set(MBED_UPLOAD_ENABLED TRUE)
set(MBED_RESET_BAUDRATE 9600)
# Config options for JLINK
# -------------------------------------------------------------
set(JLINK_UPLOAD_ENABLED FALSE)
if(JLINK_UPLOAD_ENABLED)
set(JLINK_CPU_NAME STM32F429ZI)
set(JLINK_JTAG_SPEED 4000)
endif()
# Config options for PYOCD
# -------------------------------------------------------------
set(PYOCD_UPLOAD_ENABLED TRUE)
if(PYOCD_UPLOAD_ENABLED)
set(PYOCD_TARGET_NAME stm32f429xi)
set(PYOCD_CLOCK_SPEED 4000k)
endif()
# Config options for OPENOCD
# -------------------------------------------------------------
set(OPENOCD_UPLOAD_ENABLED FALSE)
if(OPENOCD_UPLOAD_ENABLED)
set(OPENOCD_CHIP_CONFIG_COMMANDS
-f ${CMAKE_CURRENT_LIST_DIR}/stm32f429-disco.cfg
-c "gdb_memory_map disable" # prevents OpenOCD crash on GDB connect
)
endif()
# Config options for STM32Cube
# -------------------------------------------------------------
set(STM32CUBE_UPLOAD_ENABLED TRUE)
if(STM32CUBE_UPLOAD_ENABLED)
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
set(STM32CUBE_GDBSERVER_ARGS --swd)
endif()

View File

@ -4,13 +4,16 @@
# ----------------------------------------------
# Load the upload method that the user selects
# This variable should have been set in app.cmake or by the upload method cfg file, sanity check here
if(NOT DEFINED UPLOAD_METHOD_DEFAULT)
message(STATUS "Note: UPLOAD_METHOD_DEFAULT not found. Please create an upload method config file if you wish to use CMake's auto uploading and debugging support.")
set(UPLOAD_METHOD_DEFAULT "NONE")
message(FATAL_ERROR "UPLOAD_METHOD_DEFAULT not found.")
endif()
set(UPLOAD_METHOD "${UPLOAD_METHOD_DEFAULT}" CACHE STRING "Method for uploading programs to the mbed")
# use a higher numbered port to allow use without root on Linux/Mac
set(GDB_PORT 23331 CACHE STRING "Port that the GDB server will be started on.")
include(UploadMethod${UPLOAD_METHOD})
if(NOT "${UPLOAD_${UPLOAD_METHOD}_FOUND}")
@ -42,7 +45,7 @@ endif()
function(mbed_generate_upload_debug_targets target)
# add upload target
gen_upload_target(${target} ${CMAKE_BINARY_DIR}/${target}.bin ${CMAKE_BINARY_DIR}/${target}.hex)
gen_upload_target(${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex)
# add debug target
if(UPLOAD_SUPPORTS_DEBUG)

View File

@ -21,7 +21,7 @@ To debug, first run `make gdbserver` in one terminal to start up the debug probe
|STM32Cube|`-DUPLOAD_METHOD=STM32CUBE`|✔️|✔️|Fast|All STMicroelectronics Mbed boards, custom boards with ST_Link probes.
### Common Parameters (for all methods)
### Common Parameter (for all methods)
> UPLOAD_METHOD_DEFAULT
@ -29,6 +29,8 @@ To debug, first run `make gdbserver` in one terminal to start up the debug probe
This sets the default upload method that CMake will use if one is not explicitly set.
### Common Options (for all methods)
> GDB_PORT
**Type:** Integer

View File

@ -64,8 +64,14 @@ else()
endif()
# load mbed_create_distro
include(${CMAKE_CURRENT_LIST_DIR}/create_distro.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/mbed_create_distro.cmake)
# load upload method
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/upload_methods)
include(${CMAKE_CURRENT_LIST_DIR}/UploadMethodManager.cmake)
# load upload method configuration defaults for this target
set(EXPECTED_MBED_UPLOAD_CFG_FILE_PATH targets/upload_method_cfg/${MBED_TARGET}.cmake)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
message(STATUS "Mbed: Loading default upload method configuration from ${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH}")
include(${CMAKE_CURRENT_LIST_DIR}/../../${EXPECTED_MBED_UPLOAD_CFG_FILE_PATH})
else()
message(STATUS "Mbed: Target does not have any upload method configuration. 'make flash-' commands will not be available unless configured by the upper-level project.")
set(UPLOAD_METHOD_DEFAULT "NONE")
endif()

View File

@ -0,0 +1,14 @@
# This file is configured by CMake to create the script used to execute each Greentea test.
# First flash the target using its configured Mbed OS upload method
execute_process(
# Note: we don't use cmake --build because that performs a reconfigure of the build system each time
COMMAND @CMAKE_MAKE_PROGRAM@ flash-@MBED_GREENTEA_TEST_NAME@
WORKING_DIRECTORY @CMAKE_BINARY_DIR@
COMMAND_ERROR_IS_FATAL ANY)
# Then run and communicate with the test
execute_process(
COMMAND mbedhtrun --skip-flashing -f @MBED_GREENTEA_TEST_IMAGE_NAME@ @MBED_HTRUN_ARGUMENTS@
WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@"
COMMAND_ERROR_IS_FATAL ANY)

View File

@ -5,14 +5,6 @@ option(MBED_GREENTEA_TEST_BAREMETAL "Select baremetal greentea tests" OFF)
set(MBED_HTRUN_ARGUMENTS "" CACHE STRING "Argument list to forward to htrun.")
# TODO: After we convert all greentea tests to use CTest, remove this code. We
# define these parameters in mbed-os/CMakeLists.txt for greentea tests.
if(NOT BUILD_GREENTEA_TESTS)
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "")
endif()
# CMake Macro for generalizing CMake configuration across the greentea test suite with configurable parameters
# Macro args:
# TEST_NAME - Test suite name
@ -137,17 +129,22 @@ function(mbed_greentea_add_test)
list(APPEND MBED_HTRUN_ARGUMENTS "--baud-rate=${BAUD_RATE}")
endif()
# Configure the CMake script which runs the test.
# We have to use a helper script in order to run both the flashing and htrun in one test
configure_file(
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/mbed-run-greentea-test.in.cmake
${CMAKE_CURRENT_BINARY_DIR}/mbed-run-greentea-${MBED_GREENTEA_TEST_NAME}.cmake
@ONLY)
# Make sure the cmake script gets removed later
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/mbed-run-greentea-${MBED_GREENTEA_TEST_NAME}.cmake)
add_test(
NAME ${MBED_GREENTEA_TEST_NAME}
COMMAND mbedhtrun
-f ${MBED_GREENTEA_TEST_IMAGE_NAME}
${MBED_HTRUN_ARGUMENTS}
COMMAND_EXPAND_LISTS
COMMAND
${CMAKE_COMMAND} -P mbed-run-greentea-${MBED_GREENTEA_TEST_NAME}.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
endfunction()