NRF52840 Development

From HiveTool
Jump to: navigation, search

NRF52840 Development Code


To compile, flash and reset

~/Projects/nRF5_SDK_14.2.0_17b948a/examples/peripheral/spi/pca10056/blank/armgcc

$ make
$ nrfjprog -f NRF52 --program _build/nrf52840_xxaa.hex --sectorerase
$ nrfjprog -f NRF52 --reset


Using Segger's Linux command line tools

Open three terminals in the /opt/SEGGER/JLink_V622g directory.

JLink Debugger

1. start JLinkExe then issue the following commands:

connect
NRF52840_XXAA
S
<Enter>
$ ./JLinkExe
SEGGER J-Link Commander V6.22g (Compiled Jan 17 2018 16:40:37)
DLL version V6.22g, compiled Jan 17 2018 16:40:32  

Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 12 2018 16:05:20
Hardware version: V1.00
S/N: 683525645
VTref = 3.300V


Type "connect" to establish a target connection, '?' for help
J-Link>connect
Please specify device / core. <Default>: NRF52832_XXAA
Type '?' for selection dialog
Device>NRF52840_XXAA
Please specify target interface:
 J) JTAG (Default)
 S) SWD
TIF>S
Specify target interface speed [kHz]. <Default>: 4000 kHz
Speed>
Device "NRF52840_XXAA" selected.


Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Found SW-DP with ID 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>

Useful commands:

h halt
g go (start running)
r reset

Real Time Terminal Client

2. start RTT client

$ ./JLinkRTTClient

###RTT Client: ************************************************************ 
###RTT Client: *           SEGGER MICROCONTROLLER GmbH & Co KG            * 
###RTT Client: *   Solutions for real time microcontroller applications   * 
###RTT Client: ************************************************************ 
###RTT Client: *                                                          * 
###RTT Client: *  (c) 2012 - 2016  SEGGER Microcontroller GmbH & Co KG    * 
###RTT Client: *                                                          * 
###RTT Client: *     www.segger.com     Support: support@segger.com       * 
###RTT Client: *                                                          * 
###RTT Client: ************************************************************ 
###RTT Client: *                                                          * 
###RTT Client: * SEGGER J-Link RTT Client   Compiled Jan 17 2018 16:40:49 * 
###RTT Client: *                                                          * 
###RTT Client: ************************************************************ 

###RTT Client: -----------------------------------------------
###RTT Client: Connecting to J-Link RTT Server via localhost:19021  Connected.
###RTT Client: Connection lost. Going to reconnect.
###RTT Client: Connecting to J-Link RTT Server via localhost:19021 .............. Connected.
SEGGER J-Link V6.22g - Real time terminal output
J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 12 2018 16:05:20 V1.0, SN=683525645
Process: JLinkRemoteServer

output from printf commands will be sent here:

SPI Initialized.
reset_AD7124.
Reset failed:  0x00

Remote Server

To debug on the local machine, remote server does not seem to be necessary but here is how to start it:

start remote server

$ ./JLinkRemoteServer 

SEGGER J-Link Remote Server V6.22g
Compiled Jan 17 2018 16:40:43

'q' to quit '?' for help
Connected to J-Link with S/N 683525645
Waiting for client connection... 

This example uses tunneling to connect to the Segger website so you can remotely access the test device if it is behind a firewall.

$ ./JLinkRemoteServer UseTunnel

SEGGER J-Link Remote Server V6.22g
Compiled Jan 17 2018 16:40:43

'q' to quit '?' for help 

Connected to J-Link with S/N 683525645

Resolving host name (jlink.segger.com)... O.K.
Tunnel server IP: 185.162.249.2
Connecting to tunnel server... O.K.
Waiting for client connection...

Resources

Debugging Nordic nRF51822 using SEGGER Real Time Terminal (RTT)



IoT example using UDP

Setup a SoftDevice on the nFR52 using gcc

Running the makefile will erase any existing SoftDevice and program the appropriate SoftDevice for the example.

make flash_softdevice

Resources

https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/getting_started_softdevice.html#getting_started_sd https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/iot_sdk_app_udp.html

Nordic's IPv6 Stack based UDP Examples

https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/iot_sdk_user_guides_ipv6_address_creation.html

https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/iot_sdk_app_ipv6_stack_udp_client_server.html

Now trying the IoT Lightweight IP example Problem? There is no 10056 directory, only 10040 Good news. This is not a show stopper. "All of the PCA10040 examples will work with the nRF52840, you'll just have to do a little extra work to port it over."

In

/Projects/nRF5_SDK_14.2.0_17b948a/examples/iot/udp/lwip/client/pca10040/s132/armgcc
make flash_softdevice
nrfjprog -f NRF52 --program _build/nrf52832_xxaa.hex --sectorerase
nrfjprog -f NRF52 --reset


Resources

http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.2.0%2Fiot_ug_border_router.html&resultof=%22link-local%22%20%22ipv6%22%20

You should be familiar with the IPv6 addressing model as defined in specification RFC 4291 to understand the following content.



Set up the Pi as a Bluetooth-to-Ethernet router

Setup

Install the Router Advertisement Daemon on the Pi to distribute a global IPv6 prefix to the connected devices:

# apt-get install radvd

Create the file /etc/radvd.conf containing

# vi /etc/radvd.conf

interface bt0
{
   AdvSendAdvert on;
   prefix 2001:db8::/64
   {
       AdvOnLink off;
       AdvAutonomous on;
       AdvRouterAddr on;
   };
};

Set IPv6 forwarding (must be present).

# echo 1 > /proc/sys/net/ipv6/conf/all/forwarding

Run radvd daemon.

# service radvd restart

Check that the radvd daemon is running

# ps -ef |grep radvd
root     20328     1  0 11:35 ?        00:00:00 /usr/sbin/radvd --logmethod stderr_clean
root     20329 20328  0 11:35 ?        00:00:00 /usr/sbin/radvd --logmethod stderr_clean
root     20333  6708  0 11:36 pts/0    00:00:00 grep radvd

Observe if new IPv6 prefix is disseminating over bt0 interface. HOW?

Load the bluetooth_6lowpan module

# modprobe bluetooth_6lowpan

Check that it is loaded

# lsmod|grep blue

bluetooth_6lowpan      11549  0
6lowpan                18741  8 nhc_udp,nhc_routing,nhc_mobility,bluetooth_6lowpan,nhc_fragment,nhc_dest,nhc_hop,nhc_ipv6
bluetooth             365780  30 bluetooth_6lowpan,hci_uart,bnep,btbcm,rfcomm
rfkill                 20851  6 bluetooth,cfg80211


# echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable


# hciconfig
hci0:   Type: Primary  Bus: UART
        BD Address: B8:27:EB:62:9E:24  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING 
        RX bytes:843 acl:0 sco:0 events:60 errors:0
        TX bytes:4254 acl:0 sco:0 commands:60 errors:0
# hciconfig hci0 lestates
  Supported link layer states:
       YES Non-connectable Advertising State
       YES Scannable Advertising State
       YES Connectable Advertising State
       YES Directed Advertising State
       YES Passive Scanning State
       YES Active Scanning State
       YES Initiating State/Connection State in Master Role
       YES Connection State in the Slave Role
       YES Non-connectable Advertising State and Passive Scanning State combination
       YES Scannable Advertising State and Passive Scanning State combination
       YES Connectable Advertising State and Passive Scanning State combination
       YES Directed Advertising State and Passive Scanning State combination
       YES Non-connectable Advertising State and Active Scanning State combination
       YES Scannable Advertising State and Active Scanning State combination
       YES Connectable Advertising State and Active Scanning State combination
       YES Directed Advertising State and Active Scanning State combination
       YES Non-connectable Advertising State and Initiating State combination
       YES Scannable Advertising State and Initiating State combination
       YES Non-connectable Advertising State and Master Role combination
       YES Scannable Advertising State and Master Role combination
       YES Non-connectable Advertising State and Slave Role combination
       YES Scannable Advertising State and Slave Role combination
       YES Passive Scanning State and Initiating State combination
       YES Active Scanning State and Initiating State combination
       YES Passive Scanning State and Master Role combination
       YES Active Scanning State and Master Role combination
       YES Passive Scanning State and Slave Role combination
       YES Active Scanning State and Slave Role combination
       YES Initiating State and Master Role combination/Master Role and Master Role combination
# hcitool lescan
  LE Scan ...
  00:91:4C:20:FC:01 UDP_Client
  00:91:4C:20:FC:01 (unknown)

Resources

Distributing a global IPv6 prefix
Connecting the Nordic nRF52 chip to IPv6 networks via 6LoWPAN
Prepare the Linux router device by initializing the 6LoWPAN module.

Testing the UDP link

