How to create a new LPC project using LPCOpen and MCUXpresso IDE

Document created by soledad Employee on Jul 12, 2017Last modified by soledad Employee on Aug 11, 2017
Version 3Show Document
  • View in full screen mode

This document explains how to create a new project using MCUXpresso IDE for a LPCXpresso1549 board.

There is important to mention that there is no SDK for LPC15xx device family so we are using LPCOpen libraries.

 

MCUXpresso IDE introduction

 

MCUXpresso IDE is based on the Eclipse IDE and includes the industry standard ARM GNU toolchain. It brings developers an easy-to-use and unlimited code size development environment for NXP MCUs based on Cortex-M cores (LPC and Kinetis). MCUXpresso IDE debug connections support Freedom, Tower®, LPCXpresso and your custom development boards with industry- leading open-source and commercial debug probes including LPC-Link2, P&E and SEGGER.

The fully featured debugger supports both SWD and JTAG debugging, and features direct download to on-chip flash.

When MCUXpresso IDE is installed, it will contain pre-installed part support for most LPC based MCUs. Example code for these pre-installed parts is provided by sophisticated LPCOpen packages (and Code Bundles). Each of these contains code libraries to support the MCU features, LPCXpresso boards (and some other popular ones), plus a large number of code examples and drivers.

 

In addition, MCUXpresso IDE’s part support can be extended using freely available MCUXpresso SDK2.x packages. These can be installed via a simple ‘drag and drop’ and automatically extend the IDE with new part knowledge and examples.

SDKs for MCUXpresso IDE can be generated and downloaded as required using the SDK Builder on the MCUXpresso Config Tools website at:

http://mcuxpresso.nxp.com/

 

Create a new project

 

For this document, we are using the LPCXpresso1549 board (for this MCU an LPCOpen project exists), however the process is the same for any LPCXpresso board.

It is necessary to download the LPCOpen bundle for your target MCU/board and import it into your Workspace, LPCOpen is available in the next link:

 http://www.nxp.com/lpcopen

 

  1. Select “New project” in the QuickStart panel, this will open a new window

 

 

 

  1. Select the desire board. For this case, we are using the LPCXpresso1549, and click “Next”

NOTE: When the board is selected, you can see highlighted in the above figure that the matching MCU (part) is selected automatically. If no matching board is available, the required MCU can be selected from the list of Pre-Installed MCUs.

 

 

  1. The MCUXpresso IDE includes many project templates to allow the rapid creation of correctly configured projects for specific MCUs.

This New Project wizard supports 2 types of projects:

  • Those targeting LPCOpen libraries
  • Standalone projects

In this case, we will show the steps in creating a LPCOpen- Cproject. This option creates a simple C project, with the main() routine consisting of an infinite while(1) loop that increments a counter. In additions, code will also be included to initialize the board and enable a LED.

 

 

  1. Select the project name and click “Next”

 

  1. When creating an LPCOpen-based project, the first option page that you will see is the LPCOpen library selection page.

It is necessary import the LPCOpen Chip Library for the device used and optionally the LPCOpen Board Library Project, the below window allows to import the libraries if you have not already done so. Follow the below steps:

a. Click on “Import…”, a new window will appear, select the archive file to import. In this case, the projects imported are contained within archives .zip. For this example, the LPCXpresso1549 board is selected. Click “Open”. Then click “Next”

 

b. Select only the LPCOpen Chip Library and LPCOpen Board Library Project. Click “Finish”

 

  1. Select LPCOpen Libraries. Click “Next”

  1. Select CMSIS Library project. The CMSIS library option within the MCUXpresso IDE allows you to select which (if any) CMSISCORE library you want to link to from the project you are creating. For this case we selected “None” as default. Click “Next”

NOTE: The use of LPCOpen instead of CMSIS-CORE library projects is recommended in most cases for new projects.

 

  1. Enable SWO trace clock. Click “Next”

 

  1. Enable linker support for CRP. Click “Next”

 

  1. The “Semihosting C Project” wizard for some parts provides two options for configuring the implementation of printf family functions that will get pulled in from the Redlib C library:
  • Use non-floating-point version of printf
  • If your application does not pass floating point numbers to printf() family functions, you can select a non-floating-point variant of printf. This will help to reduce the code size of your application.
  • For MCUs where the wizard does not provide this option, you can cause the same effect by adding the symbol CR_INTEGER_PRINTF to the project properties.
  • Use character- rather than string-based printf
  • By default printf() and puts() make use of malloc() to provide a temporary buffer on the heap in order to generate the string to be displayed. Enable this option to switch to using

“character-by-character” versions of these functions (which do not require additional heap space). This can be useful, for example, if you are retargeting printf() to write out over a UART – since in this case it is pointless creating a temporary buffer to store the whole string, only to print it out over the UART one character at a time.

  • For MCUs where the wizard does not provide this option, you can cause the same effect by adding the symbol CR_PRINTF_CHAR to the project properties.

For this example we will maintain as default.

 

  1. Having selected the appropriate options, you can then click on the Finish button, and the wizard will create your project for you, together with appropriate startup code and a simple main.c file.

 

  1. At this point you should be able to build and debug this project

 

 

Writing my first project

 

The LPCOpen Chip Library (in this case lpc_chip_15xx) contains the drivers for some LPC peripherals. For these examples, we will use the GPIO Driver.

 

The LPCOpen Board Library Project (in this case lpc_board_nxp_lpcxpresso_1549) contains files with software API functions that provide some simple abstracted functions used across multiple LPCOpen board examples.

 

 

The board_api.h contains common board definitions that are shared across boards and devices. All of these functions do not need to be implemented for a specific board, but if they are implemented, they should use this API standard.

After create a new project using MCUXpresso and LPCOpen, it is created a simple C project where it is initialized the board and set the LED to the state of "On" using the Board_LED_Set function.

 

In this example, we will toggle the a LED using a push bottom. In LPCXpresso1549 board le LEDs are connected to PIO1.1, PIO0.3 and PIO0.25 pins. And the SW1 to PIO0.17 pin.

The function Chip_GPIO_SetPinDIRInput configures a pin as input. 

The function Chip_GPIO_GetPinState gets a GPIO pin state via the GPIO byte register.

The function Board_LED_Set set the LED to the state of "On" or “Off”..

 

 

Complete code (Set the LED using a push bottom).

 

 

/*

===============================================================================

 Name        : LPCXpresso_new_example.c

 Author      : $(author)

 Version     :

 Copyright   : $(copyright)

 Description : main definition

===============================================================================

 */

 

#if defined (__USE_LPCOPEN)

#if defined(NO_BOARD_LIB)

#include "chip.h"

#else

#include "board.h"

#endif

#endif

 

#include <cr_section_macros.h>

 

 

int main(void) {

        bool State_Input;

 #if defined (__USE_LPCOPEN)

       // Read clock settings and update SystemCoreClock variable

       SystemCoreClockUpdate();

 #if !defined(NO_BOARD_LIB)

       // Set up and initialize all required blocks and

       // functions related to the board hardware

       Board_Init();

       Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 17); //Set GPIO direction for a single GPIO pin to an input

 

#endif

#endif

 

       while(1) {

               State_Input=  Chip_GPIO_GetPinState (LPC_GPIO, 0, 17);  //Get a GPIO pin state via the GPIO byte register

               if (State_Input==0){

                      Board_LED_Set(0, true); // Set the LED to the state of "On"

               }

               else  {

                      Board_LED_Set(0, false); // Set the LED to the state of "Off"

               }

       }

       return 0 ;

}

 

1 person found this helpful

Attachments

    Outcomes