DesignSpark Electrical Logolinkedin
  • Brought to you by
  • RS Components
  • Allied Electronics

September 5, 2017 14:41


PSoC 6 Introductory Tutorial

The new PSoC 6 BLE Pioneer Kit (136-7817) – Cypress Semiconductor’s latest offering to the 32-bit microcontroller world – is one of those things that remind me how much things have changed for embedded developers. You can watch an introduction to the PSoC 6 on this video:

The first purpose-made dev kit I ever had the chance to use, as a student at the end of the 80’s, was built around an Intel 8501 microcontroller which came with a whopping 4 KiB ROM and 128 bytes of internal RAM (yes, youngsters: that is bytes, no ‘K’).

Even for the time, the kit was kind of primitive as it had been designed by one of our lecturer’s to force the user down to machine level. Programming it meant using a hexadecimal keypad to manually enter the hex values of the 8051 opcodes and the operands you wanted to work with.

After some purgatory time entering this data, you would then set the 8051 running to flash on-board LEDs as proxies for whatever I/O endpoints you were simulating on the four 8-bit bi-directional input/output ports. In my case, I was simulating actuators and motors on a washing machine as we went through a set of simple wash cycles.  

Despite this jarring introduction, I quite liked the 8051 and went on to use it in a couple of later designs of my own. The up side of the primitive dev kit was that subsequent programming in assembler seemed like a major step up and discovering embedded C was like being given ambrosia by the gods.

By contrast, when you look at the feature list for the Cypress Semiconductor PSoC6, it’s hard not to be impressed by how much stuff can be crammed onto a tiny silicon footprint and, perhaps even more importantly, how much easier it is to setup and program all that stuff.

However, if you are new to Cypress and their ‘PSoC Creator’ development tools, all the features and API software support provided in this Integrated Development Environment (IDE) can be a little overwhelming. In this article, I will try to decrease the intimidation factor by walking through the tool flow for the embedded version of a “Hello World!” program – setting up and toggling an on-board LED.

Getting Started

When you first fire up PSoC Creator you will be presented with a window similar to this one below. To open a new workspace, we need to click on File > New > Project…

We now need to select the target device from the pull-down menus – PSoC 6, in our case – and click ‘next’:

And then select an ‘Empty schematic’ for our project template and click ‘next’:

Just click ‘next’ for the third party IDEs:

Finally, we can give our project a name that is a bit more descriptive than the default of ‘Design01’ and click ‘Finish’:

We are then presented with a lovely, clean workspace:

Note - if you are having trouble seeing the detail on any of these screenshot images, simply right-click on the image and select 'View Image' at the top of the context menu to see the full size image.

Anyway, on the left side of this workspace is the ‘Workspace Explorer’ which tracks all the files related to your project.

On the right hand side of the workspace, you find the ‘Component Catalog’. This holds a large number (over 100) of configurable components that are built into the fabric of the PSoC 6 and are usable in your system designs.

The centre window, labelled ‘TopDesign.cysch’ by default, shows the schematic editor where we can place, configure and connect together the components from the Component Catalog.

The lower centre window is where PSoC Creator lets you know what it is doing. This is the output from the compiler and system builder.

OK, so now we are up and running, let’s get started on…

Our First System

We are going to start with pretty much the simplest possible system for a PSoC board, as this gives us the chance to go through the tool flow without the distraction of a lot of complexity.

Go to the Component Catalog and select ‘Ports and Pins’. You can then drag and drop a Digital Output Pin to the schematic editor window:

You will probably notice that the pin we drag across is pretty tiny. We can zoom in by clicking the magnifying glass with the ‘+’ (at the top left) a few times, or (as I prefer) press the [Ctrl] key and use the left mouse button to drag a box around the area you want to magnify.

We now have a pin we can actually see. A single click on the component will highlight it in green:

Double click on the part (or right click and select ‘Configure’ from the context menu) to bring up the part’s configuration window:

