# The Spark Core Firmware

**URL:** <https://community.particle.io/t/the-spark-core-firmware/532>\
**Category:** Getting Started\
**Created:** [November 19, 2013, 4:55pm UTC](https://community.particle.io/t/the-spark-core-firmware/532 "2013-11-19T16:55:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohit](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mohit/32/1971_2.png) [@mohit](https://community.particle.io/u/mohit)\
**Post date:** [November 19, 2013, 4:55pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/1 "2013-11-19T16:55:24Z")

</div>

# The Spark Core Firmware

This firmware depends on two other libraries: the [Spark Common Library](http://www.github.com/spark/core-common-lib) and the [Spark Communication Library](http://www.github.com/spark/core-communication-lib)

1. [Download and Install Dependencies](#1-download-and-install-dependencies)
2. [Download and Build Repositories](#2-download-and-build-repositories)
3. [Edit and Rebuild](#3-edit-and-rebuild)
4. [Flash It!](#4-flash-it)

## 1. Download and Install Dependencies

1. [GCC for ARM Cortex processors](#1-gcc-for-arm-cortex-processors)
2. [Make](#2-make)
3. [Device Firmware Upgrade Utilities](#3-device-firmware-upgrade-utilities)
4. [Zatig](#4-zatig) (for windows users only)
5. [Git](#5-git)

#### 1. GCC for ARM Cortex processors

The Spark Core uses an ARM Cortex M3 CPU based microcontroller. All of the code is built around the GNU GCC toolchain offered and maintained by ARM.

Download and install the latest version from: [https://launchpad.net/gcc-arm-embedded](https://launchpad.net/gcc-arm-embedded)

#### 2. Make

In order to turn your source code into binaries, you will need a tool called `make`. Windows users need to explicitly install `make` on their machines. Make sure you can use it from the terminal window.

Download and install the latest version from: [http://gnuwin32.sourceforge.net/packages/make.htm](http://gnuwin32.sourceforge.net/packages/make.htm)

#### 3. Device Firmware Upgrade Utilities

Install dfu-util. Mac users can install dfu-util with Homebrew, Linux users may find it in their package manager, and everyone can get it from [http://dfu-util.gnumonks.org/index.html](http://dfu-util.gnumonks.org/index.html)

#### 4. Zatig

In order for the Core to show up on the dfu list, you need to replace the USB driver with a utility called [Zadig](http://zadig.akeo.ie/). Here is a [tutorial](https://github.com/pbatard/libwdi/wiki/Zadig) on using it. This is only required for Windows users.

#### 5. Git

Download and install Git: [http://git-scm.com/](http://git-scm.com/)

## 2. Download and Build Repositories

The entire Spark Core firmware is organized into three repositories. The main firmware is located under _core-firmware_, while the supporting libraries are subdivided in to _core-common-lib_ and _core-communication-lib_.

#### How do we _download_ these repositories?

You can access all of the repositories via any git interface or download it directly from the website.

Make sure all of the following repositories are downloaded into the same folder. _For example (if all of the repositories are downloaded in a folder called Spark):_

```auto
D:\Spark\core-firmware
D:\Spark\core-common-lib
D:\Spark\core-communication-lib

```

_Method 1: Through the git command line interface._

Open up a terminal window, navigate to your destination directory and type the following commands:

(Make sure you have git installed on your machine!)

- `git clone https://github.com/spark/core-firmware.git`
- `git clone https://github.com/spark/core-common-lib.git`
- `git clone https://github.com/spark/core-communication-lib.git`

_Meathod 2: Download the zipped files directly from the Spark’s GitHub website_

- [core-firmware](https://github.com/spark/core-firmware/archive/master.zip)
- [core-common-lib](https://github.com/spark/core-common-lib/archive/master.zip)
- [core-communication-lib](https://github.com/spark/core-communication-lib/archive/master.zip)

#### How do we _build_ these repositories?

Make sure you have downloaded and installed all the required dependencies as mentioned [previously.](#1-download-and-install-dependencies)

Open up a terminal window, navigate to the build folder under core-firmware and type:

`make clean all`

This will build your main application and both the dependencies.

_For example:_ `D:\Spark\core-firmware\build [master]> make clean all`

### Navigating the code base

All of the repositories are sub divided into functional folders:

1. `/src` holds all the source code files
2. `/inc` holds all the header files
3. `/build` holds the make file and is also the destination for the compiled `.bin` and `.hex` files.

## 3. Edit and Rebuild

Now that you have your hands on the entire Spark Core firmware, its time to start hacking!

### What to edit and what not to edit?

The main user code sits in the application.cpp file under core-firmware/src/ folder. Unless you know what you are doing, refrain yourself from making changes to any other files.

After you are done editing the files, you can rebuild the repository by running the `make clean all` command. If you have made changes to the other two repositories or have updated them, make sure to run `make clean all` command to rebuild all of them.

## 4. Flash It!

Its now time to transfer your code to the Spark Core! You can always do this using the Over The Air update feature or, if you like wires, do it over the USB.

_Make sure you have dfu-util installed and available through the command line_

#### Steps:

1. Put you Core into the DFU mode by holding down the MODE button on the Core and then tapping on the RESET button once. Release the MODE button after you start to see the RGB LED flashing in yellow. This process is also described in greater detail here.

2. Open up a terminal window on your computer and type this command to find out if the Core indeed being detected correctly.

3. Now, navigate to the build folder in your core-firmware repository and use the following command to transfer the _.bin_ file into the Core.

```auto

   For example, this is how my terminal looks like:

```

D:\Spark\core-firmware\build [master]\> dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin

```auto
Upon successful transfer, the Core will automatically reset and start the running the program.

**Still having troubles?** Post your questions here!

### CREDITS AND ATTRIBUTIONS

The Spark application team: Zachary Crockett, Satish Nair, Zach Supalla, David Middlecamp and Mohit Bhoite.

The core-firmware uses the GNU GCC toolchain for ARM Cortex-M processors, ARM's CMSIS libraries, TI's CC3000 host driver libraries, STM32 standard peripheral libraries and Arduino's implementation of Wiring.

### LICENSE

Unless stated elsewhere, file headers or otherwise, all files herein are licensed under an LGPLv3 license. For more information, please read the LICENSE file.

### CONTRIBUTE

Want to contribute to the Spark Core project? Follow [this link]() to find out how.

### VERSION HISTORY

Latest Version: v1.0.0

```

---

<div class="post-metadata">

**Author:** ![zach](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zach/32/20714_2.png) [@zach](https://community.particle.io/u/zach)\
**Post date:** [November 19, 2013, 5:40pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/2 "2013-11-19T17:40:52Z")

</div>

This topic is now pinned. It will appear at the top of its category until it is either unpinned by a moderator, or the Clear Pin button is pressed.

---

<div class="post-metadata">

**Author:** ![fillibar](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@fillibar](https://community.particle.io/u/fillibar)\
**Post date:** [December 18, 2013, 12:24am UTC](https://community.particle.io/t/the-spark-core-firmware/532/3 "2013-12-18T00:24:47Z")

</div>

Anyone just copying and pasting the above lines from section 4, step 3, please be aware that “br” was added to the lines. The correct statement should be:  
dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin

---

<div class="post-metadata">

**Author:** ![mohit](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mohit/32/1971_2.png) [@mohit](https://community.particle.io/u/mohit)\
**Post date:** [December 19, 2013, 6:49pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/4 "2013-12-19T18:49:15Z")

</div>

@fillibar Thanks! I’ve removed that typo.

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [December 22, 2013, 1:29am UTC](https://community.particle.io/t/the-spark-core-firmware/532/5 "2013-12-22T01:29:15Z")

</div>

i’m having trouble getting this to build, i’ve installed binutils-arm-none-eabi, gcc-arm-none-eabi and libnewlib-arm-none-eabi as well as dfu-utils etc. (on debian jessie/sid) and proved the arm toolchain works:

```
$ arm-none-eabi-gcc -print-multi-lib
.;
thumb;@mthumb
fpu;@mfloat-abi=hard
armv6-m;@mthumb@march=armv6s-m
armv7-m;@mthumb@march=armv7-m
armv7e-m;@mthumb@march=armv7e-m
armv7-ar/thumb;@mthumb@march=armv7
armv7e-m/softfp;@mthumb@march=armv7e-m@mfloat-abi=softfp@mfpu=fpv4-sp-d16
armv7e-m/fpu;@mthumb@march=armv7e-m@mfloat-abi=hard@mfpu=fpv4-sp-d16
armv7-ar/thumb/softfp;@mthumb@march=armv7@mfloat-abi=softfp@mfpu=vfpv3-d16
armv7-ar/thumb/fpu;@mthumb@march=armv7@mfloat-abi=hard@mfpu=vfpv3-d16

```

but the makefile is not finding header files in /usr/include/ for example:

```
core-firmware/build$ makeBuilding core-common-lib
Building file: ../CC3000_Host_Driver/cc3000_common.c
Invoking: ARM GCC C Compiler
mkdir -p obj/CC3000_Host_Driver/
arm-none-eabi-gcc -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -I../CC3000_Host_Driver -I../SPARK_Firmware_Driver/inc -I../STM32F10x_StdPeriph_Driver/inc -I../STM32_USB-FS-Device_Driver/inc -I../CMSIS/Include -I../CMSIS/Device/ST/STM32F10x/Include -I. -ffunction-sections -Wall -fmessage-length=0 -MD -MP -MF obj/CC3000_Host_Driver/cc3000_common.o.d -DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -c -o obj/CC3000_Host_Driver/cc3000_common.o ../CC3000_Host_Driver/cc3000_common.c
In file included from ../CC3000_Host_Driver/cc3000_common.c:46:0:
../CC3000_Host_Driver/cc3000_common.h:41:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.
make[1]: *** [obj/CC3000_Host_Driver/cc3000_common.o] Error 1
make: *** [check_external_deps] Error 2

```

---

<div class="post-metadata">

**Author:** ![david\_s5](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@david\_s5](https://community.particle.io/u/david_s5)\
**Post date:** [January 10, 2014, 9:39pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/6 "2014-01-10T21:39:07Z")

</div>

> [@mohit](#):
>
> CONTRIBUTE
> 
> Want to contribute to the Spark Core project? Follow this link to find out how.

The link is stale [https://community.spark.io/clicks/track?url=&post\_id=1408&topic\_id=532](https://community.spark.io/clicks/track?url=&post_id=1408&topic_id=532)

How can I submit some patches?

---

<div class="post-metadata">

**Author:** ![zach](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zach/32/20714_2.png) [@zach](https://community.particle.io/u/zach)\
**Post date:** [January 10, 2014, 9:41pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/7 "2014-01-10T21:41:51Z")

</div>

> [@david\_s5](#):
>
> How can I submit some patches?

You can submit patches through pull requests on any of our public repositories:

> **[Particle](https://github.com/spark)**
>
> https://github.com/particle-iot. GitHub is where Particle builds software.

If you're not familiar with Github pull requests:

[https://help.github.com/articles/using-pull-requests](https://help.github.com/articles/using-pull-requests)

---

<div class="post-metadata">

**Author:** ![david\_s5](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@david\_s5](https://community.particle.io/u/david_s5)\
**Post date:** [January 10, 2014, 9:55pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/8 "2014-01-10T21:55:21Z")

</div>

Are you using the fork and pull or the shared repository and topic branches model?

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [January 15, 2014, 6:06pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/9 "2014-01-15T18:06:49Z")

</div>

btw, the links under “Download and Install dependencies” no longer work, e.g. link 4 Zatig goes to - [http://discourse/#4-zatig](http://discourse/#4-zatig)

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 16, 2014, 9:11pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/10 "2014-01-16T21:11:56Z")

</div>

> [@mohit](#):
>
> Make sure you have dfu-util installed and available through the command line

I've got the toolchain all setup, and can run `make` no problem from the build directory, but now it would be nice if I could get dfu-util working.

Easier said than done on Windows 7 32-bit! It's practically non-supported... I'm working my way through installing all of the tools again to build the sources for `dfu-util`

**[Dfu-util-windows - Openmoko](http://wiki.openmoko.org/wiki/Dfu-util-windows)**

If anyone has a better way, please let me know! Thanks.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [January 16, 2014, 9:17pm UTC](https://community.particle.io/t/the-spark-core-firmware/532/11 "2014-01-16T21:17:18Z")

</div>

Hey @BDub,

It looks like they have pre-compiled binaries for Windows on the site: [http://dfu-util.gnumonks.org/releases/dfu-util-0.7-binaries.7z](http://dfu-util.gnumonks.org/releases/dfu-util-0.7-binaries.7z) – open it up with 7-zip, and the win32-mingw32 version worked for me (at least on win7-64 bit)

Thanks!  
David

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 17, 2014, 12:54am UTC](https://community.particle.io/t/the-spark-core-firmware/532/12 "2014-01-17T00:54:53Z")

</div>

Awexome! Thanks Dave 🙂 I put the binaries in my PATH and they work. Just had to install the Zatig WinUSB driver for the CORE DFU device that pops up with you put the :spark: Core into DFU mode (Flashing Yellow). Built the master branch and I’ve got Tinker loaded as expected.

Earlier I had replaced the SPARK CORE WITH WIFI device that is present when the Core has booted, with the Zatig WinUSB driver. So I’m guessing I should put the other driver back that creates the USB to Serial Bridge.

One problem I am now having is when I try to rebuild the project again by typing `make` in the core-firmware\build directory, I get this error:  
`obj/src/application.o.d:1: *** multiple target patterns. Stop.`

Also can anyone comment on about how long it takes to compile the sources this way? I will time mine again when I get it working, but it seems to take quite a while longer than the web IDE.

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [January 17, 2014, 1:06am UTC](https://community.particle.io/t/the-spark-core-firmware/532/13 "2014-01-17T01:06:11Z")

</div>

The first compile takes a while because it’s clean (from scratch) compile. After that, only files that have changed are compiled.

I didn’t have to remove the Zadig driver and still got usb comms from the core.

---

<div class="post-metadata">

**Author:** ![Soulhuntre](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/soulhuntre/32/2106_2.png) [@Soulhuntre](https://community.particle.io/u/Soulhuntre)\
**Post date:** [January 17, 2014, 1:48am UTC](https://community.particle.io/t/the-spark-core-firmware/532/14 "2014-01-17T01:48:32Z")

</div>

So at this point, what is the most supported / easiest environment for this? I can run Linux in a virtual PC if needed as it looks like Windows is just not really a supported env here.  
Sill - I winder how long it will be, or if the road map even includes, parity support in the “official” Arduino IDE?

I ask because frankly my dev box is to important to my day to day to destabilize byhacking in random bits and chunks from different locations, unofficial links and so on. So I am putting it into a VC anyway - so is Linux a more directly supported ENV?

Ken

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 17, 2014, 3:29am UTC](https://community.particle.io/t/the-spark-core-firmware/532/15 "2014-01-17T03:29:22Z")

</div>

That’s kind of what I was thinking too based on the bounty to rework the makefile. Problem is I haven’t been able to compile a second time yet. I wonder if installing the MinGW environment has done something? I did that to try to compile dfu-util sources… well I’ll try to uninstall and see what changes.

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 17, 2014, 3:47am UTC](https://community.particle.io/t/the-spark-core-firmware/532/16 "2014-01-17T03:47:19Z")

</div>

I decided to google the error first, and found the GNU make manual says:

```
‘missing target pattern. Stop.’
‘multiple target patterns. Stop.’
‘target pattern contains no `%'. Stop.’
‘mixed implicit and static pattern rules. Stop.’
These are generated for malformed static pattern rules. The first means there's no pattern in the target section of the rule; the second means there are multiple patterns in the target section; the third means the target doesn't contain a pattern character (%); and the fourth means that all three parts of the static pattern rule contain pattern characters (%)–only the first two parts should. If you see these errors and you aren't trying to create a static pattern rule, check the value of any variables in your target and prerequisite lists to be sure they do not contain colons. See Syntax of Static Pattern Rules. 

```

Here’s the files that it’s complaining about… these times are all from when I created the first build successfully.  
 ![](https://sea2.discourse-cdn.com/flex026/uploads/particle/287/750a84377d398067.png)

And the first part of the application.o.d file:  
 ![](https://sea2.discourse-cdn.com/flex026/uploads/particle/288/c03f56794dacf749.png)

I doubt this is MinGW related… so I think I’ll leave it installed.

**EDIT:** Ok, If I delete all 3 of the `obj` directories, it will build again… but I’m guessing that shouldn’t be necessary? 😉

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 17, 2014, 4:26am UTC](https://community.particle.io/t/the-spark-core-firmware/532/17 "2014-01-17T04:26:40Z")

</div>

Allllrighty then… .I think this might be the issue but still don’t know enough to solve it.

![](https://sea2.discourse-cdn.com/flex026/uploads/particle/289/2ec109d67394a268.png)

I read that Make interprets the colon as defining a target pattern, and since this is technically all one line it thinks there are multiple target patterns.

Two sources claim the `c:\` windows path should be generated in a more relative path manner so Make doesn’t choke…  
[http://stackoverflow.com/questions/14514086/make-multiple-target-patterns-stop](http://stackoverflow.com/questions/14514086/make-multiple-target-patterns-stop)  
[http://cygwin.com/ml/cygwin/2009-04/msg00006.html](http://cygwin.com/ml/cygwin/2009-04/msg00006.html)

But I have no idea how to do that…

@zachary @mattande any ideas?

EDIT: for now I just made two batch files…

**M.BAT**

```
@ECHO OFF
ECHO BUILDING PROJECT!!!
rmdir /S /Q obj
rmdir /S /Q ..\..\core-common-lib\build\obj
rmdir /S /Q ..\..\core-communication-lib\build\obj
make

```

and

**P.BAT**

```
@ECHO OFF
ECHO PROGRAMMING!!!
dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin
```

---

<div class="post-metadata">

**Author:** ![Soulhuntre](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/soulhuntre/32/2106_2.png) [@Soulhuntre](https://community.particle.io/u/Soulhuntre)\
**Post date:** [January 17, 2014, 7:27am UTC](https://community.particle.io/t/the-spark-core-firmware/532/18 "2014-01-17T07:27:34Z")

</div>

@BDub - I’ll fire up a linux VM and get it running, then a windows one and work in this some - Makefiles and so on are within my sphere (as opposed to this hardware stuff 🙂 ) so I can actually be useful there!

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 17, 2014, 8:03am UTC](https://community.particle.io/t/the-spark-core-firmware/532/19 "2014-01-17T08:03:02Z")

</div>

Thanks @Soulhuntre! I’ve been searching and reading, trying to figure this out…

I renamed the paths in the application.o.d file like this manually:  
 ![](https://sea2.discourse-cdn.com/flex026/uploads/particle/290/4903e3185162f89a.png)

And now the error is in the next dependency file. Here’s a before and after…  
[![](https://i.imgur.com/sKuXMUg.png) ](https://i.imgur.com/sKuXMUg.png)

So if possible to make the GCC toolpath relative somehow I think that could be the best solution, or if “/cygdrive/c/” is valid for everyone (probably not) do some kind of renaming thing on the dependency file. I dunno, I’m not an expert here …

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [January 17, 2014, 8:06am UTC](https://community.particle.io/t/the-spark-core-firmware/532/20 "2014-01-17T08:06:26Z")

</div>

Windows (MinGW) is supported - I’ve been compiling on windows. There are some “gotchas” in the makefile that mean it doesn’t work fluidly out the box, but I hope to submit patches to fix these issues.

[Next page](https://community.particle.io/t/the-spark-core-firmware/532.md?page=2)
