Adding and Revising Boards - synthetos/g2 GitHub Wiki
This is the start page for how to add a new board or machine profile to g2core. Please read this page first, then move on to whichever following pages are relevant:
-
Adding and Revising Boards (this page)
Before we go into making a new board, we’ll cover how to use a board.
You need to know this so the other pages make sense. The makefile command line recognizes the following arguments in this hierarchy:
-
CONFIG- configuration for a specific machine-
a "machine" means a
BOARDand aSETTINGS_FILEfor that machine -
CONFIGsare located in the fileboards.mkwhere it specifies:-
the default
SETTINGS_FILEfor that machine -
the default
BOARDfor that machine
-
-
-
BOARD- top-most hardware and revision-
specifies the board type and board revision, e.g.
g2v9kis a v9, revision k -
BOARDsare located in the files board/board_file.mk-
Note: The board file should not contain the revision in the filename. Example
board/g2v9.mknotboard/g2v9k.mk -
All board revisions are located in the same board_file for that board type.
-
-
BASE_BOARDis a sub-argument that is used internally and describes the underlying hardware platform.BASE_BOARDhandles the boilerplate for configuring the compiler flags and paths for a range of devices.-
For example, in the case of a Due or other motherboard/daughterboard the
BASE_BOARDis the motherboard, and theBOARDis the daughter board (the actual shield). You should not specify theBASE_BOARDin the command line, but it can be edited in the board file. -
For example
board/g2v9.mkwill contain definitions forBOARD=g2v9kandBOARD=g2v9l. Both of thoseBOARDs specifyBASE_BOARD=g2v9, which handles the boilerplate setup for all of those boards.📓Name all BOARDand .mk files in lower case from here on.
-
-
-
SETTINGS_FILE- specifies the default settings that are applied at compile time-
example:
SETTINGS_FILE="settings_shapeoko2.h"will tellsettings.hto include the filesettings/settings_shapeoko2.h. -
If
SETTINGS_FILEis not specified directly on the command line or in aCONFIG, thensettings_default.his used.settings_default.hruns after the settings file, and provides a default value for every settings #define. This way thesettings_xxxxx.hfile does not have to contain every possible define. The values in the default file will compile a functional board (i.e. it will communicate), but will disable most devices. -
Note that the
CONFIGsets theSETTINGS_FILEoption, overriding what is on the command line
-
|
📓
|
PLATFORM has been deprecated and is no longer a make flag.
|
Example make lines:
# Compile for a PrintrbotPlus:
make CONFIG=PrintrbotPlus
# Looking into board/g2_configs.mk you will see that that's roughly equivalent to:
# make BOARD=pboard-a SETTINGS_FILE="settings_printrbot_plus.h"
# Compile for a PrintrbotPlus, but using an Achim instead:
make CONFIG=PrintrbotPlus BOARD=ArchimIf CONFIG is specified (BOARD is then implicitly or explicitly set) the object files will be in build/$(CONFIG)-$(BOARD)/ and the results files in bin/$(CONFIG)-$(BOARD)/.
If CONFIG is not specified (BOARD then must be explicitly set) the object files will be in build/$(BOARD)/ and the results files in bin/$(BOARD)/.
The make clean command line should have the same CONFIG and/or BUILD arguments as the make line so that the correct files are removed.
The final output files are located in directories based on the CONFIG and BOARD parameters. The SETTINGS_FILE and other options have no bearing on output file locations.
If CONFIG is defined, then the final output is placed in g2core/build/$(CONFIG)-$(BOARD)/ and the intermediate files (.o "object files", makefile "dependency files", etc) required to build the final output files are stored in g2core/bin/$(CONFIG)-$(BOARD)/.
Note: See Other make options below for important options to add to a make command line stored in a GUI such as Xcode or Atmel Studio.
The BOARD setting is required, however a default value is provided if you provide a CONFIG value.
The make command line should specify a CONFIG, which provides at least a default BOARD and a default SETTINGS_FILE. Even if CONFIG is specified you can override the default BOARD and SETTINGS_FILE.
All of these are case sensitive. Example:
-
For a Shapeoko dual-Y-motor configuration using a
g2v9kcallmakewithCONFIG=ShapeokoDualY:
make CONFIG=ShapeokoDualY-
For a Shapeoko dual-Y-motor configuration using a custom board called
CustomBoard:
make CONFIG=ShapeokoDualY BOARD=CustomBoard-
To enter the debugger, add
debug
make BOARD=gShield debug
# Or, to use the python-enabled gdb
make BOARD=gShield debuggyTo save time the makefile will only compile the files needed when something changes. Sometimes you need to clean out all the old compiled intermediate files. There are two ways to do this:
-
The nice way: Add
cleanto the end of your command line (replacingdebugordebuggyif it was there).📓make … cleanmust have the sameBOARD/CONFIGoptions as themakedid in order to locate the files. See Output Files for more explanation as to how it finds those files.SETTINGS_FILEcan be omitted from thecleanline. -
The not so nice way:🔨 Delete the directories
g2core/binandg2core/buildfrom your repo.⚠️ Make sure you don’t accidentally throw away board!-
This removes all of the build files and intermediates for all configurations.
-
There are a few other command line make options to be aware of:
-
VERBOSE- set this to0(for "quiet," which is the default),1(to show commands executed in full), or2(the same as1plus additional Makefile debug reporting).❗For all make command lines stored in GUIs (Atmel Studio, Xcode), you should use VERBOSE=1 -
COLOR- set this to1(the default) or0(to not use terminal escape sequences to make the voluminous output more readable)❗For all make command lines stored in GUIs (Atmel Studio, Xcode), you should use COLOR=0 -
OPTIMIZATION- set this to the-Ovalue for gcc. Generally we useOPTIMIZATION=3as the default, but may useOPTIMIZATION=sif we want to save flash space.⚠️ This should NOT be hard coded into a GUI make command unless it’s deemed necessary — use the default. ⚠️ Generally, if you set it to below
2the code will be huge and cannot fit on any of the target processors.Said again, more directly: this cannot be set to
0or the code will not fit on the processor. We rely on the optimizer to make the code perform reasonably and be a reasonable size. This has a minor negative impact on debugging, but it’s manageable.
Compilation is managed by this makefile hierarchy:
-
./g2core/MakefileMain project makefile invokes:-
./Motate/Motate.mkinvokes MotateUtilities.mk and kicks off the Board makefiles:-
./g2core/board/xxxxxx.mkis the makefile for a specific board, and may also include a baseboard makefile
-
-
In the g2core project structure (covered here) there is a boards.mk file and several files and directories under board/ for each board type.
-
boards.mk- This file is what is included by the Motate Makefile. It’s contents are primarily handlingCONFIGs. At the end it has this important line:# Note: STAR=* -- a workaround for a Makefile glitch. include $(wildcard ./board/$(STAR).mk)
-
This line imports (in relatively random order) any file that ends with
.mkthat’s directly inside theboard/directory.
-
-
board/*.mk- Each.mkfile insideboard/has the opportunity to define what happens when aBOARDhas a specific value. We’ll cover how to do that shortly. -
board/*.gdb- This is the GDB startup file for each board.-
It is located from inside Motate as
"${BOARD_PATH}.gdb".
-
Each BOARD sets a few important values:
-
BASE_BOARD- This is used later to know which settings to use for a range of boards. We show how to create that next.💡Even if you only have one board revision, it’s still good practice to break BASE_BOARDandBOARDout so you can revise later. -
DEVICE_DEFINES- This is where you pass defines directly into the code (as if they were#defined).❗You want to make sure you use +=to add toDEVICE_DEFINES, not just=or=:. There are other places to add toDEVICE_DEFINESas well, and some are called beforeboards.mkis.-
You need to define at least two values:
MOTATE_BOARDandSETTINGS_FILE-
MOTATE_BOARD(inDEVICE_DEFINES) - This is used in locating the pinout file, in the form of${MOTATE_BOARD}-pinout.h. This is generally equal toBOARD, but may be different.❗On case sensitive operating systems, such as linux, ${MOTATE_BOARD}-pinout.hmust match the pinout file name exactly. On OS X, which is usually not case sensitive, this will match with different case. Please be sure to check the case of this and the file. Better yet, just always use lowercase for both. -
SETTINGS_FILE(inDEVICE_DEFINES) - this is usually just passed through:DEVICE_DEFINES += SETTINGS_FILE=${SETTINGS_FILE}
-
-
ifeq ("$(BOARD)","g2v9k")
BASE_BOARD=g2v9
DEVICE_DEFINES += MOTATE_BOARD="G2v9k"
DEVICE_DEFINES += SETTINGS_FILE=${SETTINGS_FILE}
endif|
📓
|
|
Each BASE_BOARD sets a few important values:
-
_BOARD_FOUND- Just set it to1:_BOARD_FOUND = 1- this tells the calling Makefile that the board is configured. -
FIRST_LINK_SOURCES- Without spending too much time talking about linking order and such — and that is important, this value tells the compiler which files to link first, and it is in order.❗Make sure to only add to this value with +=! Normallymain.cppwill already be on that list and will be first.💡Use one of the other .mkfiles as an example. Generally this only refers to files in Motate, and will be the same for all processors of the same type. -
CHIP- This sets the main processor used by the board. This must be supported by Motate.❗CHIPmust be made available to the shell environment after it’s set with anexport CHIP.💡Again, use one of the other .mkfiles as an example. If Motate supports it there’s likely already another board with theCHIPyou are using. -
CHIP_LOWERCASE- This is the same asCHIPbut lowercase. This is used by Motate to locate some vendor files.CHIP_LOWERCASEdoes not need to be exported. -
BOARD_PATH- This setting sets where the project will locate the gdb file (as"${BOARD_PATH}.gdb"), and is used to find files such ashardware.hwhen this board is being used.❗The BOARD_PATHwill not be added to the include search path until it is added toSOURCE_DIRS!💡Often BOARD_PATHis equivalent to./board/${BASE_BOARD}— but it doesn’t have to be. -
SOURCE_DIRS- This setting tells Motate where to find files to compile (.c,.cpp, and*.swill be compiled and linked in), as well as where to search for included header files.❗Make sure to only add to this value with +=! This is used to generate the list of all files to be compiled, and there are several other places that add to this list.💡This is the place where you add the directories of devices under the device/directory to be included in the compile. -
PLATFORM_BASE- ThePLATFORM_BASEvalue is the path (without the.mk) to the platform definition file provided by Motate to configure compilation for this processor.❗The last line of the
BASE_BOARDdefinition must be:include $(PLATFORM_BASE).mk
ifeq ("$(BASE_BOARD)","g2v9")
_BOARD_FOUND = 1
FIRST_LINK_SOURCES += $(sort $(wildcard ${MOTATE_PATH}/Atmel_sam_common/*.cpp)) $(sort $(wildcard ${MOTATE_PATH}/Atmel_sam3x/*.cpp))
# Set CHIP and export it for GDB to see
CHIP = SAM3X8C
export CHIP
CHIP_LOWERCASE = sam3x8c
BOARD_PATH = ./board/g2v9
SOURCE_DIRS += ${BOARD_PATH} device/step_dir_driver
PLATFORM_BASE = ${MOTATE_PATH}/platform/atmel_sam
include $(PLATFORM_BASE).mk
endif|
📓
|
|
Next, continue on to Adding and Revising Configurations and Settings