A Brief Introduction to Programming the NXP LPC4370 MCU
Using the LPCXpresso IDE and Using Two LPC-Link2 Boards

Copyright 2014 by Thomas Weldon

The following  provides a brief introduction to programming the NXP LPC4370 MCU (microprogrammed control unit) using the NXP LPCXpresso development tools and two  Embedded Artists AB LPC-Link2 development boards.   One of the LPC-Link2 boards is connected to the computer running LPCXpresso IDE (integrated development environment) and acts as the JTAG programmer.  The second LPC-Link2 board is used as the target board for programming the LPC4370.  The following introduction was based on LPCXpresso  v7.3.0 [Build 186] [2014-07-09] on a 13-inch MAC laptop with OS X 10.8.5.

The sections below include:


  1. Obtain and Install LPCXpresso IDE from http://www.lpcware.com/lpcxpresso .   Register for the

  2. Purchase two LPC-Link2 boards  http://www.nxp.com/demoboard/om13054.html (NXP order code OM13054).

  3. Download the LCPOpen software for the board (lpcopen_2_12_lpcxpresso_nxp_lpclink2_4370.zip) from the LPC-Link2 (LPC4370) board Software Download link on the LPCOpen Software Development Platform (LPC43xx packages) webpage at  http://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc43xx-packages .

TenBlinks Example: Create a Workspace and Project To Make LED Blink 10 Times

    The following steps create a workspace in the LPCXpresso IDEthat contains the LPCOpen libraries, LPC-Link2/LPC4370 library, and the "tenBlinks demo C program that will blink the LED on the LPC-Link2 target board.   The example below uses a MAC computer.
  1. As illustrated below, run LPCXpresso, and browse to a directory where you would like to store your workspaces and projects, and enter the name of your new workspace.

  2. As illustrated below in LPCXpresso, click the "NewProject" button (lower left red arrow), and on the popup selectan LPC43xx Cortex-M4 basic LPCOpen-C Project.

  3. Enter the name of your new C code project as shown below.

  4. As shown below, select the LPC4370 MCU target.

  5. As illustrated below, import the LCPOpen software for the LPC-Link2 board (lpcopen_2_12_lpcxpresso_nxp_lpclink2_4370.zip).

  6. Select all the components for import as shown below .

  7. As shown below, choose the lpc_chip_43xx Chip and the lpc_board_nxp_lpclink2_4370 board.

  8. As illustrated below, choose "none" for CMSIS DSP library.

  9. Enable softABI as shown below.

  10. As shown below, disable CRP and create inc directory.

  11. As illustrated below, leave External memory blank (we will fix this later).

  12. Use non-float printf as shown below.

  13. As shown below, open your new project directory, find your mew-proct.c file, and double-click to open it.

  14. As illustrated below, edit the project properties.

  15. In the project properties popup as shown below, select MCU settings, and click to edit the memory configuration.

  16. As shown below, edit the memort by first clicking "add flash" (red arrow), editing the fields (blue arrows), moving it to top of list (black arrow), adding the flash driver by browsing (purple arrow), and saving the configuration (yellow arrow).  Click OK to save everything .

  17. As illustrated below, build your project.

  18. After the project is built, make sure there are no errors as shown below.

  19. As shown below, attach the JTAG to your LPCXpresso computer using the USB port, and use a JTAG cable to connect to the target board.  As shown below, power from the LPC-Link2 JTAG board is supplied to the LPC-Link2 Target board by connecting jumper JP1 on the JTAG board only.   All other jumpers are disconnected on both boards .

  20. As illustrated below, debug as a C NXP MCU Application.

  21. You should see a prompt to select the redlink server, as shown below.

  22. As shown below, choose the Cortex-M4 JTAG .

  23. As illustrated below, click the icon  to run the code on the target board.

  24. Click the yellow-double-bar icon to halt the program, as shown below.

  25. As shown below, add the disassembly view to see assembly language .

  26. As illustrated below, terminate the debug session.

  27. Add the source code in main() to blink the LED ten times on the target board, as shown below.
        // TODO: insert code here
        volatile int aa = 0, bb=0 ;
            Board_LED_Set(0, false);
            Board_LED_Set(0, true);
        Board_LED_Set(0, false);

  28. Rebuild the code, and rerun the code.  The target board LED should blink 10 times, then turn off, as shown in the movie below, with the target board on the right.

  29. Halt the program, and terminate the debug session..

  30. Unplug the usb from your laptp computer for the JTAG board to power down.

