KitProg: Develop (and debug) for PSoC ARM chips in Eclipse - Page 1
Forum section: electronics / general

author: FriskoxD
author_rank: Newbie
timestamp: June 08, 2016, 07:26:32 pm
content: IntroductionSo you want to develop for PSoC ARM chips in Eclipse? I don’t blame you.Whether you want to have C++ support, develop on a non-Windows OS (this does not include programming and debugging the device), can’t miss some Eclipse features or simply want to try something new, this guide will try to help you out.Before we go any further I want to clear a few things up.First and foremost; this guide does not claim to be comprehensive under all possible scenarios. In fact, for the device programming and the debugging sections it will only discuss the use of the Cypress KitProg programmer.Next; this guide will not give you a great insight in the working of compilers or programming languages.And lastly; there will be a few things that you might be interested in but will not be discussed. A few of these I can think of are:- Using C++ in PSoC Creator. If you want to accomplish this I suggest taking a look athttp://www.mbedded.ninja/programming/microcontrollers/psoc/using-cplusplus-with-psoc-creatorwhich gives you an excellent walkthrough for this exact thing.- Programming the device or debugging with KitProg in a non-Windows OS. I’m sorry, I would love to help you with this, but doing so (at least in this guide) requires PSoC Creator to be installed.By now you’re probably wondering what this guide WILL help you with. So here’s an overview of what will be discussed:1 The requirements2 Setting up the Eclipse environment for compiling2.1 Export the project from PSoC Creator2.2 Create a new Eclipse C++ project2.3 Configuring the project2.4 Excluding folders and files from the Build3 Finding out the name of your KitProg3.1 Using ppcli.exe3.2 Using PSoCProgrammer.exe4 Programming the device5 Debugging using KitProg from within Eclipse5.1 Getting and configuring ConsoleSniffer5.2 Setting up the debug configuration in EclipseOn a more personal note, English is not my first language, so I beg you'll forgive me any lingual boo-boos. Also, this is my first post in the EEVBlog forum so again, there may be mistakes there.But without any further ado let’s get straight into it.1 The requirementsDepending on which features you want to use you will need a few programs. Please keep in mind that this guide might not always use the latest available version of a program. The version being used is marked next to the program. And while I do encourage you to experiment with newer versions, they are not guaranteed to work (even partially).For general development you will need:-Eclipse IDE for C/C++ Developers – Mars.2 (4.5.2)https://www.eclipse.org/downloads/Common tools for device programming and debugging:-PSoC Creator – v3.3 SP2http://www.cypress.com/products/psoc-creator-integrated-design-environment-ideTo debug you will also need a way to control the commands Eclipse sends to GDB. This guide uses an open-source program used Console-Sniffer, which can be obtained fromhttps://github.com/FriskoxD/ConsoleSniffer.The most important thing you will need, however, is a good sense of patience.2 Setting up the Eclipse environment for compiling2.1 Export the project from PSoC CreatorThis step is not absolutely necessary. However, this guide will assume you have done this.The export function generates a prebuild.bat and postbuild.bat file. It also puts CyElfTool.exe and its needed libraries in the Export folder.To export the project you have to:Go toProjectand then select the optionExport to IDE.In the export wizard chooseEclipseand clicknext.Clicktheexportbutton.2.2 Create a new Eclipse C++ projectGo toFileselectNewand thenclickonC++ Project.The new project window:-For theproject name, fill in thesame nametheprojecthasin PSoC Creator.-Uncheck“Use default location” and for the locationbrowseto theproject folderthat has.cydsnin its name.-For theproject type select Executable->Empty Project.-For thetoolchain select Cross GCC.-Click Next twice.-For theCross compiler prefix enter“arm-none-eabi-” without the quotation marks.-For theCross compiler path enterthelocationof yourtoolchain.If you have chosen to use the toolchain provided with PSoC Creator, the default location will be “C:\Program Files (x86)\Cypress\PSoC Creator\3.3\PSoC Creator\import\gnu\arm\4.9.3\bin” without the quotation marks.If you have downloaded the toolchain, locate the bin folder and enter that location.-Click Finish.2.3 Configuring the projectFirst lets open up the properties window. To do this youright clickon theprojectandclickonProperties.Nowclick C/C++ Build, and change theBuilder typetoInternal builder.Nowclickthetriangle next to C/C++ Buildto open it up. ThenclickonEnvironment. Here we are going to add several variables.First you clickaddand undernameyou fill in “PSOC_TYPE”, under value you enter “PSoC5”OR“PSoC4” depending on the device you are using. If you are using a PRoC BLE you’ll want to fill in PSoC4.The next one we’ll beadding has thename“LINKER_OPTIONS” andvaluedepends on which type of PSoC device you are using;For PSoC5:“"${workspace_loc:/${ProjName}}/Generated_Source/${PSOC_TYPE}/cm3gcc.ld" -specs=nano.specs -march=armv7-m -mthumb -mfix-cortex-m3-ldrd -Xlinker --gc-sections”;For PSoC4 or PRoC BLE:“"${workspace_loc:/${ProjName}}/Generated_Source/${PSOC_TYPE}/cm0gcc.ld" -specs=nano.specs -march=armv6-m -mthumb -Xlinker --gc-sections”.The last one we’re going toaddhas thename“BUILD_OPTIONS” and again thevaluedepends on which type of PSoC device you are using;For PSoC5:“-mcpu=cortex-m3 -mthumb”;For PSoC4 or PRoC BLE:“-mcpu=cortex-m0 -mthumb”.Now we are ready to change the toolchain settings. To do thisclick Settings under C/C++ Build. By default this willopenon theTool Settings tab.ClickonIncludes under Cross GCC Compiler. Here we will add two Include paths; The firstInclude pathtoaddis “"${workspace_loc:/${ProjName}}"”; The secondInclude pathtoaddis “"${workspace_loc:/${ProjName}/Generated_Source/${PSOC_TYPE}}"”.NextclickonMiscellaneous under Cross GCC Compiler. ForOther flags enter“-c -fmessage-length=0 ${BUILD_OPTIONS}”.Duplicate the previous steps for the Cross G++ Compiler.NowclickonLibraries under Cross G++ Linker. For theLibrary search path add“"${workspace_loc:/${ProjName}/Generated_Source/${PSOC_TYPE}}"”.NextclickonMiscellaneous under Cross G++ Linker. ForLinker flags enter“-T ${LINKER_OPTIONS}”.The last thing to do in the Tool Settings tab is to configure the Cross GCC Assembler.ClickonGeneral under Cross GCC Assembler.ForAssembler flags enter“${BUILD_OPTIONS}”.NextaddanInclude pathfor “"${workspace_loc:/${ProjName}}"” andadda secondInclude pathas “"${workspace_loc:/${ProjName}/Generated_Source/${PSOC_TYPE}}"”.We will be switching to theBuild Steps tabnow.For thePre-build command enter“"${workspace_loc:/${ProjName}}/Export/prebuild.bat"”.And for thePost-build command enter“"${workspace_loc:/${ProjName}}/Export/postbuild.bat" "${workspace_loc:/${ProjName}}/${POSTBUILD_HEXFILE_PATH}/${ConfigName}/${ProjName}.elf"”.Next switch to theBuild Artifact tab. For theArtifact extension enter“elf”.At this point there is only one setting left to make.Clickthetriangle next to C/C++ Generaland thenclick File Types under C/C++ General.Select Use project settings.ClicktheNewbutton. In the dialogue screenenter“*.s” for thePattern.Click OKand you’re done with this part of the guide.2.4 Excluding folders and files from the BuildWhile not all of the following excludes are absolutely vital to be able to build your project, I find that doing so makes for a clean and easier to understand programming environment.To exclude a file or folder from your project’s build, firstright clickon the file or program, then open theResource Configurationsmenu andclick Exclude from Build….You will want to do this for the following files:-CyBootAsmIar.s(This file can be found under Generated_Source/PSoC5 or Generated_Source/PSoC4)-CyBootAsmRv.s(This file can be found under Generated_Source/PSoC5 or Generated_Source/PSoC4)You will want to do this for the following folders:-codegentemp-CortexM3for PSoC5 devicesOR CortexM0for PSoC4 and PRoC BLE devices-Export-TopDesign3 Finding out the name of your KitProgFor the debugging section you will need to know the name of your KitProg device. As far as I know each KitProg device has a unique name. I will discuss two ways to find out the name of your KitProg.I personally prefer the ppcli.exe way, but the Programmer way is certainly viable too.3.1 Using ppcli.exeOpenacommand window at“C:\Program Files (x86)\Cypress\Programmer”. One easy way to do this is to navigate there using windows explorer, right clicking in the explorer window while holding down the shift key and clicking open command window here.In the command windowtype ppcli.exeandpress enter.Make sure you haveinserted yourKitProgdevice.Type GetPortsandpress enter.Now the name of your KitProg device should appear on the screen. This will be something like “KitProg/0813035502274400”.3.2 Using PSoCProgrammer.exeNavigate to“C:\Program Files (x86)\Cypress\Programmer”.OpenthePSoCProgrammer.exefile.If you haveinserted yourKitProgdevice, the name of it should appear.There are several places you can find the name of the device here, it appears under Port Selection, next to Programmer in the Programmer tab, and under Actions. The name of the KitProg will be something like “KitProg/091D0538012E4400”.4 Programming the deviceFor the moment the only way I can give you for programming the device is by usingPSoCProgrammer.exe. This can be found in “C:\Program Files (x86)\Cypress\Programmer”.Click Fileand thenclick File Load…. This will open up a file browsing window you can use tonavigateto thehexfile you built. This will be in the debug folder of your project (e.g. D:\Documents\PSoC Creator\BasicDesign01\HelloWorld_Blinky01.cydsn\Debug).Once you have selected your hex file,click Fileand thenclick Program.You should see a status bar at the bottom fill up, and when it is done the word “PASS” will appear next to “Powered”.5 Debugging using KitProg from within EclipseWhile everything we’ve discussed so far is rather straightforward, debugging becomes a bit more involved. You will need a way to manipulate the commands Eclipse sends to GDB for this to be successful. In this guide I will be using a program called ConsoleSniffer.If you know about other, less convoluted, ways to accomplish this, I would be delighted to hear about them.5.1 Getting and configuring ConsoleSnifferConsoleSniffer is the program used here to manipulate the commands Eclipse sends to GDB. It can be obtained fromhttps://github.com/FriskoxD/ConsoleSniffer.Configuring ConsoleSniffer happens through an XML file. For your convenience I have added the configuration file ConsoleSnifferEclipsePSoCDebugging.txt to this guide, you will have to change the extension to .xml manually as I am not allowed to attach .xml files.There is one line you will have to customize. In the inputManipulation section of the xml file there is a replace operation that contains “D:\Documents\PSoC Creator\BasicDesign01\HelloWorld_Blinky01.cydsn\Debug\HelloWorld_Blinky01.elf”. You mustreplacethiswiththelocationof your build’s.elffile.5.2 Setting up the debug configuration in EclipseFirst we will have to install the GDB debugging plugin. To do thisgo to HelpandclickonInstall New Software.... Select the repository of your version of Eclipse (in my case this washttp://download.eclipse.org/release/mars).Nowlook fortheC/C++ GDB Hardware Debugging pluginandinstallit.Once the C/C++ GDB Hardware Debugging plugin has been installed we can move on to configuring a debug configuration.To do thisgo to Runandclick Debug Configurations....This has opened up a new window with all your debug configuration possibilities. Locate andclickthe one that statesGBD Hardware Debugging. Then, to create a new configuration,clicktheNew button.The new configuration shouldopenup on theMain tab. The only thing we will be doing here is setting the C/C++ Application. To do thisclicktheSearch Projectbutton, andselectthe.elf file.Note that this will only work if you have already built your application at least once.Switch to theDebugger tab. For theGDB Command enter“{ConsoleSnifferLocation} --snifferArgsBegin -config={ConfigLocation} -logging=false --snifferArgsEnd "{elfLocation}"” where youreplace{ConsoleSnifferLocation}with thelocationofConsoleSniffer.exe(e.g. C:\ConsoleSniffer\ConsoleSniffer.exe),{ConfigLocation}with thelocationof theConsoleSniffer configuration file(e.g. C:\ConsoleSniffer\MyCustomConfig.xml) and{elfLocation}with thelocationof your project’s.elf file(e.g. C:\PSoCProjects\ExampleWorkspace\ExampleProject.cydsn\Debug\ExampleProject.elf).CheckifUse remote targethas been checked. ForJTAG Device select Generic Serialin the dropdown box. And for theGDB Connection string enter“| "C:/Program Files (x86)/Cypress/PSoC Creator/3.3/PSoC Creator/bin/cypsocdebugger.exe" -t PPIO:{KitProgName}” where youreplace{KitProgName}with thenameofyour KitProgas we discovered it in step 3 (e.g. KitProg/091D0538012E4400:1).Now we will deal with theStartup tab. Here you want touncheck all boxes. And that’s all for this tab.Optional:If you want your device to be reset when you start debugging add (notice that you should only enter the content BETWEEN the quotation marks):For PSoC5:"set {int}0xE000EDF0 = 0b00000000000000000000000000000011" - This halts the core."set {int}0xE000EDFC = 0b00000001000000000000000000000001" - This makes sure the core doesn't start running after a reset."set {int}0xE000ED0C = 0b00000101111110100000000000000111" - This resets the device."-break-insert -h -t main" - Sets a temporary beakpoint at the beginning of your code."-exec-continue --thread 1" - Runs the device until it hits the breakpoint at the beginning of your code.For PSoC4/PRoC:I'm not sure which registers should be set, and as I have no PSoC4/PRoC device to test it on, I will not hazard a guess either. If you're feeling experimental you can find a register reference for the PSoC4 devices athttp://www.cypress.com/file/136296/downloadand for PRoC athttp://www.cypress.com/file/137276/downloadThis last step in theCommon tabis optional. Here I would advise you touncheck Launch in background. When this is checked and you click on debug you won’t notice anything happening until the debug has fully started (or failed to start). However, when it is unchecked you will get a progress bar, which is good for those of us who routinely wonder if they clicked the debug button right.And that’s it! Now you’re ready to customize your project further and have fun developing!Edit:-Change subject to make it clear that this guide is about using the KitProg programmer.-Correct a mistake where BUILD_OPTIONS had -c -fmessage-length=0 in it. (This would cause the assembler to fail)-Add parentheses around the linker script, otherwise file paths with spaces in them would make the linker go bonkers.-Remove the code for ConsoleSnifferExampleConfig.txt because it made the text go over 20000 characters.-Add the possibility for resetting PSoC5 devices on debug start.

author: Dielectric
author_rank: Regular Contributor
timestamp: June 08, 2016, 08:01:19 pm
content: Cool guide, I tried it a few times and got my project to build, but I stumbled setting up the debugger. I was trying to use the CMSIS-DAP mode on the newer kits, do you know anything about getting GDB to talk to that?

author: FriskoxD
author_rank: Newbie
timestamp: June 09, 2016, 09:47:42 am
content: Quote from: Dielectric on June 08, 2016, 08:01:19 pmNo, I haven't played around with that (yet). It seems interesting, though. I wonder if it has the same kind of quirks KitProg has, where sending GDB commands like -thread-info causes the running thread to be locked up/deleted somehow.