We can now set this pin up to drive the blue LED on the PSoC 6 development board. First, we change the name of the pin to ‘LED_Blue’. We are going to use the PSoC’s firmware fabric to drive the LED rather than a direct hardware connection, so we need to deselect that check-box:

When we click on ‘OK’, we can see the name of the pin (and its shape) will have changed.

If you now look back at the Component Catalog, you can see that there is a second tab named ‘Off-Chip’. These components have no physical effect on the system we are designing. Instead, they allow us to draw out what our external pins are connecting to: kind of like a hardware version of comments in software source code. This is, of course, completely optional but can – like source code comments -be really useful when you come back to modify your design six month down the line.

So let’s add these external components into our system by dragging and dropping a resistor from the Passives menu, a LED from the Diodes menu and a ground from the Power menu:

We can now use the wiring tool (shown by the arrow below or use the [W] key) to connect the components together.

With that done, we are free to tell the system what pin our blue LED is actually connected to in the physical world. If you have incredible eyesight and/or a magnifying glass, you can get the information from the silkscreen on the board, next to the RGB LED itself:

You might be able to work out from the image that B (blue) is 11.1 (port 11, pin 1). Feel free to experiment with the red (port 0, pin3) or green (port 1, pin 1) LEDs as we go through this tutorial. You can, of course, get this pin information in the accompanying PSoC 6 documentation.

To assign this pin to our design, go to the Workspace Explorer and double click on ‘Pins’, under Design Wide Resources. This will bring up the pin map of the PSoC 6 device:

You can see that our pin (LED_Blue) is already in the list for us to assign. Use the ‘Port’ pull-down menu to find P11[1] in the list and select it. Our pin is now highlighted in the BGA map and we can see that it maps to physical pin E5 of the BGA:

We are now set to build our system! Click on Build > Build Hello World

There will be some whirring and some output to the Output window. What we want to see at the end of this output is ‘---- Build Succeeded: date time -----‘ where ‘date’ and ‘time’ are replaced by your current date and time.

Programming the PSoC 6

Now that we have defined our system, it’s time to give it something to do.

That requires a little C programming. When I say ‘little’, I really do mean a small amount of code, due to the extensive software support underlying the PSoC 6 Application Programming Interface (API).

For our purposes, we are going to use the low-power ARM® Cortex® M0+ core. We could equally use the M4 core but whichever one we use, we don’t have to worry about the other core that we are not using – we can just leave it alone, without any code.

To get started, go to the Workspace Explorer and double click on main_cm0p.c. This will open up in our central window and comes complete with a basic skeleton for our program:

We can then add in our program to this skeletal outline:

I will go into API functions a little later, but for now you can see that our program simply uses a GPIO write function to write ON and OFF values to our LED pin. We add in a delay of 500 (milliseconds) between each switch so that the LED toggling is slow enough for us to see.

OK, let’s go for broke! If you haven’t already got your PSoC 6 connected to your PC via the USB cable supplied in the kit, get it connected now.

All we have to do now is go to Debug > Program (or hit Ctrl+F5 or use the program icon, whatever you prefer) and wait for the program to compile and download. The first time may take a little while to compile as there is a fair amount of underlying ‘generated source’ to put together. Once that’s done we are rockin’ and rollin’:

Yea us!

Taking Things Further

So maybe you think flashing an LED is beneath an MCU of the stature of an ARM Cortex? OK then, let’s do this a different way and hopefully learn a few more things.

Go back to our TopDesign.cysch tab in the central window. We are going to use a PWM to flash our LED rather than the processor core. We can find one by typing ‘pwm’ into the search box (where it says ‘Search for..’) at the top of the Component Catalog window. This will lead us to Digital > Functions > PWM (TCPWM)[v1.0]

Drag the PWM into the design and we will also need a clock, so drag one of those over too:

Info Dump:

Now is a good time to take a quick aside. You may have been wondering how you can find out what API functions are available to the components in the Component Catalog. The simplest way is right in front of us.

