domingo, 21 de outubro de 2018

SEGGER STUDIO PARA PROGRAMAÇÃO DO NINA B112 

O objetivo deste BLOG é dar uma idéia geral da ferramenta SEGGER STUDIO, utilizada para programação do NINA B112. O material é da empresa Embedded Centric, a qual oferece cursos online sobre o SDK, poupando horas de trabalho no entendimento dos códigos exemplos em C. O material (separado por LAB's) pode ser aplicado ao EVK-NINA-B1, mas requer alteração do arquivo de mapa de IO board_custom. 

nRF5x SoC Overview

The Nordic Semiconductor nRF5x SoCs are ideal for ultra-low power (ULP) and cost effective short-range wireless solutions. Typical applications for the nRF5x SoC are Internet of Things (IoT) devices, wearables, smart home, wireless mobile phone accessories, PC Peripherals, beacons, Bluetooth-enabled consumer electronics in general, human interface devices, sports equipment, medical equipment, security and toys. The nRF5x supports Bluetooth Low Energy (BLE) (also known as Bluetooth Smart) among other short-range wireless protocols. What made these devices so popular is that they can be operated for months and sometimes years on a small battery such as a button cell battery if properly programmed and configured . Samples of the nRFx SoC are shown below :
There are two series in the nRF5x SoC family. The original nRF51 series which was introduced in 2012, and the more advanced and relevantly newer nRF52 series . The nRF52 has extra features ,more memory, RAM and even lower than its predecessor in power consumption , however , when it comes to the chip cost ; the nRF51 has the advantage here.

nRF51 Series logo (Left) / nRF52 Series logo (Right)
The key differences between these two series are highlighted in the following table:

nRF52/nRF51 Comparison
Each of these two series ( nRF52 and nRF51) has three chips options.

The nRF5x SoCs are flash memory based. It means that the firmware will be residing on a flash memory inside the SOC itself . When compared with ROM or OTP SoCs, flash based SoCs are easy to work with and more fixable to update/patch the firmware later on.
The RAM memory is also hosted in the chip die. nRF52 and nRF51 chips differ in the available hardware peripherals and available RAM and Flash as shown in the tables below :
Available Hardware Peripherals in nRF51 and nRF52 Series
Available Hardware Peripherals in nRF51 and nRF52 Series
AvailableFlash_RAM_nRF51_nRF52
Available Flash and RAM in nRF51 and nRF52 series

nRF52 Architecture

This series of system on chip offers a very powerful microcontroller with an amazing multi-protocol 2.4GHz radio transceiver, combined with a rich set of  system, analog , digital peripherals  and RAM/flash memories all in  just one 3.2 x3.0 mm CSP chip. The nRF52 offers more processing power than its predecessor the nRF51  . The ARM Cortex-M4 on the nRF52 is more capable than the ARM Cortex-M0 , especially when it comes to floating point and DSP operations. More flash and RAM memory were added in the new series . The clock rate has also been increased substantially (See comparison here )and power consumption has been further reduced by adopting different advanced strategies and silicon technologies. The figures below show a brief and detailed view of the nRF52 architecture.

nRF52 Block Diagram – Brief
nRF52_block_diagram_detailed
nRF52 Block Diagram- Detailed
Available system peripherals and Digital and Analog I/O (in order as they appear in the detailed block diagram) :
  • 31x GPIO (Except the nRF52840 which has 48XGPIO ).
  • Hardware Random Number Generator (RNG).
  • 3×24-bit Real Time Clock (RTC).
  • 5×32-bit timer.
  • Built-in Temp sensor.
  • 128-bit AES ECB/CCM/AAR co-processor( AES Hardware Encryption Accelerator).
  • 2x Master SPI.
  • 2x TWI/M/S (2-wire(I2C compatible ) ).
  • 2xUART.
  • 2xSlave SPI.
  • Pulse Density Modulation (PDM)
  • Inter-IC Sound (I2S)
  • 4x Pulse Width Modulation (PWM)
  • Quadrature Demodulator.
  • Successive Approximation Analog to Digital Convertor(SAADC).
  • 2x Comparators ( COMP and LPCOMP)
  • GPIOTE( GPIO Task and Events ).
  • Near Field Communication Tag (NFCT)
  • 16-channel Programmable Peripheral Interconnect (PPI).
  • Watchdog timer.
There are three chips options in the nRF52 series :

nRF52 Series
The complete comparison between these chips is shown in the figure below(Click on the picture to enlarge):

nRF52 series chips comparison

nRF5 Software Development Kit (SDK) tutorial

Overview

The nRF5 SDK contains a broad selection of drivers,  libraries, board definition files ,communication protocol stacks such as the SoftDevices for BLE  and a large set of examples for the Nordic Semiconductor devices and development boards. The SDK must be downloaded as it will be the foundation for your firmware development targeting the nRF5 devices.

Which IDE to choose ?

The SDK does not come with an Integrated Development Environment(IDE), you get to choose which IDE and compiler to use. There are five different methods to program the Nordic Semiconductor  nRF5x devices. Here is a brief overview on the advantage and disadvantages :
  1. Segger Embedded Studio (SES) :  Completely license free, no code size limitations, no restrictions whatsoever. SEGGER and Nordic Semiconductor have signed an agreement in late 2017 that entitles developers to use Embedded Studio with Nordic nRF5x chips for both commercial and non-commercial uses .The nRF5 SDK already contains out of the box examples developed in SES.  Embedded Studio is a complete all-in-one solution for managing, building, testing and deploying embedded applications. It supports everything from a powerful project manager and source code editor, included C/C++ compilers based on GCC, as well as CLANG/LLVM and an integrated debugger with advanced debug information windows and direct J-Link integration, right through to version control features for automatic deployment of finished application. The SES is supported on Windows, Linux and OSX.
  2. GNU ARM GCC (Makefile+ Eclipse) : This approach is also license free, with no limitation . It’s based on the industry standard GNU Arm Embedded Toolchain. The nRF5 SDK comes with  examples delivered as makefiles which uses the toolchain. You could use your favorite choice of IDE (Ex: Eclipse) in this approach. This method is only recommended for advanced developers as it involves heavy setup procedures. This approach is cross-platform when it comes to the development environment(Linux, OSX, and Windows ).
  3. Keil µVision :  Keil  is a popular IDE for software development solution for ARM-based microcontrollers and includes all components that you need to create, build, and debug embedded applications. It  is also  quite user friendly , However, you need to purchase a license to use it . The free “Lite” version has both code size limitation, which means you won’t be able to generate an executable if your program size exceeded 32Kb and also features limitations. Keil only works on Windows machines.
  4. IAR Embedded Workbench:  Mature and well-established IDE but similar to Keil requires an expensive license. The current IAR workbench only works on Windows machines.
  5. ARM mbed online IDE : This is your best bet if you just want to create a quick proof of concept prototypes on a supported development board. All you need to get started is to create an account (which is completely free) and start working on your application online using their online C/C++ compiler.   Your application will be based on the Mbed OS  and its drivers /libraries. The level of abstraction offered by Mbed OS is amazing, you can create functioning prototypes very quickly. Keep in mind that the debugging capabilities of the online platform is weak. Not recommended for production-level development.
comparision_IDE_nRF5x
Comparison between the different methods available to program the nRF5x chips
The method used in this course is number 1 , which is using the license-free and mature  Segger Embedded Studio (SES)  Integrated Development Environment(IDE). The procedures to download, setup, link it with the nRF5 SDK,  and acquire the free license of the IDE are elaborated in LabA-5. Migration between projects done in SES,GNU GCC, or Keil or IAR is possible , since they all use the same backbones drivers, libraries, protocols stacks of nRF5 SDK offered by Nordic Semiconductor.
The nRF5  SDK is available as a .zip-archive file and can be downloaded free of charge from Nordic Semiconductor website .
SDK_versions
nRF5 SDK versions (Select the one which support your development kit)

Which version to choose ?

Your choice of SDK version will  strongly depend on the development board you are using . Please keep in mind that it’s not always going to be the latest one. The latest nRF5 SDK version at the time of writing this post is  v15.0.0 . It support the five Nordic Semiconductor development boards shown below
Supported Boards_nRF5 SDK v15.0.0
nRF5 SDK v15.0.0 Supported Boards
The above information was obtained from http://infocenter.nordicsemi.com -> Software Development Kit -> nRF5 SDK -> nRF5 SDK v15.0.0 -> SDK Release Notes

nRF5_SDK_v12.3.0 Supports PCA10028 and PCA10031
For a 3’rd party development board (Not produced by Nordic Semiconductor), the correct SDK version can is determined  by  finding  the Nordic chip used by the board  (nRF5xxxx)and its IC revision number ( Engineering A, Engineering B, Engineering C, 1,2, or 3 ) , these information are usually found in the datasheet or the user guide of the development board. Once these information are found go to http://infocenter.nordicsemi.com/ .  Select nRF51 Series or nRF51 Series,  then select Compatibility matrix -> nRF5x Series IC revisions compatibility with SDK and SoftDevices.
Example : Suppose you have a 3’rd party development board which hosts  the Nordic Semiconductor nRF51822 chip revision 3 . The correct SDK to chose from should be bigger than 8.0.0 and less or equal to 12.3.0(Preferably the later 12.3.0) , as obtained from the comparability matrix from Nordic Info Center.

Example : Compatible SDK version for an nRF51822 chip revision 3

Exploring the nRF5 SDK

Once you have identified the right version of the SDK that suites your development board or device( Explained in the previous step),  follow the following steps to take a brief view of what comes in the SDK.
1.Download the .zip-archive file of the suitable SDK version  from here website
nRF5 SDK v15.0.0 Download
Download SDK v15.0.0 for nRF52 series
In the screenshot above, we are assuming a development targeting the nRF52 series chips such as the ones hosted on the nRF52840-DK or nRF52-DK development boards.
2. Create a folder called nordic_semi on your local disk ( it’s preferable to place it as close as possible to the root directory and avoid paths which contains white spaces).
Extract_nRF5SDK
Extract the archived file of the nRF5 SDK locally.
3. After the extraction is complete , browse inside the SDK :
SDK_top_level
nRF5 SDK v 15.0.0 Top Level Directory Content
The directories contain the following :
A. components :  This is the core folder inside the SKD. It contains communication protocols APIs (IEEE 802.15.4,  ANT, BLE, etc.. ), boards definition files, drivers abstraction layer, a large set of  a very powerful libraries(56) ,  Softdevices binary files, and  toolchains configuration files.

components directory inside the nRF5 SDK

B. config : This folder contains a  generic sdk_config.h file that has all available static configuration options for each supported device ( For the nRF5 v 15.0.0 its only the nRF52 series ). It also contains a generic linker files for Segger Embedded Studio flash_placement.xml and ARM GCC generic_gcc_nrf52.ld . These linker files contain information about the memory sections present on the supported SoCs.

config directory inside the nRF5 SDK


Snapshot of the content of sdk_config and flash_placement
The SDK configuration header file sdk_config.h helps to manage the static configuration of a firmware that is built on top of nRF5 SDK. All projects must contain a sdk_config.h  file in which only the used modules are enabled. The configuration file consists of the SDK modules configuration part, which is common for all projects, and an application-specific configuration section.
C. documentation : As the name suggests, the SDK documentation links are placed here.  The most recommended place for documentation when it comes to Nordic nRF5x chips is the Nordic Semi info center http://infocenter.nordicsemi.com/ .What you have in this directory is just a link to it.

nRF5 SDK documentation directory
D. examples : Ready for deployment rich set of well-written examples.

nRF5 SDK examples directory
The examples covers a lot of topics :
  • IEEE 802.15.4 LR-WPAN wireless personal area networks examples.
  • ANT examples (Propitiatory short range wireless protocol).
  • Bluetooth Low Energy examples(Central role, peripheral role, both , and DFU).
  • Cryptographic examples.
  • Device Firmware Update (DFU) examples.
  • Direct Test Mode(DTM) examples.
  • Internet of things (IoT) examples.
  • Nordic proprietary protocols exmples(Gazell  , Enhanced ShockBurst)
  • Near Field Communication (NFC) examples.
  • Hardware Peripherals examples ( UART, I2C, Timers, PWM, etc..)
Not all examples are available for all development kits. Open the readme file inside the examples directory  and see which examples are supported by which boards .

nRF5 SDK examples compatibility matrix
One important note to remember regarding the nRF5 SDK examples, each example folder has several separate sub-folders, which is for the different supported development boards. See the screenshot below as an example

UART hardware peripheral example directory layout
Inside each board project directory (ex: pca10056) you will find  project sub-directories for the supported IDEs.
E. external : source code files for 3’rd party  libraries, protocol stacks  and utilities ( Lwip, FatFs, cJson, etc…)

nRF5 SDK external directory
E. external_tools : The CMSIS Configuration Wizard is shipped here . The Configuration Wizard  provides a user-friendly method to enable/disable modules(libraries, drivers, softdevices, features) from the SDK config file sdk_config.hwithout the need to do that manually. You need to have Java installed on your machine in order to use the CMSIS Configuration Wizard .

CMSIS Configuration Wizard available in the external_tools subdirectory of the SDK


CMSIS Configuration Wizard

Segger Embedded Studio for Nordic nRF5x tutorial

Overview

This lab will go over all the steps needed to download, install , configure, license and test the SEGGER Embedded studio for Nordic nRF5x devices and development boards.  SEGGER Embedded Studio(SES) is a full-fledged  powerful C/C++ integrated development environment for ARM and Cortex microcontrollers and microprocessors. It comes with both GCC and Clang/LLVM toolchains (C/C++ cross compilers, linkers , assemblers, image utilities,etc.. ) and C/C++ standard libraries that have been specifically tailored for embedded systems. SES is cross-platform, it runs on Windows, Mac OS and Linux. The main two advantages to choose SES over other standard IDEs such as Keil , and IAR is that SEGGER and Nordic Semiconductor have signed an agreement in late 2017 that entitles developers to use Segger Embedded Studio with Nordic nRF5x chips for both commercial and non-commercial uses free of charge. The second reason is that all Nordic nRF5 SDK examples have SES projects support , which significantly simplifies the process of project setup, prototyping and testing. To see the full comparison among all methods available to program the nRFx devices check the article “Which IDE to choose ?” in LabA-4 .

SEGGER Embedded Studio Logo

Setting up the tools

1.Download Nordic nRF5 SDK : Follow the steps explained in in LabA-4 to select the right SDK version for you device or development kit. In this Lab we are assuming the nRF52840-DK development board (Board ID: PCA10056)  is being used.
a.Download the .zip-archive file of the suitable SDK version from here website(https://developer.nordicsemi.com/nRF5_SDK/)

Download SDK v15.0.0 for nRF52 series
b.Create a folder called nordic_semi on your local disk ( it’s preferable to place it as close as possible to the root directory and avoid paths which contain white white spaces), and then extract the .zip-archive file.

Extract the archived file of the nRF5 SDK locally.
With this the nRF5 SDK has been downloaded and ready to be used by the Seeger Embedded Studio.
2.Download Segger Embedded Studio(SES): Go to https://www.segger.com/ , and from the Downloads  menu choose Embedded Studio as shown in the screenshot below.

Download Segger Embedded Studio
In the Downloads page of the Embedded Studio, select Embedded Studio for ARM, then select the download that fits your operating system. SES is supported on Windows , macOS and Linux . ( The example here assumes a Windows machine)

Select Embedded Studio for ARM
3.Install Segger Embedded Studio(SES): Once the download is complete, run the installer file as an administrator and then follow the basic installation steps as shown in the screenshots below.

Run SES installer as admin

SES Install – Welcome Page

SES Install – License Agreement
Select your preferred installation path or leave default options as is

SES Install – Select Installation Path

SES Install – Files association
Make sure to install the J-Link device driver to be able to program the development boards.

SES Install – J-Link device driver

SES Install – Ready to install window
Installation will start. It will take few minutes to finish. Once the installation is done, the following window will pop up. Make sure that the option Start SEGGER Embedded Studio for ARM x.xxx is checked and click Next.

SES Install – Start SES window
Segger Embedded Studio will open with an example hello world program. Leave the program open as we will in the next step request the free of charge license for Nordic Semiconductor development boards and devices.
4.License Segger Embedded Studio(SES) for Nordic devices: SEGGER and Nordic Semiconductor have signed an agreement in late 2017 that entitles developers to use Segger Embedded Studio with Nordic nRF5x chips for both commercial and non-commercial uses free of charge.
a. In SES, right click on the Solution ‘Hello’ and select Build.

SES Build Project
b. A message indicating that no commercial license is found will pop up. Click onActivate Your Free License as shown in the screenshot below.

Activate your free license
c. The request license window will show up next. You need to enter your first, last name, company name and a valid email address as the license will be sent to you by email as text(Activation Key). The request license window will automatically link the license with the MAC address of your machine.

Request License Window
d. The activation confirmation message pops up indicating that the activation key has been sent to the specified email .

Enter Activation Key Window
e.You should now check your email for your Activation Key, which is a string of text that you need to copy and paste in the activation box and then click Install License.

Install License Window
The build process will start and now you have a licensed SES for Nordic Semiconductor devices.
5.Install nRF CPU Support Package: The nRF CPU Support Packages include all supporting files needed to create a complete new project from scratch. It include startup files, memory maps, CPU initialization, etc…. To install the Support Package for the Nordic Semiconductor devices in SES , select Tools > Package Manager…

Access Package Manager
The Check for update of Package Manager will show up, click Yes to download the latest packages .

Segger Package Manager – Check for Updates
After the download finishes, type Nordic in the search bar of the Package Manager.

Search for nRF CPU Support Package
Right click on nRF CPU Support Package , select Install Selected Packages and then click Next.

Install nRF CPU Support Package
Click Next in the Summary window. Then Click Finish when the installation is complete.

Support Package Installation Summary Window
6.Setup the CMSIS Configuration Wizard  in SES : The the CMSIS Configuration Wizard is a small utility developed in Java which simplifies the process of enabling and disabling modules in the SDK configuration file sdk_config.h. In order to use this utility with SES, you need to register it as an external tool . To do that, open SES, click on FileOpen Studio FolderExternal Tools Configuration .

External Tools Configuration

The tools.xml file file will open up in the editor. Copy the code below and paste it in the tools.xml exactly as shown in the screenshot below.
<item name=“Tool.CMSIS_Config_Wizard” wait=“no”>
<menu>&amp;CMSIS Configuration Wizard</menu>
<text>CMSIS Configuration Wizard</text>
<tip>Open a configuration file in CMSIS Configuration Wizard</tip>
<key>Ctrl+Y</key>
<match>*config*.h</match>
<message>CMSIS Config</message>
<commands>
java -jar &quot;$(CMSIS_CONFIG_TOOL)&quot; &quot;$(InputPath)&quot;
</commands>
</item>

CMSIS Configuration Wizard Integration in SES
Note: You need Java to be installed on your computer for this utility to work.
With this the SES is setup and ready to be used to develop firmware for the nRF5x Nordic Semiconductor devices and development boards. In the next paragraph we will start our first program in SES. The paragraph after that shows the steps needed to run the examples offered in the next labs.

Your first program

To test that all the steps we did previously are correct and that the Segger IDE is ready for action, we will run a very simple example “Blinky Example”  from the nRF5 SDK. The Blinky example toggles the boards LED using the  Board Support Package(BSP) which we will cover in depth in the later labs.
The Blinky Example shows how to configure the GPIO pins as outputs using the BSP library. These outputs can then be used to drive LEDs, as in this example.

Illustration of the Blinky Example workflow
When the application starts, some GPIO pins are configured as outputs to drive the LEDs. The application then loops while toggling the state of one of the LEDs every 500 milliseconds.
1.Browse to the example directory:  Using your files browser, head to <nRF5 SDK Installation Path>\nordic_semi\nRF5_SDK_15.0.0_a53641a\nRF5_SDK_15.0.0_a53641a\examples\peripheral\blinky

Blinky example directory
2.Select the folder which matches your board ID: In here, we are assuming that the development is done for the RF52840 DK development board which has the board ID (PCA10056) . Therefore , we will select the pca10056 folder. If you are using a different development board , you need to select a different folder . Refer to LabA-3for more information on the available boards in the nRF52 series  and their  board ID number.

Select the project folder for your development board
3.Select whether to run with/without a protocol stack or advanced feature(s): You will notice that inside almost all board folder examples there are two and sometimes more folders ; one is usually called blank which mean without a supporting interface protocol stack or advanced features . The other folder(s) are usually the name of the supporting protocol stack (s130 softdevice, etc.. )or advanced feature .  Since we are not using any protocol stack in this simple example , select blank

Select the blank directory
4.Select ses folder: Since we are using the Segger Embedded Studio(SES) , select the ses folder to open the SES project file.

Segger Embedded Studio Project Directory
5.Open the ses project file :  Double clink on the blinky_pca10056.emProject file to open the example in SES.

Open the blinky example

blinky example in SES
6.Compile and Build the project :  Click Build -> Build blinky_pca10056 or press F7

Build Project
The build process will internally invoke the compiler ,assembler and linker and produces the executable blinky_pca10056.hex which will be flashed on the board. It will take few seconds to finish.

Build Complete
7.Connect the board to the development machine : Connect a Micro-USB cable to your development board (Port J2) and the other end of the USB cable to your laptop/workstation , then switch on your development board (SW8)
8.Download executable on the board  :  To download the program executable on the board, select Target-> Download blinky_pca10056 . The program will run automatically on the board.

Program the board
You should notice that the board LEDs (LED1-LED4)  are toggling now every 500 milliseconds.
9.Modify the code (Optional ): Modify the code and increase the toggling delay from 500 to 2500 milliseconds, then save (Ctrl+S), build and download as done in the previous steps. You should now observe the LEDs are toggling at a much lower rate.

Modify the code

Running Embedded Centric labs and tutorials

In the next labs we will start diving into more hand-on examples and labs. The source code and the SES project files for these labs are available on a GitHub repository . To be able to run any of these labs, you need to do the steps below
1.Create a directory named embeddedcentric: This directory will hold the projects files of the next labs.


Create embeddedcentric directory

2.Clone the labs repository from GitHub: Use your favorite git tool to do that , or simply go to https://github.com/ama142/Nordic-BLE-Training and click on Clone or download ->  Download ZIP .

Clone Labs and Tutorials Repository
3.Extract the repository ZIP file: Once the download is complete,extract the content of the compressed file.

Extract Repository

4.Copy the content into the embeddedcentric folder:  Copy all files and directories inside the Nordic-BLE-Training-master folder and paste them in the  embeddedcentric  directory created recently . Do exactly as shown in the screenshot below , creating or removing directories might cause compilation errors as the search paths for the SDK libraries, drivers and include files might be modified inadvertently.

Copy files and directories

Paste in the embeddedcentric folder
5.Open the ses project file for the desired lab :  Double clink on the SES project file that you want to run( Example LabA6.1)

Run the desired lab( Example : LabA-6.1 )
6.Compile and Build the project :  Click Build -> Build name of the lab or press F7

Build Project GPIO
7.Connect the board to the development machine: Connect the USB cable to your development board (Port J2) and the other end of the USB cable to your laptop/workstation , then switch on your development board (SW8). The labs are built for the nRF52840-DK but can be easily modified to tailor any other nRF5x-based development boards or devices.
8.Download executable on the board  : To download the program executable on the board, select Target-> name of the lab . The program will run automatically on the board.




Questões: suporte@smartcore.com.br

Fonte: https://embeddedcentric.com/nrf5x-soc-overview/