Local built application and library usage

Hi,
I am just trying to get my first application compiled locally. I can make the firmware and flash it locally, so I think my environment is setup correctly.

But how can I create my own application instead of the default tinker application. It seems you can create subfolders under the .\core-firmware\applications directory. But how do I tell the makefiles to use that new directory instead of tinker? And where can I put libraries i want to use?

I am not so good in understanding makefiles, but I saw somethin like this there:

# determine where user sources are, relative to project root
ifdef APP
USRSRC = applications/$(APP)/

But how can I set APP. My favorite method would be to create a makefile for every application I have and then call make in my applications directory. But how to do that?

I tried to do it with the “Spark-ReadWrite.cpp” demo app for the “sd-card-library”. It works in the Web IDE but I cannot compile it locally.

Thank you for your help

Thorsten

application.cpp is the file you edit to create your own app, the code in there when you download the firmware is the tinker code. I just rename each app… the one i want to build i quickly rename to application.cpp :smile:

Libraries are a little trickier! I don’t know if the way i do it is right but it works for me…

i add a folder to the core-firmware/libraries folder and create 2 folders in it called inc and src. the inc folder holds the .h file and the src holds the .cpp file and the build.mk file. structured like this

core-firmware
    libraries
        digole
            inc
                digole.h
            src
                digole.cpp
                build.mk

i create my own build.mk file using this as a template (just change digole to you library name)

# This file is a makefile included from the top level makefile which
# defines the sources built for the target.

# Define the prefix to this directory. 
# Note: The name must be unique within this build and should be
#       based on the root of the project
TARGET_DIGOLE_PATH = libraries/digole
TARGET_DIGOLE_SRC_PATH = $(TARGET_DIGOLE_PATH)/src

# Add include paths.
INCLUDE_DIRS += $(TARGET_DIGOLE_PATH)/inc

# C source files included in this build.
CSRC +=

# C++ source files included in this build.
CPPSRC += $(TARGET_DIGOLE_SRC_PATH)/DigoleSerialDisp.cpp

# ASM source files included in this build.
ASRC +=

then in the makefile (in the core-firmware/build folder) i add a line under the

# Include directories for optional "libraries" (eg. Serial2.h)

the line to add:

INCLUDE_DIRS += $(LIB_CORE_LIBRARIES_PATH)/digole

to make your life a bit easier: just create a folder in your core-firmware/applications named projectABC and place your application.cpp in it - now, from within core-firmware/build start the build process with make APP=projectABC and you’ll be able to find the compiled binary in core-firmware/build/applications/projectABC/projectABC.bin - much easier than renaming and taking care of having the correct application.cpp in core-firmware/src/ :smiley:

Happy compiling! :sunflower:

Yes, that works. Thank you. I just before reading your comment added APP=blah to the top of the makefile. Works also but I don’t like modifying the original makefile each time I do a new application. So your version is much nicer.

How can I call the original makefile from within my own project’s makefile. I tried something like this:

# Application name
APP=flasher

all:
	include ../../build/makefile

but it doesn’t work:

D:\Entwickl\Spark\core-firmware\applications\flasher>make
include ../../build/makefile
process_begin: CreateProcess(NULL, include ../../build/makefile, ...) failed.
make (e=2): System cannot find the file specified.
make: *** [all] Error 2

If such a thing would work, I think I can add libraries to my makefile instead of editing the main makefile.

BTW: I noticed that the firmware includes all the builtin libraries like I2C, SPI, … even if I do not use them. Is there a way to disable some feature to get the code smaller?

Ok, now I managed to include the main makefile:

# Application name
APP=flasher
all elf bin hex size:
	@$(MAKE) -C ../../build APP=$(APP) $@
program:
	@$(MAKE) -C ../../build APP=$(APP) program-dfu

Now I only need the library stuff. It seems I can simply throw a library into the “core-firmware\src” directory. But I don’t like that, because the I don’t know which files belong to which library. Better would be putting them in a subdirectory in the “libraries” path like

core-firmware\libraries\my_library

@Hootie81, I tried this and the compiler could not find the first .h file included in the user app. I checked the syntax and the spelling and still no go. The inc/src sub-directories are not being traversed by the compiler. To fix this, the makefile line for each added library should be (note the added “/inc/”):

