Programming the lpc11u24 without the mbed library

27 May 2012

Greatings,

I want to programme my mbed without the mbed library just for the fun of it and to learn how it goes. My starting point is the code examples of keil for the 11Uxx that I found here : http://www.lpcware.com/content/nxpfile/sample-code-bundle-lpc11uxx-peripherals-using-keils-mdk-arm-0

I tried the following blinky code at first :

/****************************************************************************
 *   $Id:: blinky.c 9190 2012-02-16 20:59:45Z nxp41306                      $
 *   Project: NXP LPC11xx Blinky example
 *
 *   Description:
 *     This file contains LED blink code example which include timer, 
 *     GPIO initialization, and clock monitoring.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/
#include "LPC11Uxx.h"                        /* LPC11Uxx definitions */
#include "timer16.h"
#include "clkconfig.h"
#include "gpio.h"
#include "nmi.h"

#define TEST_TIMER_NUM		0		/* 0 or 1 for 16-bit timers only */

extern volatile uint32_t timer16_0_counter[2];
extern volatile uint32_t timer16_1_counter[2];

/* Main Program */

int main (void) {
  uint32_t interval;

  SystemCoreClockUpdate();

  /* Config CLKOUT, mostly used for debugging. */
  CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK );
  LPC_IOCON->PIO0_1 &= ~0x07;	
  LPC_IOCON->PIO0_1 |= 0x01;		/* CLK OUT */

  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

  /* TEST_TIMER_NUM is either 0 or 1 for 16-bit timer 0 or 1. */
  interval = SystemCoreClock/1000 - 1;
  if ( interval > 0xFFFF )
  {
	interval = 0xFFFF;
  }
  init_timer16(TEST_TIMER_NUM, interval);
  enable_timer16(TEST_TIMER_NUM);

  /* Set port 0_7 to output */
  GPIOSetDir( 0, 7, 1 );

  while (1)                                /* Loop forever */
  {
#if TEST_TIMER_NUM
	/* I/O configuration and LED setting pending. */
	if ( (timer16_1_counter[0] > 0) && (timer16_1_counter[0] <= 200) )
	{
	  GPIOSetBitValue( 0, 7, 0 );
	}
	if ( (timer16_1_counter[0] > 200) && (timer16_1_counter[0] <= 400) )
	{
	  GPIOSetBitValue( 0, 7, 1 );
	}
	else if ( timer16_1_counter[0] > 400 )
	{
	  timer16_1_counter[0] = 0;
	}
#else
	/* I/O configuration and LED setting pending. */
	if ( (timer16_0_counter[0] > 0) && (timer16_0_counter[0] <= 200) )
	{
	  GPIOSetBitValue( 0, 7, 0 );
	}
	if ( (timer16_0_counter[0] > 200) && (timer16_0_counter[0] <= 400) )
	{
	  GPIOSetBitValue( 0, 7, 1 );
	}
	else if ( timer16_0_counter[0] > 400 )
	{
	  timer16_0_counter[0] = 0;
	}
#endif
  }
}

I compiled it but it does not seem to work. I tried to change the pin in the code and other things but it seems like it is not so easy.

Is it possible to compile this code with the online compiler of mbed and to upload it on my board? Or am I missing somthing?

Any hint?

thanks.

28 May 2012

I suppose to make that work you have to upload all the used libraries too.

I have made a couple of simple programs that don't use the mbed library but there were no other libraries used, just that basic device header

Import programFlashingLeds

Flashing leds using the four timer interrupts , 100ms, 200ms, 400ms, 800ms

You can always download uvision and compile the examples, there is a 32K limit for demo which is all that you need for this board. Than use this guide to program your board http://mbed.org/users/alexan_e/notebook/how-to-use-your-mbed-board-with-uvision/

Alex

28 May 2012

I have made a project with the blinky example from the code bundle you have specified

Import programblinky

blinky example from NXP code bundle for LPC11Uxx. No mbed library used

I have changed the port pin used to P1.8 which is led1 in the mbed board, check the following pinout to see the led pins and change it if you want http://mbed.org/users/alexan_e/notebook/pinout-of-the-mbed-lpc11u24/

I have commented a couple of lines that set the CLK out pin.

Also in order for the code to work the extern "C" prefix has to be added in front of all the used interrupt handlers. I have added this only in the timer16 libraries that were used in this case, other libraries have to be changes too for other examples in the bundle that use them.

I have tested the provided code and works fine.

Alex

28 May 2012

Thanks a lot Alexan, your are of a great help.

I am not sure to understand why I have to use the extern "C" perfix (I thought this code should work for the LPC11U24? ). Did you modify anything in one of those file ?:

  1. include "LPC11Uxx.h",#include "timer16.h",#include "clkconfig.h",#include "gpio.h",#include "nmi.h"

I would really appreciate if you post your code for me.

Thanks a lot!

28 May 2012

I have only modified the timer16.h, timer16.c and added the extern "C" prefix to the interrupt handlers. If you don't do that then the interrupt handler will never be called.

There was an article explaining this but I can't find it.

I only found the following post http://mbed.org/forum/mbed/post/13379/

28 May 2012

You can find the source code in the blinky program link I have posted. The blink.c is the main code in which I have changed the led pin.

Click import code to use it in the compiler

I mean this link

Import programblinky

blinky example from NXP code bundle for LPC11Uxx. No mbed library used

29 May 2012

Thank you very much. It works perfectly.

29 May 2012

Hi Alexan,

I gave a look at your site and found your ARMwizard app. Souds like very interessting app:

Quote:

The application generates the initialization code with the selected settings, fully commented and including register values and interrupt function handlers, you just have to copy the code in a new project to have a starting point in a few minutes, this should make that development of applications much easier and faster. The settings can also be saved and reloaded later in a new session to save time when reusing the same configuration.

I have a question : now that I have the code for the lpc11u24, how can I use it? If I understand right, I don't need to write code for exemple to initialize a GPIO for UART communication? Do I still need the KEIL_LPC11U_COMMON_LIB ?

thanks.

29 May 2012

I have two example that were generated from my applicatopn

Import programFlashingLeds

Flashing leds using the four timer interrupts , 100ms, 200ms, 400ms, 800ms

Import programGPIO_interrupts

A simple example that uses the GPIO group and pin interrupts. LED1 turns on when P21 and P22 are grounded (using group 0 interrupt) LED1 turns of when P23 or P24 are grounded (using group 1 interrupt) LED2 turns on when P19 is grounded (using GPIO interrupt 0) LED2 turns off when P18 is grounded (using GPIO interrupt 1)

First of all you have to add the extern "C" in front of the interrupt handlers in your code like I din in my examples , I don't think there is a way to avoid that with the online compiler.

I had trouble making the code compile using the LPC11Uxx.h header because there were the startup and core/system files that needed to be added so I replaced the header with mbed.h and the code worked fine. I'm sure it will work too with LPC11Uxx.h if some system libraries are added but I didn't bother much and used the mbed instead.

My application doen't have UART initialization yet but if you do it using regiters and not function from a library then you don't need to add anything. Note that sooner or later you will need to add so me library , for example LCD driver or something but this shouldn't be a problem, just add the library to the project.

Alex

29 May 2012

Alexan E wrote:

First of all you have to add the extern "C" in front of the interrupt handlers in your code like I din in my examples , I don't think there is a way to avoid that with the online compiler.

I don't think there is a way to avoid this either. The interrupt vector uses C names for these interrupt handlers which don't have name mangling. With the online compiler, even .c files are compiled as C++ so they would be name mangled if you didn't add the extern "C". I suspect that the online compiler forces .c files to be built as C++ so that you can use the mbed SDK from either .c or .cpp source files. I see that your examples use .cpp files so these should require the extern "C" even with other compilers as well.

29 May 2012

When I write in uvision I use c files (I don't know much about C++) but when I created the two projects for the onlile compiler I kept the cpp extension and just renamed the system generated file, I didn't think of changing it although it seems that the extension doesn't make a difference.

I have only attempted to change the extension of the main code file to c in the blinky example.

Alex