Monday, December 09, 2013

Setting up Eclipse under Mac OS X for the Nordic Semiconductor nRF51822

I'm developing a smartwatch with the Nordic Semiconductor nRF51822 IC (a really nice chip!).

The development environment that comes with Nordic's Development Kit is based on Keil (a very expensive commercial IDE), which has a limit of 16K code to use in circuit debugging. Therefore I want to set up a development environment on my Mac using free and open source tools. Nordic has an application note, nAN-29, which describes doing this for Windows.

I will try installing the GCC ARM Embedded, because according to this post on the Nordic forums (quote):

  1. a new gcc toolchain based on gcc ARM embedded instead of Codesourcery (As Nordic has chosen to support it and not the other)
  2. Codesourcery on Mac OSX is only a great trouble, as this toolchain lacks of S3 Mentor libs) 
  3. Nordic has released new linker scripts for gcc ARM embedded.
I'm going to try to use Eclipse rather than XCode, so that the project won't depend on OS X.

I downloaded the "Mac Installation Tarball", which didn't contain an installer. I'm not sure where to put it, so for now I'll put it in my Eclipse workspaces folder.

I created a symbolic link (not an alias) called "gcc-arm-none-eabi" so I wouldn't have to change paths in the project if I update the cross compiler version.

I installed Eclipse according to nAN-29. When I build, it tries and fails to use "C:/Program Files/GNU Tools ARM Embedded/4.7 2013q1/bin/arm-none-eabi-gcc" to compile the project. I need to find where to change this path.  nrf51_sdk_v5_0_0_34603/nrf51822/Source/templates/gcc/Makefile.common uses a GNU_INSTALL_ROOT environment variable, I wonder where it is set.

The file nrf51_sdk_v5_0_0_34603/nrf51822/Source/templates/gcc/Makefile.common references Makefile.posix, which does not seem to exist.

GNU_INSTALL_ROOT is set in Makefile.windows, but I don't see why Makefile.windows is used. I'll try to make a Makefile.posix and see if it works better.

I made a Makefile.posix as follows:
GNU_INSTALL_ROOT := /Users/erlandlewin/Eclipse-workspaces/gcc-arm-none-eabiGNU_VERSION := 4.7.4
GNU_PREFIX := arm-none-eabi
 I had to edit the Makefile.common as follows:
#ifeq ($(OS),Windows_NT)
#include $(TEMPLATE_PATH)Makefile.windows
#else
include $(TEMPLATE_PATH)Makefile.posix
#endif
I can now build the project in Eclipse and from the command line!

I will download the J-Link software for Mac from here.

 Followed the instructions in nAN-29 to set up the debugging. In the "GDB command" field of the Debug Configurations dialog, I used the Browse button to find the arm-none-eabi-gdb binary. This way I don't have to set up any paths.

I start the gdb server using the terminal from the /Application/SEGGER directory, using the following command line:

./JLinkGDBServer -if SWD -device nRF51822
(Thanks to info from Christopher Mason)

Woohoo! I can now run debug the ble_app_hrs project from Eclipse via the JLinkGDBServer!


Wednesday, August 14, 2013

Making a Raspberry Pi 3G Bridge / Hotspot

This post documents making a 3G Internet bridge / hotspot from a Raspberry Pi, a 3G modem, and a separate WiFi access point.

The purpose was to create an Internet connected WiFi-network at my parents' summer cottage.

I want to cover a fairly large area of the property and house. I might want several WiFi access points and control their placement and the placement of the 3G modem, therefore I did not want an integrated WiFi hub such as a Dovado 3/4G router (SEK 799 / €92 at Kjell & Co.

I'm using:
  • a Raspberry Pi model B (SEK 298 / €34 at Webhallen)
  • the Adafruit Occidentalis v 0.2 distribution (since I'd used it before)
  • an unlocked Huawei HiLink E353, originally tied to Swedish operator Tre, I think (SEK 179 / €21 at Swedish auction site Tradera)
  • Connected a WiFi access point I had earlier to the Raspberry Pi.
  • My plan is to use Telenor Bredband Kontant (SEK 400 / €46 for 6 months and 10 GB data). I did my tests by borrowing the SIM card from my iPad.
  • I think I also need a powered USB hub for the 3G modem, will experiment later to see if a more powerful supply for the Raspberry Pi might remove the need for this.
  • Normally, I used ssh over a network connection to the Raspberry Pi, but when setting up the network bridge, I used a regular monitor (with an HDMI - DVI cable) and a USB keyboard, because the network interfaces must be shut down to set up the bridge.
Installed Occidentalis on the SD card.

Connected RasPi to MacBook with Ethernet cable. Internet sharing from WiFi to Ethernet on MacBook, to give RasPi Internet access. Logged in with ssh on Raspberry Pi.

Booted the RasPi.
Did:
sudo apt-get update
sudo apt-get upgrade
(takes a long time)

usb_modeswitch is required to get 3G modem to work:
apt-get install usb-modeswitch
Install UPnP client, will be needed to open ports in the modem:
apt-get install miniupnpc
Remove and re-insert dongle?

Reboot:
sudo shutdown -r now
On startup, stick should be available as eth1, check with ifconfig. If it doesn't it might be that the modem needs to be in a powered USB hub.

edit /etc/network/interfaces

Add:
iface eth1 inet dhcp 
check with:
sudo ifup eth1
Great. Try to ssh into RasPi over public internet. How to get public IP?
wget http://ipecho.net/plain -O - -q ; echo
Got 90.129.85.242

Can't ssh to it (connection refused). After some research found out that in order to open port forwarding on the 3G modem, one must use UPnP.

Open port 22 to allow ssh connections from the Internet to the Raspberry Pi.
// to receive ssh
upnpc -r 22 TCP
Set up bridge (for more information, see documentation). This entails shutting down both network interfaces, so you will need to be connected to the Pi with keyboard & monitor, or with a third network connection:

I think I shut down eth0 and eth1 first:
ifdown eth0
ifdown eth1 
Then set up the bridge:
brctl addbr br0
brctl addif eth0
brctl addif eth1
dhclient br0
It works! Can access Internet via Dongle from WiFi. 

Modified my WiFi access point to have IP 192.168.1.2

Now set configuration in /etc/network/intefaces:
auto lo br0
iface lo inet loopback 

# Ethernet
iface eth0 inet manual

# Huawei 3G dongle
iface eth1 inet manual

allow-hotplug eth1

# Bridge
iface br0 inet dhcp
  bridge_ports eth0 eth1
  bridge_fd 0 # no forwarding delay

Configured DynDNS for my DNS provider Loopia according to these instructions. 

Works very nicely!

Did you find this useful? Please Flattr me!