From 1cae95654a1673ffb269ebd3bce1ece73ef776f5 Mon Sep 17 00:00:00 2001 From: derGraph Date: Mon, 22 May 2023 08:34:19 +0200 Subject: [PATCH 1/5] Updated Makefile defs to 10.3.1 --- firmware/Makefile.defs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/Makefile.defs b/firmware/Makefile.defs index bd75da3d..a3e00c1f 100644 --- a/firmware/Makefile.defs +++ b/firmware/Makefile.defs @@ -1,6 +1,6 @@ # In the nrf52 sdk, will auto detection current platform: posix or windows. # If your is already installed, and version and path is this: -# Version : 9.3.1 +# Version : 10.3.1 # Windows-path: C:/Program Files (x86)/GNU Arm Embedded Toolchain/9 2020-q2-update/bin/ # POSIX -path: /usr/local/gcc-arm-none-eabi-9-2020-q2-update/bin/ # You can ignore this file modify. From 0633da153aa5d873012bf09c1e4c7cdea5f9870f Mon Sep 17 00:00:00 2001 From: derGraph Date: Mon, 22 May 2023 09:14:08 +0200 Subject: [PATCH 2/5] Update to gcc version 10.3.1 --- How_to_use_Firmware.md | 7 +++++-- firmware/Makefile.defs | 4 ++-- firmware/nrf52_sdk/components/toolchain/gcc/Makefile.posix | 2 +- .../nrf52_sdk/components/toolchain/gcc/Makefile.windows | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/How_to_use_Firmware.md b/How_to_use_Firmware.md index 97d3af05..05077d49 100644 --- a/How_to_use_Firmware.md +++ b/How_to_use_Firmware.md @@ -3,7 +3,7 @@ In this file you can look up how to [edit](#Editing-the-code), [compile](#Compil ## Editing the code We are using [Visual Studio Code](https://code.visualstudio.com/download) to edit this project! Simply download and install it! - - Install the [ARM-GCC](https://mynewt.apache.org/latest/get_started/native_install/cross_tools.html) version [9.3.1 Compiler](https://developer.arm.com/downloads/-/gnu-rm) and remember the path where you installed it. + - Install the [ARM-GCC](https://mynewt.apache.org/latest/get_started/native_install/cross_tools.html) version [10.3.1 Compiler Tested](https://developer.arm.com/downloads/-/gnu-rm) and remember the path where you installed it. - Install the [C++ Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) in VS-Code. - Create a new IntelliSense Configuration: - press F1 in VS-Code and enter `C/C++: Edit Configurations (UI)` @@ -35,6 +35,9 @@ We are using [Visual Studio Code](https://code.visualstudio.com/download) to edi - go into folder and run `make` ## Debugging the code -- Install [openocd](https://mynewt.apache.org/latest/get_started/native_install/cross_tools.html) +- Install [nRF Util](https://www.nordicsemi.com/Products/Development-tools/nrf-util) + - Move it to a known path like `C:/nrfutil/` + - Add this path to `PATH` Environment Variable - Install [Cortex-Debug](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug) VS-Code Extension +- Install [Segger J-Link](https://www.segger.com/downloads/jlink) - MORE INFO ADDED LATER \ No newline at end of file diff --git a/firmware/Makefile.defs b/firmware/Makefile.defs index a3e00c1f..ae280879 100644 --- a/firmware/Makefile.defs +++ b/firmware/Makefile.defs @@ -1,8 +1,8 @@ # In the nrf52 sdk, will auto detection current platform: posix or windows. # If your is already installed, and version and path is this: # Version : 10.3.1 -# Windows-path: C:/Program Files (x86)/GNU Arm Embedded Toolchain/9 2020-q2-update/bin/ -# POSIX -path: /usr/local/gcc-arm-none-eabi-9-2020-q2-update/bin/ +# Windows-path: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin +# POSIX -path: /usr/local/gcc-arm-none-eabi-10.3-2021.10/bin/ # You can ignore this file modify. # Warning: your toolchain path not allow PR to public repo!!! # If you need define the toolchain path, plz delete annotate and change it. diff --git a/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.posix b/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.posix index 6a935fc7..04bbd932 100644 --- a/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.posix +++ b/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.posix @@ -1,3 +1,3 @@ -GNU_INSTALL_ROOT ?= /usr/local/gcc-arm-none-eabi-9-2020-q2-update/bin/ +GNU_INSTALL_ROOT ?= /usr/local/gcc-arm-none-eabi-10.3-2021.10/bin/ GNU_VERSION ?= 9.3.1 GNU_PREFIX ?= arm-none-eabi diff --git a/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.windows b/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.windows index 54dbc804..cda3cdac 100644 --- a/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.windows +++ b/firmware/nrf52_sdk/components/toolchain/gcc/Makefile.windows @@ -1,3 +1,3 @@ -GNU_INSTALL_ROOT ?= C:/Program Files (x86)/GNU Arm Embedded Toolchain/9 2020-q2-update/bin/ -GNU_VERSION ?= 9.3.1 +GNU_INSTALL_ROOT ?= C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/ +GNU_VERSION ?= 10.3.1 GNU_PREFIX ?= arm-none-eabi \ No newline at end of file From c2f78e2a36b183c6986b47cdb6fefb3f961e1edc Mon Sep 17 00:00:00 2001 From: derGraph Date: Sat, 10 Jun 2023 20:37:13 +0200 Subject: [PATCH 3/5] Adding STLink Support Adding STLink Support: make flash_stlink uploads program over openocd. --- firmware/application/Makefile | 15 +++++++++++++++ firmware/bootloader/Makefile | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/firmware/application/Makefile b/firmware/application/Makefile index 62821629..1520a388 100644 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -381,8 +381,23 @@ flash_softdevice: nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_7.2.0_softdevice.hex --sectorerase nrfjprog -f nrf52 --reset +# Flash with ST-Link + OpenOCD +flash_stlink: + @echo Generating settings... + nrfutil settings generate --family NRF52840 --application $(OUTPUT_DIRECTORY)/application.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 $(OUTPUT_DIRECTORY)/settings.hex + @echo Merging required files + mergehex --merge $(OUTPUT_DIRECTORY)/bootloader.hex $(OUTPUT_DIRECTORY)/settings.hex --output $(OUTPUT_DIRECTORY)/bootloader_settings.hex + mergehex --merge $(OUTPUT_DIRECTORY)/bootloader_settings.hex $(OUTPUT_DIRECTORY)/application.hex $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_7.2.0_softdevice.hex --output $(OUTPUT_DIRECTORY)/project.hex + @echo Flashing... + openocd -f interface/stlink.cfg -f target/nrf52.cfg -c "program $(OUTPUT_DIRECTORY)/project.hex verify reset ; shutdown" + erase: nrfjprog -f nrf52 --eraseall + +# Erase with ST-Link +erase_stlink: + openocd -f interface/stlink.cfg -f target/nrf52.cfg -c "flash init; init; reset halt; flash erase_sector 0 1 last; exit" + @echo Successfully deleted everything! SDK_CONFIG_FILE := ./${PROJ_DIR}/sdk_config.h CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar diff --git a/firmware/bootloader/Makefile b/firmware/bootloader/Makefile index 4a4fa503..e8f31cb3 100644 --- a/firmware/bootloader/Makefile +++ b/firmware/bootloader/Makefile @@ -267,8 +267,23 @@ flash_softdevice: nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_7.2.0_softdevice.hex --sectorerase nrfjprog -f nrf52 --reset +# Flash with ST-Link + OpenOCD +flash_stlink: + @echo Generating settings... + nrfutil settings generate --family NRF52840 --application $(OUTPUT_DIRECTORY)/application.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 $(OUTPUT_DIRECTORY)/settings.hex + @echo Merging required files + mergehex --merge $(OUTPUT_DIRECTORY)/bootloader.hex $(OUTPUT_DIRECTORY)/settings.hex --output $(OUTPUT_DIRECTORY)/bootloader_settings.hex + mergehex --merge $(OUTPUT_DIRECTORY)/bootloader_settings.hex $(OUTPUT_DIRECTORY)/application.hex $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_7.2.0_softdevice.hex --output $(OUTPUT_DIRECTORY)/project.hex + @echo Flashing... + openocd -f interface/stlink.cfg -f target/nrf52.cfg -c "program $(OUTPUT_DIRECTORY)/project.hex verify reset ; shutdown" + erase: nrfjprog -f nrf52 --eraseall + +# Erase with ST-Link +erase_stlink: + openocd -f interface/stlink.cfg -f target/nrf52.cfg -c "flash init; init; reset halt; flash erase_sector 0 1 last; exit" + @echo Successfully deleted everything! # Config project SDK_CONFIG_FILE := $(PROJ_DIR)/sdk_config.h From bcc61b8b3351c5a7eab596f926de57839c4ea79a Mon Sep 17 00:00:00 2001 From: derGraph Date: Sat, 10 Jun 2023 20:38:00 +0200 Subject: [PATCH 4/5] Instructions tested/fixed; Uploading added --- How_to_use_Firmware.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/How_to_use_Firmware.md b/How_to_use_Firmware.md index 05077d49..a4ab000f 100644 --- a/How_to_use_Firmware.md +++ b/How_to_use_Firmware.md @@ -5,6 +5,7 @@ In this file you can look up how to [edit](#Editing-the-code), [compile](#Compil We are using [Visual Studio Code](https://code.visualstudio.com/download) to edit this project! Simply download and install it! - Install the [ARM-GCC](https://mynewt.apache.org/latest/get_started/native_install/cross_tools.html) version [10.3.1 Compiler Tested](https://developer.arm.com/downloads/-/gnu-rm) and remember the path where you installed it. - Install the [C++ Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) in VS-Code. + - Install the [C++ Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack) in VS-Code. - Create a new IntelliSense Configuration: - press F1 in VS-Code and enter `C/C++: Edit Configurations (UI)` - Add a new Configuration and name it @@ -16,6 +17,7 @@ We are using [Visual Studio Code](https://code.visualstudio.com/download) to edi - Edit Makefile.defs: - Change `GNU_INSTALL_ROOT`(path of previously installed Compiler `bin` folder) - Change `GNU_VERSION` (Version of the installed Compiler) + - Change the other paths to match your system - Don't forget to remove the `#` in front of the changed lines - Install make - **Ubuntu:** @@ -33,11 +35,38 @@ We are using [Visual Studio Code](https://code.visualstudio.com/download) to edi - Install Homebrew package manager by running the following command: `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` - Once Homebrew is installed, run the following command to install Make: `brew install make` - go into folder and run `make` + - if make fails try to add a folder named `objects` in the `firmware` folder +- do this for `application` and `bootloader` folder -## Debugging the code +## Merging the code - Install [nRF Util](https://www.nordicsemi.com/Products/Development-tools/nrf-util) - Move it to a known path like `C:/nrfutil/` - Add this path to `PATH` Environment Variable +- Install [nRF Command Line Tools](https://www.nordicsemi.com/Products/Development-tools/nRF-Command-Line-Tools) +- Install nRF Util packages: + - `nrfutil install completion device nrf5sdk-tools trace` +- go into `objects` folder +- generate settings by `nrfutil settings generate --family NRF52840 --application application.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 settings.hex` (only has to be done once) +- merge bootloader and settings by `mergehex --merge bootloader.hex settings.hex --output bootloader_settings.hex` +- copy the `s140_nrf52_7.2.0_softdevice.hex` file from `nrf52_sdk/components/softdevice/s140/hex/` to `objects` +- rename `s140_nrf52_7.2.0_softdevice.hex` to `softdevice.hex` +- merge bootloader_settings and app by `mergehex --merge bootloader_settings.hex application.hex softdevice.hex --output project.hex` + +## Uploading the code +- If you are using J-Link: + - Install [Segger J-Link](https://www.segger.com/downloads/jlink) + - [Merge](#Merging-the-code) the code + - Upload softdevice with `make flash_softdevice` + - Upload bootloader in bootloader folder with `make flash` + - Upload application in application folder with `make flash` +- If you are using ST-Link: + - Install [openocd](https://mynewt.apache.org/latest/get_started/native_install/cross_tools.html) + - Install [ST-Link drivers](https://www.st.com/en/development-tools/stsw-link009.html) + - Extract downloaded zip + - run `dpinst_amd64.exe` + - Upload full image with `make flash_stlink` in application or bootloader folder + + +## Debugging the code - Install [Cortex-Debug](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug) VS-Code Extension -- Install [Segger J-Link](https://www.segger.com/downloads/jlink) - MORE INFO ADDED LATER \ No newline at end of file From ab4f366e49940c95895a8aaf9cb1077d8f6a6742 Mon Sep 17 00:00:00 2001 From: derGraph Date: Sat, 10 Jun 2023 22:54:28 +0200 Subject: [PATCH 5/5] Added debugging instruction Please someone test JLink --- How_to_use_Firmware.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/How_to_use_Firmware.md b/How_to_use_Firmware.md index a4ab000f..2da303a1 100644 --- a/How_to_use_Firmware.md +++ b/How_to_use_Firmware.md @@ -69,4 +69,42 @@ We are using [Visual Studio Code](https://code.visualstudio.com/download) to edi ## Debugging the code - Install [Cortex-Debug](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug) VS-Code Extension -- MORE INFO ADDED LATER \ No newline at end of file +- Open `app_main.c` +- Open the extension with `CTRL-SHIFT-D` +- Klick on `create a launch.json file` +- Select `Cortex-Debug` +- Add this in the configuration bracket: + ``` + { + "cwd": "${workspaceFolder}", + "executable": "${workspaceRoot}/firmware/objects/bootloader.out", + "name": "Debug with JLink", + "request": "launch", + "type": "cortex-debug", + "runToEntryPoint": "main", + "showDevDebugOutput": "none", + "servertype": "jlink", + "device": "nrf52", + "interface": "swd", + "svdFile": "${workspaceRoot}/firmware/nrf52_sdk/modules/nrfx/mdk/nrf52.svd", + "gdbPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gdb.exe" + }, + { + "cwd": "${workspaceFolder}", + "executable": "${workspaceRoot}/firmware/objects/bootloader.out", + "name": "Debug with STLink", + "request": "launch", + "type": "cortex-debug", + "runToEntryPoint": "main", + "showDevDebugOutput": "none", + "servertype": "openocd", + "device": "nrf52", + "svdFile": "${workspaceRoot}/firmware/nrf52_sdk/modules/nrfx/mdk/nrf52.svd", + "gdbPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gdb.exe", + "configFiles": [ + "interface/stlink.cfg", + "target/nrf52.cfg" + ] + } + ``` +- In the debug menu you can select `Debug with JLink` or `Debug with STLink` \ No newline at end of file