How to install the spark toolchain in Ubuntu 14.04


#1

I just upgraded to Ubuntu 14.04 and had to set my spark environment back up from scratch. I thought I’d document the process and share it with anyone else attempting to get it running.

Spark toolchain setup for Ubuntu 14.04 (Trusty)

Make sure you don’t have the wrong node package installed (node is for Amateur Packet Radio, nodejs is the one we want and we’ll install that below). Also remove the modemmanager package if you’re not using it. It likes to send junk AT commands to the spark core when you first plug it in and takes over the serial port for the first 45 seconds or so. If you’ve already installed the gcc-arm-none-eabi package, remove it now as well. It doesn’t work and will conflict with our installation of gcc-arm-none-eabi below.

sudo apt-get remove node modemmanager gcc-arm-none-eabi

Let’s get to it by installing nodejs and some other dependencies!

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install python-software-properties python g++ make nodejs
sudo apt-get install build-essential libusb-1.0-0-dev

Download and install the gcc-arm-none-eabi package:

mkdir -p ~/bin/gcc-arm-embedded && cd "$_"
wget https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q2-update/+download/gcc-arm-none-eabi-4_8-2014q2-20140609-linux.tar.bz2
tar xjf gcc-arm-none-eabi-*-linux.tar.bz2
export PATH=$PATH:$HOME/bin/gcc-arm-embedded/gcc-arm-none-eabi-4_8-2014q2/bin
echo 'export PATH=$PATH:$HOME/bin/gcc-arm-embedded/gcc-arm-none-eabi-4_8-2014q2/bin' >> ~/.bash_profile

At this point, if you run:

which arm-none-eabi-gcc

You should see something like:

/home/thunter/bin/gcc-arm-embedded/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-gcc

If you don’t, check that you setup your shell’s $PATH environment variable correctly.

Install the spark command line tools

sudo npm install -g spark-cli
spark cloud login

mkdir spark
cd spark
git clone git@github.com:spark/core-communication-lib.git
git clone git@github.com:spark/core-firmware.git
git clone git@github.com:spark/core-common-lib.git
git clone git://gitorious.org/dfu-util/dfu-util.git

Now compile and install dfu-util

cd dfu-util
sudo apt-get build-dep dfu-util
./autogen.sh
./configure
make
sudo make install
cd ..

Now plug your spark core in via usb. Hold down the mode button and press and release the reset button until the core starts flashing yellow, then release the mode button. Then run:

sudo dfu-util -l

You should see some lines like the following:

Found DFU: [1d50:607f] ver=0200, devnum=2, cfg=1, intf=0, alt=1, name="@SPI Flash : SST25x/0x00000000/512*04Kg", serial="8D91517D5055"
Found DFU: [1d50:607f] ver=0200, devnum=2, cfg=1, intf=0, alt=0, name="@Internal Flash  /0x08000000/20*001Ka,108*001Kg", serial="8D91517D5055"

The file core-firmware/src/application.cpp is the default tinker app. You can change it to your own code.
Now you can compile the spark firmware.

cd core-firmware/build
make

Make sure your spark core is in yellow-flashing mode (hold down the mode button and press and release the reset button until the core starts flashing yellow, then release the mode button) and then run the following to flash your firmware!

sudo dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin

Updated 07/04/2014: No longer installed gcc-arm-none-eabi from packages (too much headache because of conflicts). Install from the tarball.

Updated 07/16/2014: Instructions to remove the node Amateur Radio Package if installed. It conflicts with nodejs. Minor edits.


Failed connecting to WiFi
Problem with flashing firmware[Solved]
Documentation Needs
#2

As the nodejs version in 14.04 is 0.10.25 there may be no need to use the Chris PPA as advised above. Not tested. Anybody?


#3

It very well may not be necessary. I haven’t tested it myself. At the rate ubuntu releases updates for nodejs compared to the PPA I listed above, I’ve found that it’s generally good practice to just go ahead and install node from the PPA, which is why I included it in the instructions. It’s simply preventative for any possible problems that may come up. However, if someone wants to try to install the package from ubuntu’s repos, I would love to hear the results.


#4

@Hypnopompia - can you explain what you mean by this step :

Edit core-firmware/src/application.cpp and change it to your own code.

what exactly am I supposed to edit in that file ?


#5

Hi @Anool_WyoLum

When you set up the local build environment it comes preconfigured to build the “Tinker” app for your core and the source for “Tinker” is in the file application.cpp. You should replace the contents of this file with your code when you want to build your app.


#6

okay, got it. So I can just leave the Tinker app as it is for the time being until I am able to connect and talk to my Spark !


#7

@Hypnopompia, I tried to replicate what you’ve nicely documented here. I’m having a little trouble with installing gcc-arm-none-eabi.
Fundamentally, it is because 4-8-2014q1-0trusty8 isn’t accessible.
Instead, I tried sudo apt-get install build-essential gcc-arm-none-eabi=4-8-2014q2-0trusty10 that gives me errors while installing.
However, after adding the repo at first, I did the update and sudo apt-get install gcc-arm-none-eabi. Right now, I’m unable to compile the Tinker code because of this (most likely).

How can I install this?


#8

@LIGHThouse after installing the repo, you need to install the new repo’s version of the gcc-arm package:

 sudo apt-get install gcc-arm-none-eabi=4-8-2014q1-0trusty8

So you’ll probably want to remove the one you installed (ubuntu’s version) and install the one from the terry.guo repo:

