How to create a new LPC project using LPCOpen and LPCXpresso

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a new LPC project using LPCOpen and LPCXpresso

No ratings

How to create a new LPC project using LPCOpen and LPCXpresso

This document describes how to create a new LPC project using LPCOpen v2.xx, LPCXpresso v8.2.2 and LPC11U24 LPCXpresso board. In addition describes how to create 2 simple example codes.

  1. Blinking LED.
  2. Set the LED using a push bottom.

 LPCOpen

LPCOpen is an extensive collection of free software libraries (drivers and middleware) and example programs that enable developers to create multifunctional products based on LPC microcontrollers.

After install LPCXpresso, the LPCOpen packages for supported board(s)/device(s) can be found at the path:

<install_path>\lpcxpresso\Examples\LPCOpen >

This directory contains a number of LPCOpen software bundles for use with the LPCXpresso IDE and a variety of development boards.

Note that LPCOpen bundles are periodically updated, and additional bundles are released. Thus we would always recommend checking the LPCOpen pages to ensure that you are using the latest versions.

This example was created using the LPC11U24 LPCXpresso board in this case the drivers selected is lpcopen_v2_00a_lpcxpresso_nxp_lpcxpresso_11u14.zip

pastedImage_1.png

Importing libraries

In order to create a new project, it is necessary to first import the LPCOpen Chip Library for the device used and optionally the LPCOpen Board Library Project. For do that it is necessary to follow these steps:

1. Click on Import project(s).

pastedImage_3.png

2. Select the examples archive file to import. In this case, the projects imported are contained within archives .zip. 

pastedImage_4.png

3. For this example the LPC11U14 LPCXpresso board is selected. Click Open. Then click Next

pastedImage_5.png

4. Select only the LPCOpen Chip Library and LPCOpen Board Library Project. Click Finish.

pastedImage_6.png

The same steps are required for any LPC device and board you are used.

Creating a new LPC project.

 

The steps to create a new LPC project are described below:

1. In Quickstar Panel, click "New project"

 pastedImage_1.png

2. Choose a wizard for your MCU. In this case LPC1100/LPC1200 -> LPC11Uxx -> LPCOpen-C Project

This option will link the C project to LPCOpen. Then click Next.

pastedImage_9.png

 

3. Select the Project name and click Next.

 pastedImage_10.png

4. Select the device used (LPC11U24 for this case) and click Next.

 pastedImage_11.png

5. Select the LPCOpen Chip Library and LPCOpen Board Library, these projects must be present in the workspace.

  pastedImage_12.png

6. You can set the following option as default clicking Next, then click Finish.

 pastedImage_13.png

7. At this point, a new project was created. This project has a src (source) folder, the src folder contains:

cr_startup_lpc11uxx.c: This is the LPC11Uxx Microcontroller Startup code for use with LPCXpresso IDE.

crp.c: Source file to create CRP word expected by LPCXpresso IDE linker.

sysinit.c: Common SystemInit function for LPC11xx chips.

<name of project> my_first_example: This file contains the main code.

 

 pastedImage_14.png

8. LPCXpresso creates a simple C project where it is reading the clock settings and update the system core clock variable, initialized the board and set the LED to the state of "On".

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

 

Writing my first project using LPCXpresso, LPCOpen and LPC11U24.

 

This section describes how to create 2 simple example codes.

  1. Blinking LED.
  2. Set the LED using a push bottom.

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

pastedImage_15.png

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

pastedImage_16.png

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 LPCXpresso 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.

 

int main(void) {

 

#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();

    // Set the LED to the state of "On"

    Board_LED_Set(0, true);

#endif

#endif

 

    // TODO: insert code here

 

    // Force the counter to be placed into memory

    volatile static int i = 0 ;

    // Enter an infinite loop, just incrementing a counter

    while(1) {

        i++ ;

    }

    return 0 ;

}

 

    a. Blinking LED.

