You are on page 1of 28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

ABriefIntroductiontoProgrammingtheNXPLPC4370MCU
UsingtheLPCXpressoIDEandUsingTwoLPCLink2Boards
Copyright2014byThomasWeldon

ThefollowingprovidesabriefintroductiontoprogrammingtheNXPLPC4370MCU(microprogrammedcontrol
unit)usingtheNXPLPCXpressodevelopmenttoolsandtwoEmbeddedArtistsABLPCLink2development
boards.OneoftheLPCLink2boardsisconnectedtothecomputerrunningLPCXpressoIDE(integrated
developmentenvironment)andactsastheJTAGprogrammer.ThesecondLPCLink2boardisusedasthe
targetboardforprogrammingtheLPC4370.ThefollowingintroductionwasbasedonLPCXpressov7.3.0[Build
186][20140709]ona13inchMAClaptopwithOSX10.8.5.
Thesectionsbelowinclude:
Preliminaries:setupandinstallhardwareandsoftware
TenBlinksExample:CreateaWorkspaceandProjectToMakeLEDBlink10Times
RampDACExample:FindClockSpeedsandUseGPIOtoDriveaDAC(digitaltoanalogconverter)

Preliminaries
1.ObtainandInstallLPCXpressoIDEfromhttp://www.lpcware.com/lpcxpresso
(http://www.lpcware.com/lpcxpresso).Registerforthe
2.PurchasetwoLPCLink2boardshttp://www.nxp.com/demoboard/om13054.html
(http://www.nxp.com/demoboard/om13054.html)(NXPordercodeOM13054).
3.DownloadtheLCPOpensoftwarefortheboard(lpcopen_2_12_lpcxpresso_nxp_lpclink2_4370.zip)from
theLPCLink2(LPC4370)boardSoftwareDownloadlinkontheLPCOpenSoftwareDevelopmentPlatform
(LPC43xxpackages)webpageathttp://www.lpcware.com/content/nxpfile/lpcopensoftwaredevelopment
platformlpc43xxpackages(http://www.lpcware.com/content/nxpfile/lpcopensoftwaredevelopment
platformlpc43xxpackages).

TenBlinksExample:CreateaWorkspaceandProjectToMake
LEDBlink10Times
ThefollowingstepscreateaworkspaceintheLPCXpressoIDEthatcontainstheLPCOpenlibraries,LPC
Link2/LPC4370library,andthe"tenBlinksdemoCprogramthatwillblinktheLEDontheLPCLink2target
board.TheexamplebelowusesaMACcomputer.
1.Asillustratedbelow,runLPCXpresso,andbrowsetoadirectorywhereyouwouldliketostoreyour
workspacesandprojects,andenterthenameofyournewworkspace.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

1/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

2.AsillustratedbelowinLPCXpresso,clickthe"NewProject"button(lowerleftredarrow),andonthepopup
selectanLPC43xxCortexM4basicLPCOpenCProject.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

2/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

3.EnterthenameofyournewCcodeprojectasshownbelow.

4.Asshownbelow,selecttheLPC4370MCUtarget.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

3/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

5.Asillustratedbelow,importtheLCPOpensoftwarefortheLPCLink2board
(lpcopen_2_12_lpcxpresso_nxp_lpclink2_4370.zip).

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

4/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

6.Selectallthecomponentsforimportasshownbelow.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

5/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

7.Asshownbelow,choosethelpc_chip_43xxChipandthelpc_board_nxp_lpclink2_4370board.

8.Asillustratedbelow,choose"none"forCMSISDSPlibrary.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

6/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

9.EnablesoftABIasshownbelow.

10.Asshownbelow,disableCRPandcreateincdirectory.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

7/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

11.Asillustratedbelow,leaveExternalmemoryblank(wewillfixthislater).

12.Usenonfloatprintfasshownbelow.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

8/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

13.Asshownbelow,openyournewprojectdirectory,findyourmewproct.cfile,anddoubleclicktoopenit.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

9/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

14.Asillustratedbelow,edittheprojectproperties.

15.Intheprojectpropertiespopupasshownbelow,selectMCUsettings,andclicktoeditthememory
configuration.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

10/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

16.Asshownbelow,editthememortbyfirstclicking"addflash"(redarrow),editingthefields(bluearrows),
movingittotopoflist(blackarrow),addingtheflashdriverbybrowsing(purplearrow),andsavingthe
configuration(yellowarrow).ClickOKtosaveeverything.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

11/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

17.Asillustratedbelow,buildyourproject.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

12/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

18.Aftertheprojectisbuilt,makesuretherearenoerrorsasshownbelow.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

13/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

19.Asshownbelow,attachtheJTAGtoyourLPCXpressocomputerusingtheUSBport,anduseaJTAGcable
toconnecttothetargetboard.Asshownbelow,powerfromtheLPCLink2JTAGboardissuppliedtothe
LPCLink2TargetboardbyconnectingjumperJP1ontheJTAGboardonly.Allotherjumpersare
disconnectedonbothboards.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

14/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

20.Asillustratedbelow,debugasaCNXPMCUApplication.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

15/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

21.Youshouldseeaprompttoselecttheredlinkserver,asshownbelow.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

16/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

22.Asshownbelow,choosetheCortexM4JTAG.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

17/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

23.Asillustratedbelow,clicktheicontorunthecodeonthetargetboard.

24.Clicktheyellowdoublebaricontohalttheprogram,asshownbelow.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

18/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

25.Asshownbelow,addthedisassemblyviewtoseeassemblylanguage.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

19/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

26.Asillustratedbelow,terminatethedebugsession.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

20/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

27.Addthesourcecodeinmain()toblinktheLEDtentimesonthetargetboard,asshownbelow.
//TODO:insertcodehere
volatileintaa=0,bb=0
for(aa=0aa<10aa++)
{
Board_LED_Set(0,false)
for(bb=0bb<8000000bb++)
Board_LED_Set(0,true)
for(bb=0bb<8000000bb++)
}
Board_LED_Set(0,false)

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

21/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

28.Rebuildthecode,andrerunthecode.ThetargetboardLEDshouldblink10times,thenturnoff,asshown
inthemoviebelow,withthetargetboardontheright.

0:00 /0:13

29.Halttheprogram,andterminatethedebugsession..
30.UnplugtheusbfromyourlaptpcomputerfortheJTAGboardtopowerdown.

RampDACExample:FindClockSpeedsandUseGPIOtoDrivea22/28

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

RampDACExample:FindClockSpeedsandUseGPIOtoDrivea
DAC(digitaltoanalogconverter)
1.Makeacopyofyour"tenBlinks"projectbyrightclickingtheproject,copy,paste,andrenamingit
"rampDAC"
2.ThefollowingprojectwilldriveaDAC(digitaltoanalogconverter)onGPIOport1fromconnectorJ9onthe
targettheLPCLink2board.LPCLink2digitaloutputsonconnectorJ9provideaccesstoGPIO1pins04,
12,and13.SowewilluseGPIO1_0asLSB(leastsignificantbit)andGPIO1_13asMSBfortheDAC.
ConnectyourfavoriteDACtotheLPCLink2connectorJ9asillustratedbelow,withthebluearrowpointing
totheDACprototypeboard.

3.Editthenew"rampDAC"projectbyreplacingthepriorcodeinmainwiththefollowingnewcode:

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

23/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

//TODO:insertcodehere
//===========================================================
//begintpwcode
//===========================================================
//blinkLED3timesandturnoff
volatileintaa=0,bb=0
for(aa=0aa<3aa++)
{
Board_LED_Set(0,false)
for(bb=0bb<8000000bb++)
Board_LED_Set(0,true)
for(bb=0bb<8000000bb++)
}
Board_LED_Set(0,false)

//findratesofvariousclocks
//itisusefultoknowyourclockratesindrivingyourDAC
//toseethevaluesonyourchip,halttheprogramandreadthesevariables

volatilestaticlongintsysCoreClk=0,maxSysClk=MAX_CLOCK_FREQ,mainPllClk

volatilestaticlongintchipBaseClk=0,mainPllDivisor=0,xtalClk=0

volatilestaticlongintperiphBaseClk=0,spifiBaseClk=0,hsadcBaseClk=0,us

volatilestaticlongintspifiClk=0,hsadcClk=0,usbClk=0,gpioClk=0

uint32_tsysCoreClk1=0

sysCoreClk1=Chip_Clock_GetRate(CLK_MX_MXCORE)

sysCoreClk=(longint)sysCoreClk1

mainPllClk=(longint)Chip_Clock_GetMainPLLHz()

chipBaseClk=(longint)Chip_Clock_GetBaseClocktHz(CLKIN_CLKIN)

mainPllDivisor=(longint)Chip_Clock_GetDividerDivisor(CLKIN_MAINPLL)

xtalClk=(longint)Chip_Clock_GetClockInputHz(CLKIN_CRYSTAL)

periphBaseClk=(longint)Chip_Clock_GetBaseClocktHz(CLK_BASE_PERIPH)

spifiBaseClk=(longint)Chip_Clock_GetBaseClocktHz(CLK_BASE_SPIFI)

spifiClk=Chip_Clock_GetRate(CLK_MX_SPIFI)

hsadcBaseClk=(longint)Chip_Clock_GetBaseClocktHz(CLK_BASE_ADCHS)

hsadcClk=Chip_Clock_GetRate(CLK_MX_ADCHS)

usbBaseClk=(longint)Chip_Clock_GetBaseClocktHz(CLK_BASE_ADCHS)

usbClk=Chip_Clock_GetRate(CLK_MX_USB0)

gpioClk=Chip_Clock_GetRate(CLK_MX_GPIO)

//useLPCLink2digitaloutputstodriveyourfavoriteDAC
//onconnectorJ9GPIO1pins04and12,13areavailable
//soweuseGPIO1_0asLSBandGPIO1_13asMSB
//belowweclearGPIO1thenseteachbitinsuccession

volatilestaticintnn=0
volatilestaticinticnt=0
volatilestaticintkk=0

//firstconfigurepinsasfastoutputpins

for(nn=0nn<5nn++)

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)
http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

24/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT,(uint8_t)1,(uint8_t)(13))
//createinfiniteloopofDACoutput
while(1)
{
//cleartheoutputdataonportGPIO1
Chip_GPIO_SetPortValue(PC_GPIO_PORT,(uint8_t)1,(uint32_t)(0))
//markthebeginningoftheloopbysettingabithigh
Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t)1,(uint32_t)(1<<4))
//useforloopforashorttimepause
for(kk=0kk<2kk++)
Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t)1,(uint32_t)(0))
for(kk=0kk<2kk++)
for(nn=0nn<5nn++)

Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t)1,(uint32_t)(1<<nn))

