|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 | 4 | # ----------------------------------------------
|
5 |
| -# Load the upload method that the user selects |
| 5 | +# Common upload method options |
6 | 6 |
|
7 | 7 | # This variable should have been set in app.cmake or by the upload method cfg file, sanity check here
|
8 | 8 | if(NOT DEFINED UPLOAD_METHOD_DEFAULT)
|
9 | 9 | message(FATAL_ERROR "UPLOAD_METHOD_DEFAULT not found.")
|
10 | 10 | endif()
|
11 | 11 |
|
| 12 | +## Upload method |
12 | 13 | set(UPLOAD_METHOD "${UPLOAD_METHOD_DEFAULT}" CACHE STRING "Method for uploading programs to the mbed")
|
13 | 14 |
|
14 |
| -# use a higher numbered port to allow use without root on Linux/Mac |
15 |
| -set(GDB_PORT 23331 CACHE STRING "Port that the GDB server will be started on.") |
16 |
| - |
17 |
| -# Upload methods must be uppercase, guard against the user making a mistake (since Windows will allow opening |
18 |
| -# an include file with the wrong case, the error message gets confusing) |
| 15 | +# Upload methods must be uppercase, guard against the user making a mistake (since Windows and Mac will allow including |
| 16 | +# an include file with the wrong case, the error that happens later gets confusing) |
19 | 17 | string(TOUPPER "${UPLOAD_METHOD}" UPLOAD_METHOD_UCASE)
|
20 | 18 | if(NOT "${UPLOAD_METHOD_UCASE}" STREQUAL "${UPLOAD_METHOD}")
|
21 | 19 | message(WARNING "UPLOAD_METHOD value should be uppercase. It has been automatically changed to \"${UPLOAD_METHOD_UCASE}\".")
|
22 | 20 | set(UPLOAD_METHOD "${UPLOAD_METHOD_UCASE}" CACHE STRING "" FORCE)
|
23 | 21 | endif()
|
24 | 22 |
|
25 |
| -# Load the upload method. This is expected to set the following variables: |
26 |
| -# UPLOAD_${UPLOAD_METHOD}_FOUND - True iff the dependencies for this upload method were found |
27 |
| -# UPLOAD_SUPPORTS_DEBUG - True iff this upload method supports debugging |
28 |
| -# UPLOAD_GDBSERVER_DEBUG_COMMAND - Command to start a new GDB server |
29 |
| -# UPLOAD_WANTS_EXTENDED_REMOTE - True iff GDB should use "target extended-remote" to connect to the GDB server |
30 |
| -# UPLOAD_LAUNCH_COMMANDS - List of GDB commands to run after launching GDB. |
31 |
| -# UPLOAD_RESTART_COMMANDS - List of GDB commands to run when the "restart chip" function is used. |
| 23 | +## GDB port |
| 24 | +# use a higher numbered port to allow use without root on Linux/Mac |
| 25 | +set(MBED_GDB_PORT 23331 CACHE STRING "Port that the GDB server will be started on.") |
| 26 | + |
| 27 | +## Upload tool serial number |
| 28 | +set(MBED_UPLOAD_SERIAL_NUMBER "" CACHE STRING "Serial number of the Mbed board or the programming tool, for upload methods that select by serial number.") |
| 29 | + |
| 30 | +# Handle legacy per-upload-method aliases for the upload serial number |
| 31 | +foreach(LEGACY_VAR_NAME JLINK_USB_SERIAL_NUMBER LINKSERVER_PROBE_SN MBED_TARGET_UID OPENOCD_ADAPTER_SERIAL PYOCD_PROBE_UID STLINK_SERIAL_ARGUMENT STM32CUBE_PROBE_SN) |
| 32 | + if(DEFINED ${LEGACY_VAR_NAME}) |
| 33 | + if(NOT "${${LEGACY_VAR_NAME}}" STREQUAL "") |
| 34 | + message(WARNING "${LEGACY_VAR_NAME} is deprecated, set the MBED_UPLOAD_SERIAL_NUMBER variable instead. MBED_UPLOAD_SERIAL_NUMBER will be set to the value of ${LEGACY_VAR_NAME}.") |
| 35 | + set(MBED_UPLOAD_SERIAL_NUMBER ${${LEGACY_VAR_NAME}} CACHE STRING "" FORCE) |
| 36 | + endif() |
| 37 | + endif() |
| 38 | +endforeach() |
| 39 | + |
| 40 | +## Upload base address |
| 41 | +if(NOT DEFINED MBED_UPLOAD_BASE_ADDR OR "${MBED_UPLOAD_BASE_ADDR}" STREQUAL "") |
| 42 | + set(BASE_ADDR_DESCRIPTION "Base address for uploading code, i.e. the memory address where the first byte of the bin/hex file will get loaded to (with 0x prefix). Generally should point to the start of the desired flash bank and defaults to the configured start of the primary ROM bank (MBED_CONFIGURED_ROM_START).") |
| 43 | + if(MBED_CONFIG_DEFINITIONS MATCHES "MBED_CONFIGURED_ROM_START=(0x[0-9a-zA-Z]+)") |
| 44 | + set(MBED_UPLOAD_BASE_ADDR ${CMAKE_MATCH_1} CACHE STRING ${BASE_ADDR_DESCRIPTION}) |
| 45 | + else() |
| 46 | + if(NOT ${UPLOAD_METHOD} STREQUAL "NONE") |
| 47 | + message(FATAL_ERROR "Since no ROM banks have been defined, you need to set the MBED_UPLOAD_BASE_ADDR option so we know where to upload code. NOTE: If you upgraded from an old version of Mbed CE and are getting this error, delete and reconfigure your CMake build directory.") |
| 48 | + endif() |
| 49 | + endif() |
| 50 | +endif() |
| 51 | + |
| 52 | +# ---------------------------------------------- |
| 53 | +# Load the upload method. |
| 54 | +# Upload methods are expected to refer to the following variables: |
| 55 | +# - MBED_UPLOAD_SERIAL_NUMBER - USB serial number of the mbed board or of the programmer |
| 56 | +# - MBED_UPLOAD_BASE_ADDR - Base address of the flash where the bin file will be updated |
| 57 | +# |
| 58 | +# Upload methods are expected to set the following variables: |
| 59 | +# - UPLOAD_${UPLOAD_METHOD}_FOUND - True iff the dependencies for this upload method were found |
| 60 | +# - UPLOAD_SUPPORTS_DEBUG - True iff this upload method supports debugging |
| 61 | +# - UPLOAD_GDBSERVER_DEBUG_COMMAND - Command to start a new GDB server |
| 62 | +# - UPLOAD_WANTS_EXTENDED_REMOTE - True iff GDB should use "target extended-remote" to connect to the GDB server |
| 63 | +# - UPLOAD_LAUNCH_COMMANDS - List of GDB commands to run after launching GDB. |
| 64 | +# - UPLOAD_RESTART_COMMANDS - List of GDB commands to run when the "restart chip" function is used. |
32 | 65 | # See here for more info: https://github.com/mbed-ce/mbed-os/wiki/Debugger-Commands-and-State-in-Upload-Methods
|
| 66 | +# |
| 67 | +# WARNING: Upload method files are included during the add_subdirectory(mbed-os) call in the top-level CMakeLists.txt. This means that |
| 68 | +# if you declare variables in an upload method script, you have to save them as CACHE INTERNAL (or PARENT_SCOPE) so that they are accessible |
| 69 | +# to code running outside of the mbed-os subdirectory. |
33 | 70 | include(UploadMethod${UPLOAD_METHOD})
|
34 | 71 |
|
35 | 72 | if(NOT "${UPLOAD_${UPLOAD_METHOD}_FOUND}")
|
|
0 commit comments