Add support for Black magic probe (using GDB client).

Add documentation about that in README.md
This commit is contained in:
JF 2020-01-17 14:56:56 +01:00
parent 6abf12ffb7
commit 81d629e86a
3 changed files with 161 additions and 36 deletions

View file

@ -11,9 +11,40 @@ if (NOT NRF5_SDK_PATH)
message(FATAL_ERROR "The path to the NRF52 SDK must be specified on the command line (add -DNRF5_SDK_PATH=<path>")
endif ()
if (NOT NRFJPROG)
message(FATAL_ERROR "the path to the tool nrfjprog must be specified on the command line (add -DNRFJPROG=<path>")
endif ()
if(NOT USE_JLINK AND NOT USE_GDB_CLIENT)
set(USE_JLINK true)
endif()
if(USE_JLINK)
if (NOT NRFJPROG)
message(FATAL_ERROR "the path to the tool nrfjprog must be specified on the command line (add -DNRFJPROG=<path>")
endif ()
endif()
if(USE_GDB_CLIENT)
if(NOT GDB_CLIENT_BIN_PATH)
set(GDB_CLIENT_BIN_PATH "arm-none-eabi-gdb")
endif()
if(NOT GDB_CLIENT_TARGET_REMOTE)
message(FATAL_ERROR "The GDB target must be specified (add -DGDB_CLIENT_TARGET_REMOTE=<target>")
endif()
endif()
message("BUILD CONFIGURATION")
message("-------------------")
message(" * Toolchain : " ${ARM_NONE_EABI_TOOLCHAIN_PATH})
message(" * NRF52 SDK : " ${NRF5_SDK_PATH})
set(PROGRAMMER "???")
if(USE_JLINK)
message(" * Programmer/debugger : JLINK")
message(" * NrfJprog : " ${NRFJPROG})
elseif(USE_GDB_CLIENT)
message(" * Programmer/debugger : GDB Client")
message(" * GDB Client path : " ${GDB_CLIENT_BIN_PATH})
message(" * GDB Target : " ${GDB_CLIENT_TARGET_REMOTE})
endif()
include("cmake-nRF5x/CMake_nRF5x.cmake")
add_subdirectory(src)

View file

@ -42,23 +42,72 @@ See [this page](./doc/PinetimeStubWithNrf52DK.md)
* Download and unzip arm-none-eabi and NRF52 SDK
* Clone this repo
* Call CMake with the following command line argument
* **[JLINK]** Call CMake with the following command line argument
- -DARM_NONE_EABI_TOOLCHAIN_PATH=[Path to the toolchain]
- -DNRF5_SDK_PATH=[Path to the SDK]
- -DNRFJPROG=[Path to NRFJProg]
- -DARM_NONE_EABI_TOOLCHAIN_PATH=[Path to the toolchain directory]
- -DNRF5_SDK_PATH=[Path to the SDK directory]
- -DUSE_JLINK=1
- -DNRFJPROG=[Path to NRFJProg executable]
* OR
* **[GDB CLIENT (if you use a BlackMagicProbe, for example)]** Call CMake with the following command line argument
- -DARM_NONE_EABI_TOOLCHAIN_PATH=[Path to the toolchain directory]
- -DNRF5_SDK_PATH=[Path to the SDK directory]
- -DUSE_GDB_CLIENT=1
- -DGDB_CLIENT_BIN_PATH=[Path to arm-none-eabi-gdb executable]
- -DGDB_CLIENT_TARGET_REMOTE=[Target remote connetion string. Ex : /dev/ttyACM0]
* Optionally, you can define MERGEHEX with the path to the ```mergehex``` tool from [NRF5X Command Line Tools](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf5x_cltools%2FUG%2Fcltools%2Fnrf5x_command_line_tools_lpage.html&cp=6_1) to be able to merge the application and softdevice into one HEX file. In this case the merged file is generated in src/pinetime-app-full.hex
- -DMERGEHEX=[Path to the mergehex executable]
JLINK
```
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DNRFJPROG=... ../
$ cmake -DCMAKE_BUILD_TYPE=Debug -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_JLINK=1 -DNRFJPROG=... ../
```
GDB (Back Magic Probe)
```
$ mkdir build
$ cd build
$ cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_GDB_CLIENT=1 -DGDB_CLIENT_BIN_PATH=... -DGDB_CLIENT_TARGET_REMOTE=... -DMERGEHEX=... ../
```
* Make
```
$ make -j
$ make -j pinetime-app
```
## How to program
* Erase
```
$ make FLASH_ERASE
```
* Flash softdevice & application
```
$ make FLASH_SOFTDEVICE
$ make FLASH_pinetime-app
```
Or, with ```mergehex```
```
$ make FLASH_MERGED_pinetime-app
```
* For your information : list make targets
```
$ make help
```
## RTT
RTT is a feature from Segger's JLink devices that allows bidirectionnal communication between the debugger and the target.

View file