In board_api.h file there is an API function that toggle the LED void Board_LED_Toggle(uint8_t LEDNumber);

 LEDNumber parameter is the LED number to change the state. The number of the LED for the LPCXpresso LPC11U24 is 0.

It is easy to create a delay function using FOR loops. For example:

void Delay (unsigned int ms)

{

        volatile static int x,y;

 

        while (ms)

        {

                for (x=0; x<=140; x++)

                {

                        y++;

                }

                ms--;

        }

}

In order to have the LED blinking, it is necessary to call these functions in an infinite loop.

while(1) {

                Board_LED_Toggle(0);

                Delay (10000);

        }

Complete code (Blinking LED).

int main(void) {

#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();

        // Set the LED to the state of "On"

        Board_LED_Set(0, true);

#endif

#endif

         while(1) {

                Board_LED_Toggle(0);

                Delay (10000);

        }

        return 0 ;

}

 void Delay (unsigned int ms)

{

        volatile static int x,y;

        while (ms)

        {

                for (x=0; x<=140; x++)

                {

                        y++;

                }

                ms--;

        }

}

 

   b. Set the LED using a push bottom.

For this example it is necessary to configure a pin as input.  The gpio_11xx_1.h file contains all the function definitions for the GPIO Driver.

The example uses the pin 16 of port 0 to connect the push bottom. The function

Chip_GPIO_SetPinDIRInput(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)

sets the GPIO direction for a single GPIO pin to an input. In order to configure the Port 0, pin 16 as input we can use this function:

Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 16);

Then, it is necessary to check the status of this pin to turn-on/turn-off the LED. The function

Chip_GPIO_GetPinState(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)

gets a GPIO pin state via the GPIO byte register. This function returns true if the GPIO is high, false if low.

State_Input=  Chip_GPIO_GetPinState (LPC_GPIO, 0, 16);

 

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

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, 16);

    // Set the LED to the state of "On"

    Board_LED_Set(0, false);

 #endif

 #endif

     while(1) {

 

        State_Input=  Chip_GPIO_GetPinState (LPC_GPIO, 0, 16);

             if (State_Input==0){

                Board_LED_Set(0, true);

            }

            else {

                Board_LED_Set(0, false);

            }

    }

    return 0 ;

}

 

I hope this helps!!

Regards

Soledad

Comments

Hello, Soledad

First of all, congratulations for this post. It is very helpful for beginners at LPC like me.

 

I'm just getting familiar to LPC MCU's. I know there is a lot of material available, and I heard that LPCOpen is a great starting point to get a kit running and a good starting point to learn about those MCU's.

I took a look at LPCXpresso LPCOpen folder and noticed that it does not support some families like LPC11xx and LPC 8xx.

Is there a alternative and solution similar to LPCOpen for those families?

Thanks and best regards!

Marco Coelho

Hello Marco,

There is support for LPC11xx and LPC8xx devices you can download the LPCOpen  Software for these devices at the following links:

LPCOpen Software for LPC11XX|NXP 

LPCOpen Software for LPC8XX|NXP 

Regards

Soledad

Hi, Soledad

After step 9. I got this error:

============= END SCRIPT =====================================
Probe Firmware: LPC-LINK2 CMSIS-DAP V5.173 (NXP Semiconductors)
Serial Number: ESAVAQKQ
VID:PID: 1FC9:0090
USB Path: /dev/hidraw0
connection failed - Ee(36). Could not connect to core. - retrying
Failed on connect: Ee(36). Could not connect to core.
Connected&Reset. Was: NotConnected. DpID: 00000000. CpuID: 00000000. Info: <None>
Last stub error 0: OK
Last sticky error: 0x0 AIndex: 0
No debug bus (MemAp) selected
DAP Speed test unexecuted or failed
Debug protocol: SWD. RTCK: Disabled. Vector catch: Enabled.
(100) Target Connection Failed

I am using LPC1549 and try to create my first project, but i could not debug the project.

 

How can I fix the " not connected to core" problem?

Best,

Snoo

Version history
Revision #:
1 of 1
Last update:
‎11-04-2016 11:07 AM
Updated by: