LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Setting up an Xpresso executable image project

Setting up an Xpresso executable image project
A simple project will be created that uses another library project.

The example here shows how to build a simple blinky executable image for the Embedded Artists LCP1788 board. This executable uses the Embedded Artists LCP1788 board library.

Create a new C project
Create a new project using the New->Project selection on the file menu.

new_project1.jpg

Select C/C++->C project in the new project dialog window and press Next>.

new_c_project1.jpg

On the next dialog window, name your project and select the Empty project type. Press Next>.

new_c_project2.jpg

On the next dialog window, select the default 'Debug' and 'Release' project configurations. This will create an unoptimized debug configuration and an optimized release configuration of the project. Press Next>.

On the next dialog window, select the device your project will use. For this example, we use the LPC1788.. Press Finish.

new_project4.jpg

After pressing Finish, the project is added to the project explorer window. Before adding source files to the project, a few more items specific to the LPCOpen platform need to be configured in the project.

CORE_M? symbol setup
Although all of the default project settings should work fine, the LPCOpen platform code requires a few additional configuration steps.

Right click on the project in the Project explorer and select Properties from the popup menu. This will being up the project properties dialog window.

From the category list on the left side of the dialog window, select the C/C++ Build option. In the right half of the window, notice that the project contains 2 configurations - Debug and Release. The additional steps indicated below must be applied to both configurations separately. To switch configurations, just select the configuration in the Configuration drop down box.

project_settings1.jpg

Select the C/C++ Build->Settings option in the category window and the MCU C Compiler->Symbols option in the Tool Settings tab in the right window. For the device you are using, you will need to add a new symbol here of value CORE_M0, CORE_M0PLUS, CORE_M3, or CORE_M4. To add this new symbol, click the green + button and type in the name of the symbol and press OK. A list of CORE_M? values to use for each device can be found at one of the links below based on your selected device family.
CHIP: LPC8xx Chip driver build time options
CHIP: LPC11xx Chip driver build time options
CHIP: LPC13xx Chip driver build time options
CHIP: LPC17xx/40xx Chip driver build time options
CHIP: LPC18xx/43xx Chip driver build time options
The example screen below uses CORE_M3 for the LCP1788 device. Do this for both Debug and Release configurations.

project_settings2.jpg

sys_config.h symbols
If a symbol needed for building a platform isn't included in sys_config.h (see Adding platform definitions using sys_config.h), then is must also be added in the symbol list similar to the CORE_M value.

Xpresso run-time library selection
Most LPCOpen projects run with the Redlib(none) or Redlib(nohost) libraries. These are the recommended libraries to use when building LPCOpen. For best size, use the (none) version of the library. If you plan on using standard I/O (printf), use the (nohost) version of the library. If you use the DEBUG_ENABLE option (see Adding platform definitions using sys_config.h), then use the (nohost) option. The library type can be selected on the quickstart panel.

proj_sel_libtype.jpg

Adding libraries
If you want to link with a library, you need to add the library to your project. To add the library, right click on the project in the project explorer window and select properties. Select the C/C++ Build->Settings option in the category window and the MCU Linker->Libraries option in the Tool Settings tab in the right window. Locate the library (in this example, it will be in the "<WORKSPACE>\board_lib_1788\debug" or "<WORKSPACE>\board_lib_1788\release" directory) with a name of "libboard_lib_1788.a".

In the dialog box, click the green + button in the 'Libraries (-l)' section and add the library to the project. Also click on the green + button in the 'Library search path (-L)' section and add the path to the library in yuor workspace. You will need to do this for debug and release configurations. It is recommended to use the debug library path for the debug configuration and the release library path for the release configuration. Save the settings by pressing the OK button.
When adding the library name, remvoe the leading 'lib' and the trailing '.a' from the library filename.

xpresso_lib_setup1.jpg

Ideally, when the executable project is built, other projects that the executable project depends on - such as the board library project - should also automatically re-build if something in them has changed. To add this support, a project depdendency needs to be added to the project. Add the dependency by right click on the project in the project explorer window and select properties. Select the Project references option in the category window and check the 'board_lib_1788' project in the right window. Press OK to save. Now, whenever the executable project is built, the library that the executable project depends on will be built first if it needs to be re-built.

xpresso_lib_setup2.jpg

Adding source files
To build an executable image, the compiler needs startup code and example code. Start by adding the example source file. In the project explorer window, right click on the project and select New->File.

proj_add_new_file.jpg

Type in the file name (main.c) and press Finish.

proj_add_new_file_2.jpg

The file will be added to your project and the empty file will open in the editor view. Add the following code to the file and save it.

#include "board.h"

static void small_delay(int delay)
{
    delay = delay * 100;
 while (delay > 0) {
        delay--;
    }
}

