|
| 1 | +# Introduction |
| 2 | + |
| 3 | +This project uses CMake and the GNU ARM-Toolchain as build system and GDB/OpenOCD are used for debugging purposes. |
| 4 | + |
| 5 | +By using these tools the development environment is platform agnostic and independent of chip manufacturer specific Integrated Development Environments. |
| 6 | +It allows to build the project either by using a command line terminal or by using IDE's like [VSCode](#vscode) or [KDevelop](#kdevelop). |
| 7 | + |
| 8 | +# Prerequisites |
| 9 | + |
| 10 | +* CMake >= 3.6 |
| 11 | + * GNU/Linux: |
| 12 | + * Ubuntu 16.04/ Linux Mint 18: Since the official repository version is too old, one can use e.g. [PPA](https://launchpad.net/~adrozdoff/+archive/ubuntu/cmake) |
| 13 | + * Linux Arch: `pacman -S cmake` |
| 14 | + * Windows: |
| 15 | + * [CMake Download](https://cmake.org/download/) |
| 16 | + **Note**: Please ensure that CMake path is added to the system PATH variable. |
| 17 | + * OSX: |
| 18 | + * Homebrew: `brew install cmake` |
| 19 | +* GNU ARM-Toolchain |
| 20 | + * GNU/Linux: |
| 21 | + * Ubuntu 16.04/ Linux Mint 18: Since the official repository version is too old, one can use e.g. [PPA](https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa) |
| 22 | + * Linux Arch: `pacman -S arm-none-eabi-gcc arm-none-eabi-newlib` |
| 23 | + * Windows: |
| 24 | + * [GNU Arm Embedded Toolchain](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm) |
| 25 | + * The Make utility is also required, one can use e.g. [MSYS2](http://www.msys2.org) |
| 26 | + **Note**: Please ensure that both paths are added to the system PATH variable. |
| 27 | + * OSX: |
| 28 | + * Homebrew: `brew tap ARMmbed/homebrew-formulae && brew install arm-none-eabi-gcc` |
| 29 | +* OpenOCD |
| 30 | + * GNU/Linux: |
| 31 | + * Ubuntu 16.04/ Linux Mint 18: `apt-get install openocd` |
| 32 | + * Linux Arch: `pacman -S openocd` |
| 33 | + * Windows: |
| 34 | + * Unofficial binary packages are available [here](http://openocd.org/getting-openocd/) for download |
| 35 | + **Note**: The debug configuration for [VSCode](#vscode) will assume that OpenOCD is installed under `C:/openocd`. If it is not the case one must change the `OPENOCD_BIN` variable according to right location. |
| 36 | + * OSX: |
| 37 | + * Homebrew: `brew install openocd` |
| 38 | + |
| 39 | +# Commandline build instructions |
| 40 | + |
| 41 | +1. Go to root directory of the project |
| 42 | + |
| 43 | + `cd path/to/project/directory` |
| 44 | + |
| 45 | +2. Create a directory named 'build' |
| 46 | + |
| 47 | + `mkdir build` |
| 48 | + |
| 49 | +3. Go to the created `build` directory |
| 50 | + |
| 51 | + `cd build` |
| 52 | + |
| 53 | +4. run |
| 54 | + |
| 55 | + `cmake -DCMAKE_TOOLCHAIN_FILE="cmake/toolchain-arm-none-eabi.cmake" ..` |
| 56 | + |
| 57 | +**Note**: If the GNU ARM-Toolchain is not installed under the default path (GNU Linux:`/usr`, Mac OS `/usr/local`) a prefix has to be provided: |
| 58 | + `cmake -DCMAKE_TOOLCHAIN_FILE="cmake/toolchain-arm-none-eabi.cmake" -DTOOLCHAIN_PREFIX="/path/to/the/toolchain" ..` |
| 59 | +For Windows platforms the prefix has to be provided anyway and additionally the CMake Generator for MinGW Makefiles has to be chosen: |
| 60 | + `cmake -DCMAKE_TOOLCHAIN_FILE="cmake/toolchain-arm-none-eabi.cmake" -DTOOLCHAIN_PREFIX="/path/to/the/toolchain" -G "MinGW Makefiles" ..` |
| 61 | + |
| 62 | +## Available configuration options for CMake |
| 63 | + |
| 64 | +The possibility to choose the application, target board and more options can be done using the provided configuration options. |
| 65 | + |
| 66 | +These configuration options can be set through additional commandline parameters, for example: |
| 67 | + `cmake -DCMAKE_TOOLCHAIN_FILE="cmake/toolchain-arm-none-eabi.cmake" -DAPPLICATION="LoRaMac" -DCLASS="classC" ..` |
| 68 | + |
| 69 | +Alternatively one can use a graphical interface to configure CMake, drop down menus and check boxes will provide to the user the possible options. |
| 70 | + |
| 71 | +* CMake QT GUI with `cmake-gui ..` |
| 72 | +* CMake curses interface with `ccmake ..` |
| 73 | + |
| 74 | +### Options that can be choose by the user |
| 75 | + |
| 76 | +* `APPLICATION` - Application example choice. |
| 77 | + The possible choices are: |
| 78 | + * LoRaMac (Default) |
| 79 | + * ping-pong |
| 80 | + * rx-sensi |
| 81 | + * tx-cw |
| 82 | +* `CLASS` - Class specific application example choice. |
| 83 | + **Note**: Only applicable to LoRaMac `APPLICATION` choice. |
| 84 | + The possible choices are: |
| 85 | + * classA |
| 86 | + * classB |
| 87 | + * classC |
| 88 | +* `ACTIVE_REGION` - Active region for which the stack will be initialized. |
| 89 | + **Note**: Only applicable to LoRaMac `APPLICATION` choice. |
| 90 | + The possible choices are: |
| 91 | + * LORAMAC_REGION_EU868 |
| 92 | + * LORAMAC_REGION_US915 |
| 93 | + * LORAMAC_REGION_CN779 |
| 94 | + * LORAMAC_REGION_EU433 |
| 95 | + * LORAMAC_REGION_AU915 |
| 96 | + * LORAMAC_REGION_AS923 |
| 97 | + * LORAMAC_REGION_CN470 |
| 98 | + * LORAMAC_REGION_KR920 |
| 99 | + * LORAMAC_REGION_IN865 |
| 100 | + * LORAMAC_REGION_US915_HYBRID |
| 101 | +* `MODULATION` - Type of modulation choice. |
| 102 | + **Note**: Only applicable to ping-pong or rx-sensi `APPLICATION` choice. |
| 103 | + The possible choices are: |
| 104 | + * LORA |
| 105 | + * FSK |
| 106 | +* `USE_BOOTLOADER` - Enables Bootloader support. (Default OFF) |
| 107 | + **Note**: Only applicable to LoRaMote or SensorNode `BOARD` choice. |
| 108 | +* `USE_USB_CDC` - Enables USB-Uart support. (Default OFF) |
| 109 | + **Note**: Only applicable to LoRaMote or SensorNode `BOARD` choice. |
| 110 | +* `USE_DEBUGGER`- Enables debugger support. (Default ON) |
| 111 | +* `BOARD` - Target board choice. |
| 112 | + The possible choices are: |
| 113 | + * LoRaMote (Default) |
| 114 | + * MoteII |
| 115 | + * NAMote72 |
| 116 | + * SAML21 |
| 117 | + * SensorNode |
| 118 | + * SK-iM880A |
| 119 | +* `REGION_EU868` - Enables support for the Region EU868 (Default ON) |
| 120 | +* `REGION_US915` - Enables support for the Region US915 (Default OFF) |
| 121 | +* `REGION_CN779` - Enables support for the Region CN779 (Default OFF) |
| 122 | +* `REGION_EU433` - Enables support for the Region EU433 (Default OFF) |
| 123 | +* `REGION_AU915` - Enables support for the Region AU915 (Default OFF) |
| 124 | +* `REGION_AS923` - Enables support for the Region AS923 (Default OFF) |
| 125 | +* `REGION_CN470` - Enables support for the Region CN470 (Default OFF) |
| 126 | +* `REGION_KR920` - Enables support for the Region IN865 (Default OFF) |
| 127 | +* `REGION_IN865` - Enables support for the Region AS923 (Default OFF) |
| 128 | +* `REGION_US915_HYBRID` - Enables support for the Region US915 HYBRID (Default OFF) |
| 129 | + |
| 130 | +### Options that are automatically set |
| 131 | + |
| 132 | +* `RADIO` - Defines the radio to be used. |
| 133 | + The possible choices are: |
| 134 | + * sx1272 |
| 135 | + * sx1276 |
| 136 | +* `LINKER_SCRIPT` - Defines the target specific linker script path. |
| 137 | +* `OPENOCD_BIN` - Defines the OpenOCD path. |
| 138 | +* `OPENOCD_INTERFACE` - Defines the interface configuration file to be used by OpenOCD. |
| 139 | +* `OPENOCD_TARGET` - Defines the target configuration file to be used by OpenOCD. |
| 140 | + |
| 141 | +# Debugging |
| 142 | + |
| 143 | +1. OpenOCD |
| 144 | + OpenOCD has to be started with parameters that depend on the used debugger device and target board. |
| 145 | + Some examples are shown below: |
| 146 | + * LoRaMote + STLinkV2: |
| 147 | + `openocd -f interface/stlink-v2.cfg -f target/stm32l1.cfg` |
| 148 | + |
| 149 | + * MoteII + STLinkV2-1 (On board debugger): |
| 150 | + `openocd -f interface/stlink-v2-1.cfg -f target/stm32l0.cfg` |
| 151 | + |
| 152 | + * LoRaMote + JLink: |
| 153 | + `openocd -f interface/jlink.cfg -c "transport select swd" -f target/stm32l1.cfg` |
| 154 | + |
| 155 | + * SAML21 Xplained Pro (On board debugger, tested with openocd 0.10, did not work with 0.9): |
| 156 | + `openocd -f interface/cmsis-dap.cfg -f target/at91samdXX.cfg` |
| 157 | + |
| 158 | +2. GDB |
| 159 | + The below GDB usage example shows how to start a debug session, writing the program to the flash and run. |
| 160 | + * Run ARM-GNU GDB with: |
| 161 | + `arm-none-eabi-gdb` |
| 162 | + * Choose the program you want to debug: |
| 163 | + `file src/apps/LoRaMac/LoRaMac-classA` |
| 164 | + * Connect GDB to OpenOCD: |
| 165 | + `target extended-remote localhost:3333` |
| 166 | + * Execute a reset and halt of the target: |
| 167 | + `monitor reset halt` |
| 168 | + * Flash the program to the target Flash memory: |
| 169 | + `load` |
| 170 | + * Add a one-time break point at main: |
| 171 | + `thbreak main` |
| 172 | + * Run the program until the break point: |
| 173 | + `continue` |
| 174 | + * Finally run the program: |
| 175 | + `continue` |
| 176 | + |
| 177 | + |
| 178 | +# IDE Support |
| 179 | + |
| 180 | +## VSCode |
| 181 | + |
| 182 | +### Additional Prerequisites |
| 183 | + |
| 184 | +* Visual Studio Code: |
| 185 | + * GNU/Linux, Windows and OSX: |
| 186 | + * [Download](https://code.visualstudio.com/Download) |
| 187 | +* Extensions: Open `VSCode ->EXTENSION (Crtl+Shift+x)` and search for: |
| 188 | + * C/C++ |
| 189 | + * CMake |
| 190 | + * CMake Tools |
| 191 | + * Native Debug |
| 192 | + |
| 193 | +### Configuration |
| 194 | + |
| 195 | +For Windows platforms it is necessary to make some additional configurations. Open your settings under *File->Preferences->Settings* and add the following lines: |
| 196 | + |
| 197 | +Add MinGW Makefiles as preferred Generator: |
| 198 | + |
| 199 | +```json |
| 200 | +"cmake.preferredGenerators": [ |
| 201 | + "MinGW Makefiles", |
| 202 | + "Ninja", |
| 203 | + "Unix Makefiles" |
| 204 | + ] |
| 205 | +``` |
| 206 | + |
| 207 | +Set the CMake path: |
| 208 | +```json |
| 209 | + "cmake.cmakePath": "path/to/cmake.exe" |
| 210 | +``` |
| 211 | + |
| 212 | +### Usage |
| 213 | + |
| 214 | +1. Open the directory of the cloned repository. |
| 215 | + The *CMake Tools* extension will automatically generate a *`.cmaketools.json`* file based on the CMakeLists. |
| 216 | +2. The *`settings.json`* file under `.vscode` directory is the place where one can change the build options. |
| 217 | + These are the build options that will be provided to CMake. |
| 218 | + Please see chapter [Commandline Build Instructions](#commandline-build-instructions) for information about build options. |
| 219 | +3. Click on the blue status bar of *CMake Tools* to choose a build type (`Debug` or `Release`). |
| 220 | + A CMake configuration process will be performed. |
| 221 | +4. A `Build` button will now be available. |
| 222 | + Click this button to build the target. |
| 223 | +5. The CMake build system will automatically generate a *`launch.json`* file which setups the debugging process for the given board. |
| 224 | +6. Press the `F5` key to start a debug session. |
| 225 | + This will automatically start the GDB and OpenOCD processes. |
| 226 | + |
| 227 | +### Useful Hints |
| 228 | + |
| 229 | +* Change CMake options: Open the Command palette (Crtl+Shift+P) and type `CMake: Edit the CMake Cache` |
| 230 | +* Execute a clean rebuild: Open the Command palette (Crtl+Shift+P) and type `CMake: Clean rebuild` |
| 231 | + |
| 232 | +For detailed information about CMake Tools extension please see their [github repository](https://github.com/vector-of-bool/vscode-cmake-tools). |
| 233 | + |
| 234 | +## KDevelop |
| 235 | + |
| 236 | +### Additional Prerequisites |
| 237 | + |
| 238 | +* KDevelop: |
| 239 | + * GNU/Linux: |
| 240 | + * Ubuntu 16.04/ Linux Mint 18: `apt-get install kdevelop` |
| 241 | + * Linux Arch: `pacman -S kdevelop` |
| 242 | + * Windows: |
| 243 | + * [KDevelop Download](https://www.kdevelop.org/download) |
| 244 | + **Note**: Currently there is no GDB support but it is planned for future releases. |
| 245 | + * OSX: |
| 246 | + * [KDevelop Download](https://www.kdevelop.org/download). |
| 247 | + No official binaries are available. Must be built from source code. |
| 248 | + |
| 249 | +### Usage |
| 250 | + |
| 251 | +1. To open the project click on *`Project->Open /Import Project...`* and choose the top level `CMakeLists.txt` directory of the cloned repository. |
| 252 | + Follow the indications to setup the project and add `-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm-none-eabi.cmake` to the *`Extra Arguments`*. |
| 253 | +2. The CMake options and variables can be changed by right-clicking on project and selecting *`Open configuration...`*. |
| 254 | + A graphical interface will pop-up. |
| 255 | + Please see chapter [Commandline Build Instructions](#commandline-build-instructions) for information about build options. |
| 256 | +3. Click on `Build` to build the project. |
| 257 | +4. Create a launch configuration for debugging: |
| 258 | + * Click on *`Run->Configure Launches...`* and add a new *`Compiled Binary Launcher`*. |
| 259 | + * Set the field *`Debugger executable`* according to your system. For example `/usr/bin/arm-none-eabi-gdb` . |
| 260 | + * Choose the `Run gdb script` according to the application you want to debug. |
| 261 | + For example: `loramac-node/build/src/apps/LoRaMac/openocd-run.gdb`. |
| 262 | + **Note**: The CMake build system will automatically generate the GDB run script. |
| 263 | +5. Start OpenOCD in a command line terminal as described on chapter [Debugging](#debugging). |
| 264 | +6. Click on "Debug" to launch a debug session. |
0 commit comments