Step 1: Setting Up Toolchain Folders
Step 2: Options for Cortex Processors
Step 3: Makefile Project Settings
Step 4: Makefile General Settings
Step 5: Makefile Command-Line Generation
Step 6: Makefile Execution
Complete Makefile
______________________________________________
A few weeks ago I successfully installed GNU GCC ARM Embedded Toolchain and configured my Eclipse Indigo IDE to develop firmware for Cortex embedded processors.
Here you are a very interesting and helpfull link (http://www.emb4fun.de/arm/eclipse/index.html) where it is explained, step-by-step, how to setup your Eclipse IDE + CDT + GCC ARM Toolchain to support Cortex embedded development.
I have not installed Yagarto, but a different ARM Embedded Toolchain, and have tested it by debugging a mbed LPC1768 board (cortex-m3) by following the instructions in the link above (also using a Segger J-Link EDU debugger), and I must say that it works really, really fine.
Well, let's go into the matter.
In order to make binaries for any embedded Cortex (M/R) processor, I've gone through arm-none-eabi toolchain documentation and adapted a makefile to make me easier the task of building code for different target processors with minimum changes in that makefile.
In the following sections I explain how does the makefile works...really simple, for sure!
Step 1: Setting Up Toolchain Folders
In this first section we are declaring some variables to keep track of the folders containing toolchain binaries, libraries and header files.
We are also building the paths for each binary into makefile variables... AS, CC, CCP, LD and OBJCOPY.
Just change it to fit your toolchain installation.
Step 2: Options for Cortex Processors
In this section we declare a couple of makefile variables for each target processor (M0, M0+, M1, M3, M4, R4, R5).
- CORTEX_xxxx_CC_FLAGS stores mcu specific GCC command-line options
- CORTEX_xxxx_LIB_PATH stores mcu specific prebuilt libraries supplied with the toolchain. Check your toolchain path to find where these libraries are stored.
If you are using the same toolchain as me, you should not need to change a line in this section.
Please note that NOFP, SWFP and HWFP modifiers in cortex-m4, cortex-r4 and cortex-r5 targets, stand respectivelly for no-floating-point, software-floating-point and harware-floating-point implementations.
Step 3: Makefile Project Settings
Here you must enter specific options for the project you want to build. Just a few comments about this section:
- MCU_CC_FLAGS and MCU_LIB_PATH receive the variables CORTEX_xxxx_CC_FLAGS and CORTEX_xxxx_LIB_PATH related to your target processor.
- OPTIMIZE_FOR variable must be set to SIZE to optimize code for size ( OPTIMIZE_FOR = SIZE ), or leave it undeclared ( OPTIMIZE_FOR = ) otherwise.
- DEBUG_LEVEL defines the option to append to -g compiler modifier. For example, if you set DEBUG_LEVEL = 3, the command line will include -g3 option. If you leave this variable undeclared, no -g option will be included into gcc command line.
- OPTIM_LEVEL works in the same way as DEBUG_LEVEL, but relates to -O optimization modifier. For example, if you set OPTIM_LEVEL = 1, the command line will include -O1 option. If you leave this variable undeclared, no -O option will be included into gcc command line.
Other variables in this section allows you to include custom object files, paths to project libs and headers, preprocessor symbol definitions, etc.
Customize it as your needs...
Step 4: Makefile General Settings
In Makefile General Settings section we are declaring variables to include paths to toolchain libraries and headers folders, and some library inclussion based on the optimization options declared in the previous section, by using conditional ifeq_else_endif makefile instructions.
These variables reference toolchain-related elements (objs, libs, headers, paths, etc), not project-related ones.
Later in command-line building section we are merging toolchain-related and project-related options into a single command-line for each toolchain binary as required.
Step 5: Makefile Command-Line Generation
As explained above, in this section we are building the whole command lines by merging project and toolchain specific compiler options and preprocessor symbols.
In a first approach you should not need to chage a line in this section because it processes variables already declared in previous sections..., but of course you are free to change it if your build requires it...
Step 6: Makefile Execution
Last section has no special nor additional comments about it. It just cleans generated files from previous builts and performs the execution of toolchain binaries to build your project.
Complete Makefile
And finally, the complete makefile is shown below...