RampDAC Example: Find Clock Speeds and Use GPIO to Drive a DAC (digital to analog converter)

  1. Make a copy of your "tenBlinks" project by right-clicking the project, copy, paste, and renaming it "rampDAC"

  2. The following project will drive a DAC (digital to analog converter) on GPIO port 1 from connector J9 on the target the LPC-Link2 board.  LPC-Link2 digital outputs on connector J9 provide access to GPIO1 pins 0-4, 12, and 13.  So we will use GPIO1_0 as LSB (least significant bit) and GPIO1_13 as MSB for the DAC. Connect your favorite DAC to the LPC-Link2 connector J9 as illustrated below, with the blue arrow pointing to the DAC prototype board.

  3. Edit the new "rampDAC" project by replacing the prior code in main with the following new code:
        // TODO: insert code here
        //begin tpw code
        //blink LED 3 times and turn off
        volatile int aa = 0, bb=0 ;
            Board_LED_Set(0, false);
            Board_LED_Set(0, true);
        Board_LED_Set(0, false);
        //find rates of various clocks
        //it is useful to know your clock rates in driving your DAC
        //to see the values on your chip, halt the program and read these variables
    		volatile static long int sysCoreClk=0,maxSysClk=MAX_CLOCK_FREQ,mainPllClk=0;
    		volatile static long int chipBaseClk=0,mainPllDivisor=0,xtalClk=0;
    		volatile static long int periphBaseClk=0,spifiBaseClk=0,hsadcBaseClk=0,usbBaseClk=0;
    		volatile static long int spifiClk=0,hsadcClk=0,usbClk=0,gpioClk=0;
    		uint32_t sysCoreClk1=0;
    		sysCoreClk1 = Chip_Clock_GetRate(CLK_MX_MXCORE);
    		sysCoreClk=(long int)sysCoreClk1;
    		mainPllClk=(long int)Chip_Clock_GetMainPLLHz();
    		chipBaseClk=(long int)Chip_Clock_GetBaseClocktHz(CLKIN_CLKIN);
    		mainPllDivisor=(long int)Chip_Clock_GetDividerDivisor(CLKIN_MAINPLL);
    		xtalClk=(long int)Chip_Clock_GetClockInputHz(CLKIN_CRYSTAL);
    		periphBaseClk=(long int)Chip_Clock_GetBaseClocktHz(CLK_BASE_PERIPH);
    		spifiBaseClk=(long int)Chip_Clock_GetBaseClocktHz(CLK_BASE_SPIFI);
    		hsadcBaseClk=(long int)Chip_Clock_GetBaseClocktHz(CLK_BASE_ADCHS);
    		usbBaseClk=(long int)Chip_Clock_GetBaseClocktHz(CLK_BASE_ADCHS);
        //use LPC-Link2 digital outputs to drive your favorite DAC
        //on connector J9 GPIO1 pins 0-4 and 12, 13 are available
        //so we use GPIO1_0 as LSB and GPIO1_13 as MSB
        //below we clear GPIO1 then set each bit in succession
    	volatile static int nn = 0 ;
        volatile static int icnt = 0 ;
        volatile static int kk = 0 ;
    	//first configure pins as fast output pins
    	for(nn=0; nn<5;nn++)
    		Chip_SCU_PinMuxSet((uint8_t) 1, (uint8_t)(nn), SCU_PINIO_FAST);
    		Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, (uint8_t) 1, (uint8_t)(nn));
    		Chip_SCU_PinMuxSet((uint8_t) 1, (uint8_t)(12), SCU_PINIO_FAST);
    		Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, (uint8_t) 1, (uint8_t)(12));
    		Chip_SCU_PinMuxSet((uint8_t) 1, (uint8_t)(13), SCU_PINIO_FAST);
    		Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, (uint8_t) 1, (uint8_t)(13));
    	//create infinite loop of DAC output
    	//clear the output data on port GPIO1
    	Chip_GPIO_SetPortValue(PC_GPIO_PORT,(uint8_t) 1, (uint32_t)(0) );
    	//mark the beginning of the loop by setting a bit high
    	Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t) 1, (uint32_t)(1<<4) );
    	//use for loop for a short time pause
    	for(kk=0; kk<2;kk++);
    	Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t) 1, (uint32_t)(0) );
    	for(kk=0; kk<2;kk++);
    	for(nn=0; nn<5;nn++)
    		Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t) 1, (uint32_t)(1<<nn) );
    		for(kk=0; kk<2;kk++);
    	Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t) 1, (uint32_t)(1<<12) );
    	for(kk=0; kk<2;kk++);
    	//set GPIO1_13 as MSB
    	Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t) 1, (uint32_t)(1<<13) );
    	for(kk=0; kk<2;kk++);
    	//clear the port data
    	Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t) 1, (uint32_t)(0) );
    	for(kk=0; kk<4;kk++);
        icnt++ ;
        //end tpw code
    as shown below:

  4. Build and run the code as in the "tenBlinks" example above.  Halt the program to observe the varibles.  The speed of the waveforms is determined by the clocks on your LPC-Link2 board.  These can observed in the variables tab as shown at the red arrow below.  Also note the disssssembly at the blue arrow below.

  5. When the "rampDAC" is running, you should observe DAC outputs changing as follows:

    and zooming in to observe the response time of the DAC:

  6. When you finish your measurements, halt the program, terminate the debug session, and unplug the usb from your laptp computer to power down the JTAG board.

Notice: All referenced brands, product names, service names and trademarks are property of their respective owners. LPCXpresso_Getting_Started_Guide ARM and Cortex are trademarks of ARM Limited.  NXP is a registered trademark of NXP Semiconductors. LPCXpresso is a trademark of NXP Semiconductors. All other brands or product names are the property of their respective holders.  Mac and OS X are trademarks of Apple Inc.