From 37d50ed62bd3ff396ac37a23a923a6fcf0f25cad Mon Sep 17 00:00:00 2001 From: lucas Date: Sun, 26 Jan 2020 01:38:06 +0100 Subject: [PATCH 1/3] added some inital support for flashing via openocd instead of gdb, for wider compatability --- CMakeLists.txt | 8 +++++--- cmake-nRF5x/CMake_nRF5x.cmake | 6 ++++++ pinetime.cfg | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 pinetime.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index 063decbe..6e2ddeac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,9 @@ 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=") endif () -if(NOT USE_JLINK AND NOT USE_GDB_CLIENT) - set(USE_JLINK true) -endif() +#if(NOT USE_JLINK AND NOT USE_GDB_CLIENT) +# set(USE_JLINK true) +#endif() if(USE_JLINK) if (NOT NRFJPROG) @@ -44,6 +44,8 @@ elseif(USE_GDB_CLIENT) message(" * Programmer/debugger : GDB Client") message(" * GDB Client path : " ${GDB_CLIENT_BIN_PATH}) message(" * GDB Target : " ${GDB_CLIENT_TARGET_REMOTE}) +elseif(USE_OPENOCD_CLIENT) + message(" * Programmer/debugger : OpenOCD Client") endif() set(VERSION_EDIT_WARNING "// Do not edit this file, it is automatically generated by CMAKE!") diff --git a/cmake-nRF5x/CMake_nRF5x.cmake b/cmake-nRF5x/CMake_nRF5x.cmake index 0ecc60a3..4d0cb5da 100755 --- a/cmake-nRF5x/CMake_nRF5x.cmake +++ b/cmake-nRF5x/CMake_nRF5x.cmake @@ -401,6 +401,12 @@ macro(nRF5x_addExecutable EXECUTABLE_NAME SOURCE_FILES) 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" ) + elseif(USE_OPENOCD_CLIENT) + add_custom_target("FLASH_MERGED_${EXECUTABLE_NAME}" + DEPENDS ${EXECUTABLE_NAME} + COMMAND /usr/bin/openocd -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -f /home/luben/code/Pinetime/pinetime.cfg -c "program \"${EXECUTABLE_NAME}-full.hex\"" -c reset -c shutdown + COMMENT "flashing ${EXECUTABLE_NAME}-full.hex" + ) endif() endif() diff --git a/pinetime.cfg b/pinetime.cfg new file mode 100644 index 00000000..23b5ffce --- /dev/null +++ b/pinetime.cfg @@ -0,0 +1,7 @@ + +source [find interface/stlink.cfg] + +transport select hla_swd +#set WORKAREASIZE 0 + +source [find target/nrf52.cfg] From 61284527048c0a9caeea81ff0da92d2c1adedfd7 Mon Sep 17 00:00:00 2001 From: lucas Date: Sun, 26 Jan 2020 16:40:45 +0100 Subject: [PATCH 2/3] cleaned up openocd cmake options and added a readme --- CMakeLists.txt | 8 +++++++- README.md | 27 +++++++++++++++++++++++---- cmake-nRF5x/CMake_nRF5x.cmake | 20 +++++++++++++++++--- pinetime.cfg | 7 ------- 4 files changed, 47 insertions(+), 15 deletions(-) delete mode 100644 pinetime.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e2ddeac..9bf80a53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,12 @@ if(USE_GDB_CLIENT) endif() endif() +if(USE_OPENOCD) + if(NOT OPENOCD_BIN_PATH) + set(OPENOCD_BIN_PATH "openocd") + endif() +endif() + message("BUILD CONFIGURATION") message("-------------------") message(" * Version : " ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) @@ -44,7 +50,7 @@ elseif(USE_GDB_CLIENT) message(" * Programmer/debugger : GDB Client") message(" * GDB Client path : " ${GDB_CLIENT_BIN_PATH}) message(" * GDB Target : " ${GDB_CLIENT_TARGET_REMOTE}) -elseif(USE_OPENOCD_CLIENT) +elseif(USE_OPENOCD) message(" * Programmer/debugger : OpenOCD Client") endif() diff --git a/README.md b/README.md index d45f7ab9..dc0ef39d 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,10 @@ See [this page](./doc/PinetimeStubWithNrf52DK.md) * Clone this repo * **[JLINK]** 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_JLINK=1 - - -DNRFJPROG=[Path to NRFJProg executable] + - -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 @@ -58,6 +58,18 @@ See [this page](./doc/PinetimeStubWithNrf52DK.md) - -DGDB_CLIENT_BIN_PATH=[Path to arm-none-eabi-gdb executable] - -DGDB_CLIENT_TARGET_REMOTE=[Target remote connetion string. Ex : /dev/ttyACM0] + * OR + * **[OPENOCD (if you use a STlink v2 clone, 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_OPENOCD=1 + + * Optionally, if you want to use a another version then whats on your path + + - -DOPENOCD_BIN_PATH=[path to openocd] + + * 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] @@ -74,6 +86,13 @@ 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=... ../ +``` + +OpenOCD (STlink v2 clones) +``` +$ mkdir build +$ cd build +$ cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DUSE_OPENOCD=1 -DGDB_CLIENT_BIN_PATH=[optional] -DMERGEHEX=... ../ ``` * Make diff --git a/cmake-nRF5x/CMake_nRF5x.cmake b/cmake-nRF5x/CMake_nRF5x.cmake index 4d0cb5da..8a43cf12 100755 --- a/cmake-nRF5x/CMake_nRF5x.cmake +++ b/cmake-nRF5x/CMake_nRF5x.cmake @@ -344,6 +344,15 @@ macro(nRF5x_setup) 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" ) + elseif(USE_OPENOCD) + add_custom_target(FLASH_SOFTDEVICE + COMMAND ${OPENOCD_BIN_PATH} -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c "program \"${SOFTDEVICE_PATH}\"" -c reset -c shutdown + COMMENT "flashing SoftDevice" + ) + add_custom_target(FLASH_ERASE + COMMAND ${OPENOCD_BIN_PATH} -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c init -c halt -c 'nrf5 mass_erase' -c reset -c shutdown + COMMENT "erasing flashing" + ) endif() if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") @@ -401,10 +410,10 @@ macro(nRF5x_addExecutable EXECUTABLE_NAME SOURCE_FILES) 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" ) - elseif(USE_OPENOCD_CLIENT) + elseif(USE_OPENOCD) add_custom_target("FLASH_MERGED_${EXECUTABLE_NAME}" DEPENDS ${EXECUTABLE_NAME} - COMMAND /usr/bin/openocd -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -f /home/luben/code/Pinetime/pinetime.cfg -c "program \"${EXECUTABLE_NAME}-full.hex\"" -c reset -c shutdown + COMMAND ${OPENOCD_BIN_PATH} -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c "program \"${EXECUTABLE_NAME}-full.hex\"" -c reset -c shutdown COMMENT "flashing ${EXECUTABLE_NAME}-full.hex" ) endif() @@ -425,7 +434,12 @@ macro(nRF5x_addExecutable EXECUTABLE_NAME SOURCE_FILES) 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" ) - + elseif(USE_OPENOCD) + add_custom_target("FLASH_${EXECUTABLE_NAME}" + DEPENDS ${EXECUTABLE_NAME} + COMMAND ${OPENOCD_BIN_PATH} -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c "program \"${EXECUTABLE_NAME}.hex\"" -c reset -c shutdown + COMMENT "flashing ${EXECUTABLE_NAME}.hex" + ) endif() endmacro() diff --git a/pinetime.cfg b/pinetime.cfg deleted file mode 100644 index 23b5ffce..00000000 --- a/pinetime.cfg +++ /dev/null @@ -1,7 +0,0 @@ - -source [find interface/stlink.cfg] - -transport select hla_swd -#set WORKAREASIZE 0 - -source [find target/nrf52.cfg] From a956ed1e61533854d460385336ace6f37c277a87 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 26 Jan 2020 19:29:50 +0100 Subject: [PATCH 3/3] Default to JLink programmer/debugger is no USE_* variable has been specified during CMake build. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79b3dbe9..837bf11e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,9 @@ 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=") endif () -#if(NOT USE_JLINK AND NOT USE_GDB_CLIENT) -# set(USE_JLINK true) -#endif() +if(NOT USE_JLINK AND NOT USE_GDB_CLIENT AND NOT USE_OPENOCD) + set(USE_JLINK true) +endif() if(USE_JLINK) if (NOT NRFJPROG)