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 at
http://www.mbedded.ninja/programming/microcontrollers/psoc/using-cplusplus-with-psoc-creator which 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 requirements
2 Setting up the Eclipse environment for compiling
2.1 Export the project from PSoC Creator
2.2 Create a new Eclipse C++ project
2.3 Configuring the project
2.4 Excluding folders and files from the Build
3 Finding out the name of your KitProg
3.1 Using ppcli.exe
3.2 Using PSoCProgrammer.exe
4 Programming the device
5 Debugging using KitProg from within Eclipse
5.1 Getting and configuring ConsoleSniffer
5.2 Setting up the debug configuration in Eclipse
On 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 SP2
http://www.cypress.com/products/psoc-creator-integrated-design-environment-ide To 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 from
https://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 to
Project and then select the option
Export to IDE.

In the export wizard choose
Eclipse and click
next.
Click the
export button.
2.2 Create a new Eclipse C++ projectGo to
File select
New and then
click on
C++ Project.

The new project window:
-For the
project name, fill in the
same name the
project has
in PSoC Creator.
-
Uncheck “
Use default location” and for the location
browse to the
project folder that has
.cydsn in its name.
-For the
project type select Executable->Empty Project.
-For the
toolchain select Cross GCC.

-
Click Next twice.
-For the
Cross compiler prefix enter “
arm-none-eabi-” without the quotation marks.
-For the
Cross compiler path enter the
location of your
toolchain.
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 you
right click on the
project and
click on
Properties.
Now
click C/C++ Build, and change the
Builder type to
Internal builder.

Now
click the
triangle next to C/C++ Build to open it up. Then
click on
Environment. Here we are going to add several variables.
First you click
add and under
name you 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 be
adding has the
name “
LINKER_OPTIONS” and
value depends 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 to
add has the
name “
BUILD_OPTIONS” and again the
value depends 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 this
click Settings under C/C++ Build. By default this will
open on the
Tool Settings tab.
Click on
Includes under Cross GCC Compiler. Here we will add two Include paths; The first
Include path to
add is “
"${workspace_loc:/${ProjName}}"”; The second
Include path to
add is “
"${workspace_loc:/${ProjName}/Generated_Source/${PSOC_TYPE}}"”.

Next
click on
Miscellaneous under Cross GCC Compiler. For
Other flags enter “
-c -fmessage-length=0 ${BUILD_OPTIONS}”.
Duplicate the previous steps for the Cross G++ Compiler.
Now
click on
Libraries under Cross G++ Linker. For the
Library search path add “
"${workspace_loc:/${ProjName}/Generated_Source/${PSOC_TYPE}}"”.

Next
click on
Miscellaneous under Cross G++ Linker. For
Linker flags enter “
-T ${LINKER_OPTIONS}”.

The last thing to do in the Tool Settings tab is to configure the Cross GCC Assembler.
Click on
General under Cross GCC Assembler.
For
Assembler flags enter “
${BUILD_OPTIONS}”.
Next
add an
Include path for “
"${workspace_loc:/${ProjName}}"” and
add a second
Include path as “
"${workspace_loc:/${ProjName}/Generated_Source/${PSOC_TYPE}}"”.

We will be switching to the
Build Steps tab now.
For the
Pre-build command enter “
"${workspace_loc:/${ProjName}}/Export/prebuild.bat"”.
And for the
Post-build command enter “
"${workspace_loc:/${ProjName}}/Export/postbuild.bat" "${workspace_loc:/${ProjName}}/${POSTBUILD_HEXFILE_PATH}/${ConfigName}/${ProjName}.elf"”.

Next switch to the
Build Artifact tab. For the
Artifact extension enter “
elf”.

At this point there is only one setting left to make.
Click the
triangle next to C/C++ General and then
click File Types under C/C++ General.
Select Use project settings.
Click the
New button. In the dialogue screen
enter “
*.s” for the
Pattern.
Click OK and 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, first
right click on the file or program, then open the
Resource Configurations menu and
click 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-
CortexM3 for PSoC5 devices
OR CortexM0 for PSoC4 and PRoC BLE devices
-
Export-
TopDesign
3 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.exeOpen a
command 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 window
type ppcli.exe and
press enter.
Make sure you have
inserted your
KitProg device.
Type GetPorts and
press 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”.
Open the
PSoCProgrammer.exe file.
If you have
inserted your
KitProg device, 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 using
PSoCProgrammer.exe. This can be found in “
C:\Program Files (x86)\Cypress\Programmer”.
Click File and then
click File Load…. This will open up a file browsing window you can use to
navigate to the
hex file 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 File and then
click 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 from
https://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 must
replace this
with the
location of your build’s
.elf file.
5.2 Setting up the debug configuration in EclipseFirst we will have to install the GDB debugging plugin. To do this
go to Help and
click on
Install New Software.... Select the repository of your version of Eclipse (in my case this was
http://download.eclipse.org/release/mars).
Now
look for the
C/C++ GDB Hardware Debugging plugin and
install it.

Once the C/C++ GDB Hardware Debugging plugin has been installed we can move on to configuring a debug configuration.
To do this
go to Run and
click Debug Configurations....

This has opened up a new window with all your debug configuration possibilities. Locate and
click the one that states
GBD Hardware Debugging. Then, to create a new configuration,
click the
New button.

The new configuration should
open up on the
Main tab. The only thing we will be doing here is setting the C/C++ Application. To do this
click the
Search Project button, and
select the
.elf file.
Note that this will only work if you have already built your application at least once.
Switch to the
Debugger tab. For the
GDB Command enter “
{ConsoleSnifferLocation} --snifferArgsBegin -config={ConfigLocation} -logging=false --snifferArgsEnd "{elfLocation}"” where you
replace {ConsoleSnifferLocation} with the
location of
ConsoleSniffer.exe (e.g. C:\ConsoleSniffer\ConsoleSniffer.exe),
{ConfigLocation} with the
location of the
ConsoleSniffer configuration file (e.g. C:\ConsoleSniffer\MyCustomConfig.xml) and
{elfLocation} with the
location of your project’s
.elf file (e.g. C:\PSoCProjects\ExampleWorkspace\ExampleProject.cydsn\Debug\ExampleProject.elf).
Check if
Use remote target has been checked. For
JTAG Device select Generic Serial in the dropdown box. And for the
GDB Connection string enter “
| "C:/Program Files (x86)/Cypress/PSoC Creator/3.3/PSoC Creator/bin/cypsocdebugger.exe" -t PPIO:{KitProgName}” where you
replace {KitProgName} with the
name of
your KitProg as we discovered it in step 3 (e.g. KitProg/091D0538012E4400:1).

Now we will deal with the
Startup tab. Here you want to
uncheck 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 at
http://www.cypress.com/file/136296/download and for PRoC at
http://www.cypress.com/file/137276/download 
This last step in the
Common tab is optional. Here I would advise you to
uncheck 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.