int main(void)
{
 /* Initialize the board layer */
    Board_Init();

    /* Loop forever */
 while (1) {
  Board_LED_Set(0, 1); /* Turn board LED 0 on */
  DEBUGSTR("LED on\r\n");
  small_delay(5000);
  Board_LED_Set(0, 0); /* Turn board LED 0 off */
  DEBUGSTR("LED 0ff\r\n");
  small_delay(5000);
    }

 return 0;
}

Next, add the startup code for the LPC17xx/40xx device family from the LPC17xx/40xx example area. Pre-made startup code can be found in the following directory:
"<LPCOPEN_PATH>\applications\lpc17xx_40xx\startup_code".
For the Xpresso platform and the Embedded Artistst LPC1788 board, the cr_startup_lpc17xx40xx.c file needs to be added to the project. The file can be added to the project by dragging the file from an folder window directly to the project or using the file import option. Select 'Copy files' to move the file into your workspace.

Adding include paths
To add include paths to the project, right click on the project in the project explorer window and select properties. Select the C/C++ Build->Settings option in the category window and the MCU C Compiler->Includes option in the Tool Settings tab in the right window. Add include paths one at a time to the project by pressing the green + symbol. Be sure to do this for both Debug and Release configurations. Once all the include paths have been added, press OK to return to the workspace view.
For the EA1788 board project, the following include paths are needed:

  • "<LPCOPEN_PATH>\software\CMSIS\CMSIS\Include"
  • "<LPCOPEN_PATH>\software\lpc_core\lpc_ip"
  • "<LPCOPEN_PATH>\software\lpc_core\lpc_chip\chip_common"
  • "<LPCOPEN_PATH>\software\lpc_core\lpc_chip\chip_lpc17xx_40xx"
  • "<LPCOPEN_PATH>\software\lpc_core\lpc_boards\board_common"
  • "<LPCOPEN_PATH>\software\lpc_core\lpc_boards\boards_17xx_40xx\ea_devkit_17884088"
  • "<LPCOPEN_PATH>\software\lpc_core\lpc_boards\boards_17xx_40xx\ea_devkit_17884088\ea_devkit_1788" (for EA1788 sys_config.h only)
    Include paths needed for the Chip and Board layers for a device family can be found at LPCOpen library configurations.
    project_include1.jpg

At this point, the library project is complete. You can build test the debug and release configurations of your project now.

17:02:12 **** Build of configuration Debug for project ea1788_blinky ****
make all 
Building file: ../cr_startup_lpc17xx40xx.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DCORE_M3 -DDEBUG -D__CODE_RED -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_ip" -I"C:\dev\git2\lpcopen\software\CMSIS\CMSIS\Include" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_chip\chip_common" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_chip\chip_17xx_40xx" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_board\board_common" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_board\boards_17xx_40xx\ea_devkit_17884088" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_board\boards_17xx_40xx\ea_devkit_17884088\ea_devkit_1788" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"cr_startup_lpc17xx40xx.d" -MT"cr_startup_lpc17xx40xx.d" -o "cr_startup_lpc17xx40xx.o" "../cr_startup_lpc17xx40xx.c"
Finished building: ../cr_startup_lpc17xx40xx.c
 
Building file: ../main.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DCORE_M3 -DDEBUG -D__CODE_RED -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_ip" -I"C:\dev\git2\lpcopen\software\CMSIS\CMSIS\Include" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_chip\chip_common" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_chip\chip_17xx_40xx" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_board\board_common" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_board\boards_17xx_40xx\ea_devkit_17884088" -I"C:\dev\git2\lpcopen\software\lpc_core\lpc_board\boards_17xx_40xx\ea_devkit_17884088\ea_devkit_1788" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.c"
Finished building: ../main.c
 
Building target: ea1788_blinky.axf
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -L"C:\nxp\workspace\board_lib_1788\Debug" -Xlinker -Map="ea1788_blinky.map" -Xlinker --gc-sections -mcpu=cortex-m3 -mthumb -T "ea1788_blinky_Debug.ld" -o "ea1788_blinky.axf"  ./cr_startup_lpc17xx40xx.o ./main.o   -lboard_lib_1788
Finished building target: ea1788_blinky.axf
 
make --no-print-directory post-build
Performing post-build steps
arm-none-eabi-size "ea1788_blinky.axf"; # arm-none-eabi-objcopy -O binary "ea1788_blinky.axf" "ea1788_blinky.bin" ; checksum -p LPC1343 -d "ea1788_blinky.bin";
   text    data     bss     dec     hex filename
   7312       0       4    7316    1c94 ea1788_blinky.axf
 

17:02:15 Build Finished (took 3s.104ms)