INCLUDE_DIRS += $(LIB_CORE_LIBRARIES_PATH)/digole/inc/

Also, the build.mk files will never be found because the makefile specifies to look ONLY in the “src” directory. So the line that searches for build.mk files in the path should be:

# Find all build.mk makefiles in each source directory in the src tree.
SRC_MAKEFILES := $(call rwildcard,$(SRC_PATH),build.mk)

instead of:

# Find all build.mk makefiles in each source directory in the src tree.
SRC_MAKEFILES := $(call rwildcard,$(SRC_PATH)src,build.mk)

How did you get your stuff to compile? :smile:

Hmmm i dont know but it works for me! i originally got the info off the forum somewhere… i think it was the page with the netbeans video. but that above is a cut and paste from my currently working setup… I’ll look into it a bit more when i get some time. i do remember having a hard time making it work!

Any more on this topic? Any official word on how to add libraries locally in an official way, like the applications simply create a new folder in application/ folder?

Would be nice if we could just drop new folder with inc/src structure in libraries/ folder and it would just work.

I don’t think it will “just work” without doing anything.

As far as i know, using feature/hal branch, you can add the library in the main/inc or something

@BDub should have some idea!

editted 10/17/2014 I forgot some stuff.

@Hootie81 and @peekay123 thanks for the posts and work. Below is how I implemented local libraries. A big goal for me was to be able to import (clone) the libraries right from the github repositories if they are already in the correct format for a spark library. So this whole process assume the library is compliant with the spark library format. This is really all copied from bootie and peekay (thanks again).

First navigate to the libraries folder in the "core_firmware folder. Then clone the library you want to use.

//clone library into "libraries" directory I was getting the adafruit
//DHT22 library
$ pwd
<your path>/spark/core-firmware/libraries
$ git clone https://github.com/russgrue/Adafruit_DHT_Library.git

Navigate to the “firmware” folder

$ cd Adafruit_DHT_Library/firmware

Now add the build.mk file in the “firmware” folder

$ touch build.mk

edit the build.mk like the following. Anywhere you need stuff like “ADAFRUIT” OR “ADAFRUIT_DHT” you need to change it for your library.

# This file is a makefile included from the top level makefile which
# defines the sources built for the target.

# Define the prefix to this directory. 
# Note: The name must be unique within this build and should be
#       based on the root of the project
TARGET_ADAFRUIT_DHT_PATH = libraries/Adafruit_DHT_Library/firmware
TARGET_ADAFRRUIT_DHT_SRC_PATH = $(TARGET_ADAFRUIT_DHT_PATH)

# Add include paths.
INCLUDE_DIRS += $(TARGET_ADAFRUIT_DHT_PATH)

# C source files included in this build.
CSRC +=

# C++ source files included in this build.
CPPSRC += $(TARGET_ADAFRRUIT_DHT_SRC_PATH)/Adafruit_DHT.cpp

# ASM source files included in this build.
ASRC +=

Now your almost done.
Note my local source code here <your path>/spark/core-firmware/applications/<project name>/application.cpp
WAS (in the web ide)

// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

CHANGE TO (in the local code).

#include "Adafruit_DHT.h"

modify the “makefile” @

<your path>/spark/core-firmware/build/makefile

change around line 87 (see below)

# Find all build.mk makefiles in each source directory in the src tree.
#was SRC_MAKEFILES := $(call rwildcard,$(SRC_PATH)src,build.mk) #was
SRC_MAKEFILES := $(call rwildcard,$(SRC_PATH),build.mk) # is

in make file (around line 99) add: (third line down)

# Include directories for optional "libraries" (eg. Serial2.h)
INCLUDE_DIRS += $(LIB_CORE_LIBRARIES_PATH)Serial2 #already there
INCLUDE_DIRS += $(LIB_CORE_LIBRARIES_PATH)Adafruit_DHT_Library/firmware

Navigate to “build” directory

<your path>/spark/core-firmware/build

make the program and load it

$ make APP=<project name>TARGET=core-firmware
$ dfu-util -d 1234:4567 -a 0 -s 0x08005000:leave -D core-firmware.bin

Maybe that we help someone. I know it will help me when I forget how to do this (so like sometime tomorrow).

3 Likes