With the PWM selected, you can see a description box, at the bottom right, underneath the Component Catalog window. This box also contains a link to the PDF datasheet for the component, labelled Open datasheet. This datasheet contains all the usual stuff like I/O connection descriptions, functional parameters and component characteristics.  It also has an Application Programming Interface section describing the component wrapper functions available to the part. We can use this information to help us control our parts’ functionality in software.

Setting Up Our Components

Before we can use the new parts we have just put on the design schematic, we will need to set them up.  The first component we need to change is our trusty digital output pin. Double click on it to bring up the configuration window.

We need to re-enable the ‘HW connection’ check box to allow us to connect other internal components to the pin. When you do that and click OK you will see that our pin has changed and now has an input box we can connect things to.

Next we want to set up our PWM. Double click on that to bring up its configuration box. As we only have one PWM, we may as well rename it simply as ‘PWM’. In the ‘Basic’ tab, take the scroll bar down to the bottom and set the period to 1000(ms). To make it a little more interesting, I gave our LED a very short 50(ms) duty cycle, giving our flash more of a strobe effect, which can make it a bit more noticeable to the peripheral vision of the human eye.

Then we will configure our clock to 1 kHz:

Lastly, we need to wire up our little schematic with the wiring tool. Our clock is connected to the clock input and pwm_n connects to our output pin. Note that in this case our wires are green. Should you connect any analogue signals in your designs, these will be orange.

We are now ready to build our project. You can use Build > Build Hello World or just hit [shift]+[F6] (or use the ‘Build’ icon) – there are usually a handful of ways to get each job done. While the project is building, you will be able to see the APIs for each of our components start to assemble themselves under the ‘Generated Source’ folder in the Workspace Explorer.

All that remains now is to program our device. Because of all the underlying software work that Cypress have already done for us, our program is one solitary line of C code - a call to the PWM_start() function:

Use Debug > Program (or [Ctrl] + [F5], or the ‘program’ icon) to compile and load our program to the PSoC 6.

Yea, us! We have a differently flashing blue LED!

Now that the PSoC Creator IDE is a little less scary, you can start to pick apart the example software that Cypress has created for the board. At the time of writing, there are three pretty comprehensive examples:

  1. CE218133 – EINK Display with CapSense®: demonstrates how to create a user interface using the EINK display and the capacitance sensing buttons and slider on the board.
  2. CE218134 – BLE with CapSense®: demonstrates transferring CapSense and control data via Bluetooth Low Energy with the PSoC 6 acting as a BLE peripheral and GATT server.
  3. CE218135 – BLE with Proximity: PSoC 6 acts as a BLE peripheral and GATT server for a custom service transferring CapSense proximity sensing information.

A large proportion of the functionality in these software examples can easily be used to form the basis of many other projects.

Final Thoughts

It makes sense to use the right tool for the job when you want the job done well. Microcontrollers are the right tool for embedded digital control applications. Sure, it can be great fun to fudge things with a Raspberry Pi or any one of the other small dev boards on the market, but for commercially viable designs where size, cost, power consumption and predictable (low) interrupt latencies are important factors, microcontrollers are still the way to go.

Manufacturers like Cypress are making it easier than it has ever been to quickly create system designs requiring a minimal amount of external components, while supplying full-featured (but low cost) development kits and software environments to speed up the development cycle. The barriers to entry for the embedded system market have never been lower.

So what are you waiting for? Get embedding microcontrollers in everything!


Mark completed his Electronic Engineering degree in 1991 and went on to work in real-time digital signal processing applications engineering, later moving into technical marketing.

September 5, 2017 14:41



1 Votes

September 10, 2017 08:55

I believe that to work with a PSOC 6 device, Creator 4.2 is required. The highest version that is available today is Creator 4.1 Update 1, at least that is what I can see on the cypress site. You might want to talk about that so that folks don't waste time searching for something that is not yet generally available.


September 12, 2017 10:47

@lgarnand Thanks for your comment. You are correct that support for PSoC 6 will be with PSoC Creator 4.2 which should be available later this month.