This is the project folder for the IMU firmware. It includes the nRF5 SDK 15.2.0 source files and the nrf52832_mdk development board config files.
Requirements:
- GNU Arm Embedded Toolchain
- GNU make GNUwin Make (for Windows)
- pyOCD
Download Git for Windows https://git-scm.com/downloads to clone this repository. We will use Git Bash terminal for building this project.
Clone this repo by using:
git clone https://github.com/MickAvery/head-impact-imu
You're using Linux, you should already know this. You're on your own.
Download and install the latest version of GNU Arm Embedded Toolchain . Then make sure to add the path to your toolchain to your OS "PATH" environment variable:
<path to install directory>/gcc-arm-none-eabi-6-2017-q2-update/bin
Adding the path makes it possible to run the toolchain executables from any directory using the terminal. To verify that the path is set correctly, type the following in your terminal:
$ arm-none-eabi-gcc --version
For Windows download and install GNUwin Make (for Windows). Download the "Complete package, except sources Setup" link. Run "make-3.81.exe" to install make. Add the path to your GNU Make executable to your "PATH" environment variable. For example:
C:\Program Files (x86)\GnuWin32\bin
Check to see it works by using
$ make REV=x
where x
is either 1
or 2
.
pyOCD is an open source Python library for programming and debugging for ARM Cortex-M devices.
-
Requires Python 2.7.9 or later, or Python 3.6.0 or later.
-
Workaround for libusb error on Python 3.7 on Windows: Use Python 3.8
Download and install Python 3.8 from https://www.python.org/. For Windows user, please check the "Add to PATH" box when installing.
Use pip to install pyOCD.
$ pip install --pre -U pyocd
Check to see if installed correctly:
$ pyocd
Once you have the GNU ARM toolchain, GNU make and pyOCD setup, you can build this project.
The makefile
is located in `/head_impact_IMU/ble_app/armgcc/ .
Go to your app config folder and run make:
$ cd path/to/proj/root
$ make REV=x
where REV=x
can be REV=1
, REV=2
, REV=3
, or REV=MDK
. By default it compiles to REV=1
.
If successful you should see:
$ make
Linking target: _build/nrf52832_xxaa.out
text data bss dec hex filename
26604 164 2464 29232 7230 _build/nrf52832_xxaa.out
Preparing: _build/nrf52832_xxaa.hex
Preparing: _build/nrf52832_xxaa.bin
DONE nrf52832_xxaa
If you want to flash to your development board run make pyocdflash
and you should see:
$ make pyocdflash
DONE nrf52832_xxaa
Flashing: _build/nrf52832_xxaa.hex
pyocd -t nrf52 -se _build/nrf52832_xxaa.hex
INFO:pyocd.board.board:Target type is nrf52
INFO:pyocd.coresight.dap:DP IDR = 0x2ba01477 (v1 rev2)
INFO:pyocd.coresight.ap:AP#0 IDR = 0x24770011 (AHB-AP var1 rev2)
INFO:pyocd.coresight.ap:AP#1 IDR = 0x02880000 (proprietary)
INFO:pyocd.coresight.rom_table:AP#0 ROM table #0 @ 0xe00ff000 (designer=244 part=006)
INFO:pyocd.coresight.rom_table:[0]<e000e000:SCS-M4 class=14 designer=43b part=00c>
INFO:pyocd.coresight.rom_table:[1]<e0001000:DWT class=14 designer=43b part=002>
INFO:pyocd.coresight.rom_table:[2]<e0002000:FPB class=14 designer=43b part=003>
INFO:pyocd.coresight.rom_table:[3]<e0000000:ITM class=14 designer=43b part=001>
INFO:pyocd.coresight.rom_table:[4]<e0040000:TPIU-M4 class=9 designer=43b part=9a1 devtype=11 archid=0000 devid=0:0:ca1>
INFO:pyocd.coresight.rom_table:[5]<e0041000:ETM-M4 class=9 designer=43b part=925 devtype=13 archid=0000 devid=0:0:0>
INFO:pyocd.coresight.cortex_m:CPU core #0 is Cortex-M4 r0p1
INFO:pyocd.coresight.cortex_m:FPU present: FPv4-SP
INFO:pyocd.coresight.dwt:4 hardware watchpoints
INFO:pyocd.coresight.fpb:6 hardware breakpoints, 4 literal comparators
[---|---|---|---|---|---|---|---|---|----]
[========================================]
INFO:pyocd.flash.loader:Erased 0 bytes (0 sectors), programmed 0 bytes (0 pages), skipped 28672 bytes (7 pages) at 9.19 kB/s
Alternatively, you can use the Debug (pyOCD)
launch target on VSCode.
You may use any text editor you like, however we chose Visual Studio Code since it provided a debugging environment. We used the following extensions in VS Code:
A launch.json
file is included in .vscode folder for setting up the pyocd debugger and jlink debugger. Current launch targets include:
Debug (pyOCD)
- Flash the board using pyOCD (only valid when using nRF52832-MDK)Debug J-Link
- Flash the board using a JLink Debugger and nRF Command Line ToolsDebug OpenOCD
- Flash the board using an ST-Link Debugger and OpenOCD
Another note is the jlink launch.json
is set up for a linux user so you will have to change the path locations for "serverpath" and "svdFile" in the launch.json.
"serverpath": "/opt/SEGGER/JLink/JLinkGDBServerCLExe", //change to your path
.
.
.
"svdFile": "/opt/SEGGER/Ozone/Config/CPU/Cortex-M4F.svd" //change to your path
See reference links at the end on a guide to setup your launch.json
A command line interface (CLI) was implemented to provide a user interface for rapid testing. The commands have a hierarchical structure described below:
sysprop
sensor
- adxl372
- calbrate
- stream
- icm20649
- stream
- vcnl4040
- stream
flash
- erase
- pp_test
datetime
- get
- set
For example, if you want to set the datetime then you type datetime set YYYY MM DD HH MM SS ffffff
, and getting the device's datetime is datetime get
.
The CLI is accessible through UART and the JLink RTT, setup is described below:
The following MCU pins correspond with UART RX and TX pins:
REV 1 | REV 2/3 | MDK | |
---|---|---|---|
RX | 23 | 19 | 17 |
TX | 24 | 20 | 18 |
Keep in mind that when using an RS232/UART dongle, you need to hook up the dongle's TX
pin with the MCU's RX
pin and the dongle's RX
pin with the MCU's TX
pin:
RS232 TX
-> Device RX
RS232 RX
-> Device TX
Your terminal emulator should then have the following settings for a serial terminal:
Setting | Value |
---|---|
Baud | 921600 |
Data | 8-bit |
Patiry | None |
Stop bits | 1-bit |
Flow Control | None |
Newline (receive+transmit) | LF (or \n) |
Open the JLinkRTTViewer
GUI (comes with the nRF Command Line Tools, see below), and follow these configurations:
Connection to J-Link | USB |
Specify Target Device | NRF52 |
target Interface & Speed | SWD, 4000KHz |
Make sure you're in Terminal 0, which should be one of the tabs.
Go to Input > Sending..., and choose Send on Enter.
You'll now have access to the CLI through JLink RTT.
Software Requirements:
- GNU Arm Embedded Toolchain
- GNU make GNUwin Make (for Windows)
- nRF Command Line Tools
Assuming you have GNU arm toolchain and make setup properly from the above.
Hardware Requirements:
- PCB REV
- JLink mini EDU + USB A to micro USB B cable
- USB to UART adapter + USB A to USB B cable
- LiPo battery (optional if you are using the USB to UART adapter to power the device)
The USB to UART adapter is for getting serial output from the tx and rx pins. You may use the VCC and GND of the USB to UART adapter to power the PCB. The connections are VCC->VBAT, GND->GND, Tx->Rx, Rx->Tx.
Download and install nRF Command Line Tools. By default, the installer should include it in the path environment variable. Check that the path environment variable is set like:
C:\Program Files\Nordic Semiconductor\nrf-command-line-tools\bin\
Now instead of using pyocd
as the programmer and debugger, the nrfjprog
will be the programmer and debugger. The type of programmer should already be included in the makefile.
The Jlink is for programming and debugging firmware on the PCB. JLink requires using the nrfjprog
command from nRF Command Line Tools package instead of pyocd
. The JLink has a ribbon cable connector included. To check if the connection is correct, you can run JLinkExe
and check that the VTref is ~3.3V
and that you can connect to the MCU. See below for an example output.
> JLinkExe
SEGGER J-Link Commander V6.62a (Compiled Jan 31 2020 12:58:00)
DLL version V6.62a, compiled Jan 31 2020 12:57:49
Connecting to J-Link via USB...O.K.
Firmware: J-Link EDU Mini V1 compiled Jan 7 2020 16:53:19
Hardware version: V1.00
S/N: 801011674
License(s): FlashBP, GDB
VTref=3.299V
Type "connect" to establish a target connection, '?' for help
J-Link>connect
Please specify device / core. <Default>: NRF52832_XXAA
Type '?' for selection dialog
Device>
Please specify target interface:
J) JTAG (Default)
S) SWD
T) cJTAG
TIF>S
Specify target interface speed [kHz]. <Default>: 4000 kHz
Speed>
Device "NRF52832_XXAA" selected.
Connecting to target via SWD
InitTarget() start
InitTarget() end
Found SW-DP with ID 0x2BA01477
DPIDR: 0x2BA01477
Scanning AP map to find all available APs
AP[2]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
AP[1]: JTAG-AP (IDR: 0x02880000)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
Cortex-M4 identified.
J-Link>
*****************************************************************************
*** Files Organization ***
*****************************************************************************
--{root} - ChibiOS directory.
+-- main.c - Firmware entry point
+-- sdk_config.h - nRF SDK configurations
+-- .travis.yml - TravisCI configurations
+-- inc/ - Header files
+-- src/ - Modules source code
+-- drivers/ - Low level drivers for serial communication and external peripherals
+-- scripts/ - Contains scripts for automation and data processing
+-- nrf_sdk/ - nRF SDK 15.2 source files
+-- board_config/ - Contains pin mappings for each board revision
This directory contains part of the Nordic Semiconductor Software Development Kit (SDK). The full version is an extremely detailed guide for developing applications on the NRF52832 microcontroller used by the project.
The partial version contained here consists mainly of toolchain resources (as you have seen above), as well as various libraries that are included throughout the project.
The full SDK contains various examples, most of which are irrelevant to this project, and so are not included here. Nordic Semiconductor also has an onlineInfocenter that provides more detailed information on the SDK and its various modules.
This header file allows you to modify the configuration options for the code that you write. Essentially, it contains a list of #define statements that allow you to select the MCU features or specifc modes used by your application.
For continued functionality of the applciations we've developed on these platforms, we suggest copy-and-pasting the sdk_config file used by the current code set that is most comparable to your new code set, and using that as a basis for your new configuration file. In the unlikely event that you need to modify your configurations, you can edit this file.
Nordic Semiconductors supplies more information on these configuration files here
A makefile is required so that the make command can compile and link your program. This allows the make command to create the source files required for running code on the device. All of the source files and folders common to the make target need to be included in the makefile in order for the program to be compiled succesfully.
The GNU make manual can be found here