Project Build Options

The Build Options dialog box is an ImageCraft enhancement to the CodeBlocks IDE. It allows users to specify compiler options via GUI. It is a multi-tab dialog box. The left-hand pane displays all the targets for the project, and the active target is in bold, as well as noted on the title bar of the dialog box.

 

To save any changes, click OK. Otherwise, clicking Cancel throws away any changes you have made.

 

image

Default Options

You can save a particular set of options as Default by clicking “Save as Default”, and reload them later by clicking “Load Default”.

 

Build Target

The Build Target tab allows you to select whether this is a Program or a Library project. A library file has a .a extension, and should be copied to the “ImageCraft LIB directory” if it is to be linked by other projects.

 

You can also specify commands to be run before and after a build. The “after” commands will only run if the build is successful (no compilation errors).

 

The default “after” commands inserted by the CodeBlocks project wizards create a .bin and a .hex file, in addition to the .elf file generated by the compiler. These files are raw data files without symbols and debug information, which are used by program downloaders.

 

image

 

Paths

The Paths tab allows you to specify the paths where the compiler should find include and library files, as well as the output directory and output file name.

 

image

 

If you check “Normalize (relativize) All Paths”, when you click OK, all the paths are converted into relative paths.

 

The NOTE at the bottom of the dialog tab bears repeating:

 

The compiler driver automatically adds <install root>\include as the default include path and <install root>\lib as the default library path.

 

You do not need to add them to the respective edit boxes above.

 

If you do not specify a full path (i.e., a path that does not start with a \ or a drive letter), then the path is relative to the Project directory.

 

You may enter multiple paths in the "Include Paths" and the "Library Paths" fields. Multiple paths may be separated with a ";" or newline character.

Compiler/Linker

The Compiler/Linker tab allows you to specify the compiler and linker options. The CodeBlocks wizards will generate the set of the options based on the target MCU you specify (see below) and normally you do not need to modify them; however, see GCC Options.

 

image

 

It is beyond the scope of this document to describe all the GCC options in detail. However, the most important ones are:

Compiler Options

     -mcpu=cortex-m0 specifies that the CPU type is Cortex-M0. Other Cortex MCUs will have different MCU types (e.g. cortex-m3, etc.)

     -mthumb means that the ARM Thumb and Thumb2 instruction set should be used

     -Ox (eg: -O1, -O2, -O3) indicate the optimization level, ranging from 0 to 3. The higher the number, the more aggressive the optimizations. Generally, -O1 should be used when debugging is needed, and -O2 for release build. -O0 and -O3 are generally not recommended (a web search should explain why).

     -DVENDOR=ST and -DDEVICE=STM32F030C8 are predefined C macros that source files can use (e.g. #if VENDOR==ST) for conditional coding.

 

Linker Options

     -specs nano.specs and -specs nosys.specs specify that “Nano-Lib” is to be used instead of the default newlib and GCC glibc. For embedded systems without an underlying OS that provides file and memory management, nano-lib is the correct choice. See Floating Point Options and GCC Libraries.

     -TSetup/Release/Flash.ld specifies the linker memory option files. See below.

Linker Libs

Additional linker libraries can be specified here. A library file name usually has the form lib<name>.a. Library files should either be located in the default ImageCraft library directory <install root>\lib, or specified with a full path. If the former, you can omit the lib prefix and the .a suffix. For example, if you have a library file c:\iccv9cortex\lib\librexis.a, you can just write rexis in this box.

Additional Options

Clicking on the “Additional Compiler/Build Options” button on top brings up the traditional CodeBlocks compiler options dialog box:

image

 

You can fine-tune the compiler and linker options in this dialog box. Please refer to GCC document on what these options mean.

Device Target Options

The Device Target lets you select the target MCU for the project. The IDE automatically generates the linker command file (default name flash.ld) with the target MCU memory addresses. (The alternative is to craft the flash.ld by hand, which is a tedious and error-prone process.)

 

Here, it’s a simple process: first pick the silicon vendor, then select the MCU. If a particular MCU does not exist, you may need to update to the latest release of the product. You may also switch the Vendor field to Custom, where you can enter the memory addresses and sizes by hand, as well as the MCU type.

 

This tab also contains the checkbox to enable semihosting. Note that you must be using a compatible debug pod to use semihosting. See below for screencap.

Floating Point Options

Cortex-M MCU supports a variety of floating point options. The “Device Target” option tab includes the following:

 

image

 

The semihosting option is on the lower left.

 

On the right are the floating point (FP) options. The FP options are divided into two independent sets. The upper set specifies:

 

·         Software Emulation (the default). Floating point operations are done using library function calls that only use integer arithmetic. The operations may take many cycles to complete but is compatible to all Cortex-M MCUs, or

·         Enable Hardware FPU. For Cortex-M4 and Cortex-M7 based MCUs, you can enable hardware FPU (Floating Point Unit) for floating point processing. The FPU is much faster. However, if this option is used:

o   The created firmware image will not run on an MCU without an FPU, even if it is otherwise compatible in every other way.

o   If a routine uses float point operations, then it must save and restore all FPU registers at function entry and exit respectively. If the number of floating point operations used is small, then the cost of FPU save and restore may not be worthwhile.

o   Cortex-M4 only contains a single precision (32-bit) FPU whereas Cortex-M7 contains a FPU capable of single precision (32 bits) and double precision (64 bits) FP operations. On the Cortex-M4, double precision FP operations are still done using software emulation using integer operations and not the FPU.

 

Under “Enable Hardware FPU”, you have the further option of specifying which ABI (Application Binary Interface) calling convention is to be used:

 

o   Use SoftFP ABI. While floating point operations use the FPU, however, when a routine calls another routine, floating point arguments and function results use the integer registers, the same as when software emulation is used. This makes the routine compatible with library routines that are not compiled with the hardware FPU option.

o   Use HardFP ABI. This specifies that FPU registers are used for passing floating point arguments and function results between functions. This potentially is faster than SoftABI with the cost that all routines, including ones in the libraries, must be compiled with this option.

 

The lower set specifies:

 

·         Nanolib (the default). Otherwise known as newlib-nanolib. These are the Standard C and C++ libraries written specifically for microcontroller systems. They are smaller and faster than the “newlib” libraries (see next bullet). These improvements are achieved by, to quote - "Implementation focus is on code and data size reduction through optimization and removal of non-MCU features".

There are two suboptions under nanolib:

 

o   Use QFPlib. QFP is a tiny FP (floating point) package written by Mark Owen. Originally written for the Cortex M0 (but now also includes a version for the Cortex-M3 and above), all the routines including trigonometric functions fit in 1K bytes of code, significantly smaller than the routines in nanolib. Nanolib is released under GPL. According to the author:

 

Qfplib is licensed under version 2 of the GNU GPL: see http://www.gnu.org/licenses/. Roughly speaking, this means that if you wish to use it in conjunction with non-GPL code you will require an alternative license, which you may purchase from the author of Qfplib. For more information please contact qfplib@quinapalus.com or visit http://www.quinapalus.com/qfplib.html.

 

o   Enable floating point printf. One of the space saving technique that nanolib uses is to include a trimmed down version of printf that does not support floating point printout. If you need to print out floating point numbers (e.g. %f and %g format), enable this option.

·         Newlib. Newlib is an implementation of the Standard C and C++ libraries written for embedded systems. It’s called “newlib” because the traditional GCC libraries are more suitable and rely on features from traditional OS such as Linux. Both newlib and the traditional libraries are called glibc/glibc++ or sometimes just libc/libc++ as the target context clearly defines which set of libraries are being referenced.