Skip to main content

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…

01_open_project_2733deaa4bb38f4e6c03ca0eed0f8475838cc629.jpg

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

02_device_type_daa19193dff9d3c53b5c2cf2d5cca23ffe61a47c.jpg

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

03_empty_sch_52008f4fb5989623b0bfe90f54a7c4cfc95f8a58.jpg

Just click ‘next’ for the third party IDEs:

04_third_parties_2e4c26ab000288e7582025f8affe12d8fcc50304.jpg

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

05_create_project_b4d30e90f4994b0635541ad30e1a50def2845213.jpg

We are then presented with a lovely, clean workspace:

06_Workspace_9f55bcc22cad91558c3ac8f022a9a762c95ae7f5.jpg

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:

07_digital_op_pin_bbde5f625edbcdc27fb5e8704e51db77f62c9e9b.jpg

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.

08_select_for_zoom_6db8c2ac151983f09706380c5eecf012078187ee.jpg

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

09_zoomed_96991b4515d787d4bc4302be55eb22da12b55b66.jpg

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

10_configure_ae7e87f4442042ba6a67043ae776f23f1d4f857b.jpg

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:

11_configured_b81debde27c7dd7533a0b008c26240bb56c3d4f3.jpg

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:

12_off_chip_2c23fc690c261884e8284ae6f7ab67e6fee6e883.jpg

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

13_OC_connected_88954e3ff6459f01472bac50fb4d39efed84b186.jpg

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:

LEDs_a0a2e4ca5335c643ffe3359bf00376ccc0b71411.jpg

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:

14_pin_assign_a_25abd7ee326277b0e844d9e059becb68afaa539a.jpg

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:

14_5_272e7048200be68e0ba3e72797a1c739106a7e14.jpg

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:

15_empty_code_c8dc607de4de139c033275ddb39715dd896c68f7.jpg

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

16_code_e56acfecb8021f81579d88fcd4a9ec438e1dc4b5.jpg

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:

30_pwm_clk_1a68cae3280aaf886bea552fc6227e68c4c8b2bf.jpg

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.

31_pin_26cbd3822b3b9b65d8d1cbb7f70188147f947909.jpg

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.

32_pwm_set_a93f4d3d439f49dea75df29f41a78fa699dd7cf5.jpg

Then we will configure our clock to 1 kHz:

33_clk_set_fadc7720f8cefc567136995139a62441b9f1b326.jpg

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.

34_connect_a8af258f4a319eefb632cc2a27ea66550ebed5b0.jpg

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:

35_built_aeb67b602f3c90c48e04eeccfb4571b932ebe3d0.jpg

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 worked in real-time digital signal processing applications engineering for a number of years, before moving into technical marketing.
DesignSpark Electrical Logolinkedin