Porting an Existing Project

Getting Started

The Nordic Semiconductor nRF5 SDK is a great starting for developing 2.4 GHz solutions using their development boards. You'll want to grab a copy of the SDK to get started because we're going to build the treadmill sensor based off of the ANT+ SDM Tx example.

Alternatively, I've got just the ANT+ SDM Tx example pulled out with all of the other relevant files available on GitHub. If you'd like to skip all of the porting, you can get a ANT+ SDM Tx example that's been already ported to the NRF52840 Dongle on GitHub.

If you'd like to skip all this step and get right to the code, go with this option and we'll pick up again in the Calculating Speed and Distance post.

Getting Started

If you're not a regular embedded device developer, you'll probably need to set up the development environment like I did. This was by far the most difficult part of the process with many steps along the way. I'm not exactly sure how many were required to make things work. The NRF52840 Dongle Get Started guide will point to the tools and SDK. I ended up using SEGGER Embedded Studio for development and nRF Connect for its development environment setup guide and for programming the dongle.

Get the SoftDevice and ANT+ Key

At this point you're going to need the S212 SoftDevice and ANT+ Network Key. If you haven't already signed up as an ANT+ Adopter, this is the time.

Extract the S212 SoftDevice and navigate to the "include" directory inside it. Copy all of the files including the nrf52 directory to the "components/softdevice/s212/headers" folder.


Starting with an Example Project

You can now open this project in SEGGER Embedded Studio, which is free by the way, and try to compile the project.
Build->Build ant_sdm_tx_pca10040_s212
The build should fail because of an error in app_error_weak.h.
 You'll need to uncomment the evaluation key in app_error_weak.h:
//#define ANT_LICENSE_KEY "..."

If your build didn't fail here, this key is probably already uncommented. This is a good time to remember that this is all for non-commercial use. Any commercial use would require a commercial license key and license payments for each unit using the ANT SoftDevices.

There's one last step to making this is real ANT+ example. Earlier I mentioned that you'd need the ANT+ Network Key, here's where it comes in. Without the network key the code will default to the ANT public network key and any existing ANT+ devices won't see it. I ran into this problem the first time I got the example running and had to dig through the code to find out why SimulANTII and my watch couldn't see the SDM example. It's because the ANT+ network key needed to be set. Let's set it now:


  1. Right Click the project in the Project Explorer
  2. Change the Configuration to Common in the Project Options
  3. Select Preprocessor and expand the Preprocessor Definitions
  4. Add ANT_PLUS_NETWORK_KEY={REAL ANT PLUS NETWORK KEY}
You're all set. Now let's port this project to the NRF52840 Dongle.

Porting to the NRF52840 Dongle

Reading through this tutorial provides a good starting point for working with the NRF52840 dongle.

The NRF52840 dongle is board PCA10059 so we're going to port the PCA10040 SDM Tx example to the PCA10059. Start by copying the pca10040 folder and rename the copy to pca10059. Now, go to pca10059/s212/ses and rename the emProject and emSession files to reflect pca10059 instead of pca10040. Finally, open each of these files and find/replace the references of pca10040 with pca10059. Pay close attention in the emProject file because one of these replacements is a preprocessor definition and will need to be capitalized. Don't worry if you messed it up, we'll double check it in the next step.

Open up the emProject file within the pca10059 directory. Right-click on the the project in Project Explorer and select Options. Once again, select Common, click on Preprocessor, and expand the Preprocessor Definitions. Here are the values to change:
  • BOARD_PCA10059 (Should be changed already from the find/replace earlier)
  • NRF52 - Remove this entry
  • NRF52832_XXAA - Change to NRF52840_XXAA
Click OK to save those changes and next click on Linker. We need to change a few details about the Flash and RAM. For this step we're going to need some details provided in the S212 SoftDevice release notes. There should be a release notes PDF in the S212 download.
The SoftDevice properties tell us how much room in Flash and RAM we need to leave for the SoftDevice. Expand the Section Placement Macros property so these can be set:
  • FLASH_PH_START=0x0
  • FLASH_PH_SIZE=0x100000
  • RAM_PH_START=0x20000000
  • RAM_PH_SIZE=0x40000
    • 256KB
  • FLASH_START=0x12000
    • This is already correct. SoftDevice Flash Size
  • FLASH_SIZE=0xce000
    • The tutorial says the boot loader sits at 0xe0000 and occupies the rest of Flash. So the available size is 0xe0000 - 0x12000
  • RAM_START=0x20000b80
    • This is already correct. Calculated as RAM_PH_START + SoftDevice RAM Size
  • RAM_SIZE=0x3f480
    • 0x40000 - SoftDevice RAM Size
The project is now ready to run on the NRF52840 dongle. Next up is Calculating Speed and Distance.

Comments

Post a Comment