sudo apt-get remove gcc-arm-none-eabi
sudo apt-get install gcc-arm-none-eabi=4-8-2014q1-0trusty8

The other solution (which I will probably change the how-to to reflect would be to just download the gcc-arm package and run as-is without installing it globally. Then there are no conflicts with the ubuntu packages.

Update: @LIGHThouse I just updated the instructions to install the arm-gcc package from the tarball file. use that instead of trying to install from the apt packages. It’s less headache in the long run.


#9

@Hypnopompia, That helped a lot!

Could you help me fix a linker error (I think):

make: arm-none-eabi-g++: Command not found
make: *** [core-firmware.elf] Error 127

I try which arm-none-eabi-g++

and I get /home/virtual-ubuntu1404-ani/bin/gcc-arm-embedded/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-g++

I later tried sudo make clean all
which gave me this:

make[1]: arm-none-eabi-gcc: Command not found
make[1]: *** [obj/CC3000_Host_Driver/cc3000_common.o] Error 127
make: *** [check_external_deps] Error 2

although which arm-none-eabi-gcc gives me the expected result.

Thanks!


#10

@LIGHThouse I think the problem is that you’re running the make command as root (you’re using sudo) and for root, the path to arm-none-eabi-gcc isn’t setup correctly. Try running make clean all without the sudo and see what happens. If you have files in that build directory made by root, you’ll probably run into permission problems, so you’ll have to manually clean those out or chown all of them to your user.


#11

@Hypnopompia, I’d tried using sudo because I saw this everytime:
arm-none-eabi-g++: error: nano.specs: No such file or directory make: *** [core-firmware.elf] Error 1

I thought it should have been gcc instead of g++ and gave sudo a try.
I was puzzled because I got random errors every different time, which were, however, one of the 3 or 4 errors I listed in this thread.

It looks like this nano.specs is pretty common elsewhere (I’m still debugging this). I hope I can resolve it soon.

Thanks!


#12

Hi @LIGHThouse,

Sorry about the slow reply, if you haven’t fixed this yet, make sure you update your gcc toolchain ( https://launchpad.net/gcc-arm-embedded/+download ). The nano.specs is in the 4.8 version :smile:

Thanks!
David


#13

Thanks @Dave! One of my buddies had helped me complete it recently :smile:!


#14

I was able to make this work in Linux Mint 16.
The main problem I had was this error :

arm-none-eabi-gcc
bash: /home/david/bin/gcc-arm-embedded/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-gcc: No such file or directory

Turns out it was because I have 64-bit linux, so I installed the ia32-libs metapackage and then it worked.


#15

Hi @Hypnopompia

Were you able to get Serial.println to work in Ubuntu 14.04 ?
I have tried with :

sudo screen /dev/usb 9600

but I get the error :
Cannot exec ‘/dev/usb’: Permission denied
[screen is terminating]


Making serial monitor work for ubuntu
#16

@Rockvole, Try this:

sudo screen /dev/ttyACM0 9600

#17

Thank-you @Hypnopompia - that worked.

I needed some help from this page also to get it to work:
http://forums.linuxmint.com/viewtopic.php?f=90&t=135914


#18

I had a problem trying to install the spark-cli on Ubuntu Server 14.04. I’m going to give my solution just in case anyone else encounters the same problem.

Problem: node-pre-gyp uses node instead of nodejs, so the following package didn’t install

> serialport@1.4.5 install /usr/local/lib/node_modules/spark-cli/node_modules/serialport
> node-pre-gyp install --fallback-to-build

/usr/bin/env: node: No such file or directory
npm info serialport@1.4.5 Failed to exec install script
npm info /usr/local/lib/node_modules/spark-cli/node_modules/serialport unbuild
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

This occurred even after I had removed node

The fix is to use a symbolic link:

sudo ln -s /usr/bin/nodejs /usr/bin/node

After creating the symlink, installing the spark-cli succeeded.


Problem with Update the Core Firmware in Ubuntu linux
#19

Hey guys I am stuck on this part. I am using Linux Mint.

 cd dfu-util
sudo apt-get build-dep dfu-util
./autogen.sh
./configure
make
sudo make install
cd ..

When I run the cmd. sudo apt-get build-dep dfu-util I got an error that says

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to find a source package for dfu-util

I am having issues to install this utility even on windows thats why I tried to do it on Linux, any help is appreciated
Thanks


#20

Rather than all that initial faffing with tarballs and PATHs to make sure you’re using the right version of gcc-arm-none-eabi, you can instead just

$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-add-repository ppa:terry.guo/gcc-arm-embedded
$ sudo tee /etc/apt/preferences.d/terry_guo-gcc-arm-embedded # copypasta the next 3 lines, then press Ctrl-D
Package: *
Pin: release o=LP-PPA-terry.guo-gcc-arm-embedded
Pin-Priority: 1000
$ sudo apt-get update
$ sudo apt-get install nodejs gcc-arm-none-eabi

Then continue on from ‘Install the spark command line tools’.

Also, instead of cloning dfu-utils and building it from source, I was able to install version 0.8 (effectively as recent as you’re going to get from the git repository) by selecting the most recent build for my architecture, downloading the .deb at the bottom of the page and:

$ sudo dpkg -i dfu-util_0.8-1_amd64.deb

Since it’s such a simple package it doesn’t depend on anything that’s not already in Trusty.