echo "connect <mac address from hcitool output> 1" > /sys/kernel/debug/bluetooth/6lowpan_control
echo "connect 00:91:4C:20:FC:01 1" > /sys/kernel/debug/bluetooth/6lowpan_control
# ifconfig
bt0: flags=4177<UP,POINTOPOINT,RUNNING,MULTICAST>  mtu 1280
       inet6 fe80::ba27:ebff:fe62:9e24  prefixlen 64  scopeid 0x20<link>
       unspec B8-27-EB-FF-FE-62-9E-24-00-00-00-00-00-00-00-00  txqueuelen 1  (UNSPEC)
       RX packets 1  bytes 28 (28.0 B)
       RX errors 0  dropped 2  overruns 0  frame 0
       TX packets 8  bytes 437 (437.0 B)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


https://devzone.nordicsemi.com/f/nordic-q-a/7258/iot-udp-client-can-not-communicate-with-server-by-using-global-ipv6

Ping the Bluetooth LE device from Raspberry Pi. Use the link-local IPv6 address of the nRF52 device derived from its MAC address since routing is not configured. Derive the link-local IPv6 address: fe80::291:4cff:fe20:fc01 from the MAC address: 00:91:4C:20:FC:01

# ping6 fe80::291:4cff:fe20:fc01 -I bt0
PING fe80::291:4cff:fe20:fc01(fe80::291:4cff:fe20:fc01) from fe80::ba27:ebff:fe62:9e24%bt0 bt0: 56 data bytes
64 bytes from fe80::291:4cff:fe20:fc01%bt0: icmp_seq=1 ttl=255 time=94.0 ms
64 bytes from fe80::291:4cff:fe20:fc01%bt0: icmp_seq=2 ttl=255 time=105 ms
                              ...
64 bytes from fe80::291:4cff:fe20:fc01%bt0: icmp_seq=23 ttl=255 time=136 ms
64 bytes from fe80::291:4cff:fe20:fc01%bt0: icmp_seq=24 ttl=255 time=79.9 ms
ping: sendmsg: No buffer space available
ping: sendmsg: No buffer space available
ping: sendmsg: No buffer space available


Change the /etc/radvd.conf file to:

interface bt0
{    
   AdvSendAdvert on;    
   prefix fd00:a::/64
   {        
       AdvOnLink off;        
       AdvAutonomous on;       
       AdvRouterAddr on;     
   };
};


Assign a global IPv6 address to the Pi

ifconfig eth0 add fd00:b::1/64

Assign a global IPv6 address to another pc (linux debian)

ip addr add fd00:b::2/64 dev wlp1s0


Resources

https://visualgdb.com/tutorials/arm/nrf51/6lowpan/

CoAP

Added Copper plug in to Firefox

https://addons.mozilla.org/en-US/firefox/addon/copper-270430/

Nordic's CoAP observable server example

http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.2.0%2Fiot_ug_border_router.html&resultof=%22link-local%22%20%22ipv6%22%20


https://www.hackster.io/deligence-technologies/dht22-data-from-arduino-to-raspberry-pi-using-mysql-and-coap-28d570
https://cs.iupui.edu/~xiaozhon/course_tutorials/Coap_tutorial_RPi.pdf
http://www.win.tue.nl/~lrahman/iot/files/RaspberryPi_2.pdf
https://www.slideshare.net/zdshelby/coap-tutorial


Routing IPv6 bt0 and wlan0

Added copper to Chrome on the Pi but copper still can't see the PDK although I can ping it using using the link local IP and the interface:

ping6 fe80::291:4cff:fe20:fc01 -I bt0


https://github.com/mkovatsc/Copper/issues/12

IPv6 addresses in the fe80::/10 range are link-local addresses. The same link-local address range appears on every interface for a host. This presents a problem for the host if you try to use that address range to communicate since the host cannot know which interface to use. In most OSes, you must add a zone (interface) ID to the end of a link-local address in order to use it. Some applications have a problem with this.

You should use a routable address. The global address range is 2000::/3 (2001:2::/48 for benchmarking or 2001:db8::/32 for documentation are good candidates for testing, but they can't be used on the Internet). The Unique Local address range is fc00::/7 (fd00::/8 in that range is available for local assignment with specific rules about pseudo random assignment), addresses this range can't be used on the Internet.

https://stackoverflow.com/questions/32455644/cant-send-coap-messages-with-firefox-copper-plugin-to-other-than-local-address

# ip -6 neigh add fe80::291:4cff:fe20:fc01 lladdr 2001:db8::1 dev bt0
 "2001" is invalid lladdr.
# ip -6 neigh add fe80::291:4cff:fe20:fc01 lladdr 2000:db8::1 dev bt0
 "2000" is invalid lladdr.
# ip -6 neigh add fe80::291:4cff:fe20:fc01 lladdr fc00::1 dev bt0
 "fc00" is invalid lladdr.


https://teamarin.net/2015/03/03/ipv6-brewed-coffee-bluetooth-smart/