for(kk=0kk<2kk++)

}
Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t)1,(uint32_t)(1<<12))
for(kk=0kk<2kk++)
//setGPIO1_13asMSB
Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t)1,(uint32_t)(1<<13))
for(kk=0kk<2kk++)
//cleartheportdata
Chip_GPIO_SetPortValue(LPC_GPIO_PORT,(uint8_t)1,(uint32_t)(0))
for(kk=0kk<4kk++)

icnt++
}

//===========================================================
//endtpwcode
//===========================================================

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

25/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

asshownbelow:

4.Buildandrunthecodeasinthe"tenBlinks"exampleabove.Halttheprogramtoobservethevaribles.The
speedofthewaveformsisdeterminedbytheclocksonyourLPCLink2board.Thesecanobservedinthe
variablestabasshownattheredarrowbelow.Alsonotethedisssssemblyatthebluearrowbelow.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

26/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

5.Whenthe"rampDAC"isrunning,youshouldobserveDACoutputschangingasfollows:

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

27/28

10/12/2016

IntroductiontoProgrammingtheNXPLPC4370MCUUsingtheLPCxpressoToolsandUsingTwoLPCLink2Boards

andzoomingintoobservetheresponsetimeoftheDAC:

6.Whenyoufinishyourmeasurements,halttheprogram,terminatethedebugsession,andunplugtheusb
fromyourlaptpcomputertopowerdowntheJTAGboard.

Notice:Allreferencedbrands,productnames,servicenamesandtrademarksarepropertyoftheirrespective
owners.LPCXpresso_Getting_Started_GuideARMandCortexaretrademarksofARMLimited.NXPisa
registeredtrademarkofNXPSemiconductors.LPCXpressoisatrademarkofNXPSemiconductors.Allother
brandsorproductnamesarethepropertyoftheirrespectiveholders.MacandOSXaretrademarksofApple
Inc.

http://thomasweldon.com/tpw/lpc4370/lpc4370tutorial1/index.html

28/28