@ -5,9 +5,9 @@ if (NOT NRF5_SDK_PATH)
message(FATAL_ERROR "The path to the nRF5 SDK (NRF5_SDK_PATH) must be set.")
endif ()
if (NOT NRFJPROG)
message(FATAL_ERROR "The path to the nrfjprog utility (NRFJPROG) must be set.")
endif ()
#if (NOT NRFJPROG)
# message(FATAL_ERROR "The path to the nrfjprog utility (NRFJPROG) must be set.")
#endif ()
# convert toolchain path to bin path
if(DEFINED ARM_NONE_EABI_TOOLCHAIN_PATH)
@ -323,17 +323,28 @@ macro(nRF5x_setup)
)
# adds target for erasing and flashing the board with a softdevice
add_custom_target(FLASH_SOFTDEVICE ALL
COMMAND ${NRFJPROG} --program ${SOFTDEVICE_PATH} -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing SoftDevice"
)
if(USE_JLINK)
add_custom_target(FLASH_SOFTDEVICE ALL
COMMAND ${NRFJPROG} --program ${SOFTDEVICE_PATH} -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing SoftDevice"
)
add_custom_target(FLASH_ERASE ALL
COMMAND ${NRFJPROG} --eraseall -f ${NRF_TARGET}
COMMENT "erasing flashing"
)
add_custom_target(FLASH_ERASE ALL
COMMAND ${NRFJPROG} --eraseall -f ${NRF_TARGET}
COMMENT "erasing flashing"
)
elseif(USE_GDB_CLIENT)
add_custom_target(FLASH_SOFTDEVICE ALL
COMMAND ${GDB_CLIENT_BIN_PATH} -nx --batch -ex 'target extended-remote ${GDB_CLIENT_TARGET_REMOTE}' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'kill' ${SOFTDEVICE_PATH}
COMMENT "flashing SoftDevice"
)
add_custom_target(FLASH_ERASE ALL
COMMAND ${GDB_CLIENT_BIN_PATH} -nx --batch -ex 'target extended-remote ${GDB_CLIENT_TARGET_REMOTE}' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'mon erase_mass'
COMMENT "erasing flashing"
)
endif()
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
set(TERMINAL "open")
@ -343,13 +354,15 @@ macro(nRF5x_setup)
set(TERMINAL "gnome-terminal")
endif()
add_custom_target(START_JLINK ALL
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkGDBServer-${NRF_TARGET}"
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkExe-${NRF_TARGET}"
COMMAND sleep 2s
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkRTTClient"
COMMENT "started JLink commands"
)
if(USE_JLINK)
add_custom_target(START_JLINK ALL
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkGDBServer-${NRF_TARGET}"
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkExe-${NRF_TARGET}"
COMMAND sleep 2s
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkRTTClient"
COMMENT "started JLink commands"
)
endif()
endmacro(nRF5x_setup)
@ -368,14 +381,46 @@ macro(nRF5x_addExecutable EXECUTABLE_NAME SOURCE_FILES)
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_NAME}.out "${EXECUTABLE_NAME}.hex"
COMMENT "post build steps for ${EXECUTABLE_NAME}")
if(MERGEHEX)
add_custom_command(TARGET ${EXECUTABLE_NAME}
POST_BUILD
COMMAND ${MERGEHEX} --merge ${EXECUTABLE_NAME}.hex ${NRF5_SDK_PATH}/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex --output ${EXECUTABLE_NAME}-full.hex
COMMENT "merging HEX files")
if(USE_JLINK)
add_custom_target("FLASH_MERGED_${EXECUTABLE_NAME}" ALL
DEPENDS ${EXECUTABLE_NAME}
COMMAND ${NRFJPROG} --program ${EXECUTABLE_NAME}-full.hex -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing ${EXECUTABLE_NAME}-full.hex"
)
elseif(USE_GDB_CLIENT)
add_custom_target("FLASH_MERGED_${EXECUTABLE_NAME}" ALL
DEPENDS ${EXECUTABLE_NAME}
COMMAND ${GDB_CLIENT_BIN_PATH} -nx --batch -ex 'target extended-remote ${GDB_CLIENT_TARGET_REMOTE}' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'kill' ${EXECUTABLE_NAME}-full.hex
COMMENT "flashing ${EXECUTABLE_NAME}-full.hex"
)
endif()
endif()
# custom target for flashing the board
add_custom_target("FLASH_${EXECUTABLE_NAME}" ALL
DEPENDS ${EXECUTABLE_NAME}
COMMAND ${NRFJPROG} --program ${EXECUTABLE_NAME}.hex -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing ${EXECUTABLE_NAME}.hex"
)
if(USE_JLINK)
add_custom_target("FLASH_${EXECUTABLE_NAME}" ALL
DEPENDS ${EXECUTABLE_NAME}
COMMAND ${NRFJPROG} --program ${EXECUTABLE_NAME}.hex -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing ${EXECUTABLE_NAME}.hex"
)
elseif(USE_GDB_CLIENT)
add_custom_target("FLASH_${EXECUTABLE_NAME}" ALL
DEPENDS ${EXECUTABLE_NAME}
COMMAND ${GDB_CLIENT_BIN_PATH} -nx --batch -ex 'target extended-remote ${GDB_CLIENT_TARGET_REMOTE}' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'kill' ${EXECUTABLE_NAME}.hex
COMMENT "flashing ${EXECUTABLE_NAME}.hex"
)
endif()
endmacro()