From ad3e0ac7cdee0ab916845188e523f98a0bf571fe Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Mon, 3 Jul 2023 13:22:23 +0800 Subject: [PATCH] Jlink work. --- How_to_use_Firmware.md | 193 ++++++++++++++++++++++++----------------- 1 file changed, 111 insertions(+), 82 deletions(-) diff --git a/How_to_use_Firmware.md b/How_to_use_Firmware.md index 2da303a..33df645 100644 --- a/How_to_use_Firmware.md +++ b/How_to_use_Firmware.md @@ -1,110 +1,139 @@ # How to use the Firmware -In this file you can look up how to [edit](#Editing-the-code), [compile](#Compiling-the-code) and [debug](#Debugging-the-code) the code! + +In this file you can look up how to [edit](#Editing-the-code), [compile](#Compiling-the-code) +and [debug](#Debugging-the-code) the code! ## 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 [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 - - Specify your Compiler path (path of previously installed Compiler `bin` folder) - - Change IntelliSense mode to `gcc-arm (legacy)` - - Add include path `${workspaceFolder}/**` + +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 + - Specify your Compiler path (path of previously installed Compiler `bin` folder) + - Change IntelliSense mode to `gcc-arm (legacy)` + - Add include path `${workspaceFolder}/**` + ## Compiling the code - - Install the compiler (for instructions have a look at [Editing the code](#Editing-the-code)) - - 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 the compiler (for instructions have a look at [Editing the code](#Editing-the-code)) +- 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:** - - Open a terminal. - - Run the following command to install Make: `sudo apt-get install build-essential` - - **Windows using Chocolatey:** - - Install Chocolatey: - - Open a PowerShell terminal with administrator privileges. - - Run the following command to install Chocolatey: - ``` Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) ``` - - Install Make: - - In the same PowerShell terminal, run the following command to install Make using Chocolatey: `choco install make` - - **macOS:** - - Open a terminal. - - 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` + - **Ubuntu:** + - Open a terminal. + - Run the following command to install Make: `sudo apt-get install build-essential` + - **Windows using Chocolatey:** + - Install Chocolatey: + - Open a PowerShell terminal with administrator privileges. + - Run the following command to install Chocolatey: + ``` Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) ``` + - Install Make: + - In the same PowerShell terminal, run the following command to install Make using + Chocolatey: `choco install make` + - **macOS:** + - Open a terminal. + - 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 + - if make fails try to add a folder named `objects` in the `firmware` folder - do this for `application` and `bootloader` folder ## 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 + - 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` + - `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) +- 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` +- 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 +- 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 - 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" - ] - } - ``` + +``` +{ + "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", +}, +{ + "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" + ] +} +``` + +- If you are jlink probe, create `settings.json` in {projectRoot}/.vscode directory. + +``` +{ + "cortex-debug.armToolchainPath": "C:\\UserProgram\\arm_gcc\\none\\bin", + "cortex-debug.JLinkGDBServerPath": "C:\\Program Files\\SEGGER\\JLink\\JLinkGDBServerCL.exe", +} +``` + +- To change `executable` target in `launch.json` to `application` or `bootloader` - In the debug menu you can select `Debug with JLink` or `Debug with STLink` \ No newline at end of file