Recently Cypress updated their PSoC Creator tool suite to version 3.0.
V3.0 Brought with it some great new features, such as:
- Auto Complete
- Goto Definition
- Code Explorer
- Inline Diagnostics
- Disabled code highlighting
- Automatic indenting
- And loads of other productivity and compiler improvements.
However as I have mentioned in this post before, the tool dropped support for the PSoC 5 Chip, which has been superseded by the fantastic new PSoC5LP Device. There are drop in replacements for every PSoC5 chip from the new 5LP Range. Cypress encourage developers to use the new 5LP devices in their new projects and when updating existing projects. The 5LP are pin and source-code compatible with the equivalent 5 Devices, but they are not binary code compatible. You need to rebuild your code with the new device selected in PSoC Creator.
But what do you do if you have an existing product, using PSoC5 devices that is out there in the field, all new boards that you manufacture should have 5LP on them, and you have to maintain and update the code on these boards? You cannot just build a project in the new tools and target the two devices – because the latest tools no longer support PSoC5, just the new PSoC5LP.
It seems there are two options:
- Stick with the old tools and mis-out on all the new features of the IDE
- Fork the project, and build for PSoC5 using Creator v2.2 and build for PSoC5LP in Creator 3.0.
In the first option you miss out on all the great new features of Creator 3.x, but you only need to maintain one set of code. In the second option you get all the new features, but you have to maintain two sets of code, and make the same updates to both of them.
What I’d like to propose is that there is in fact a third option, that allows you to write and maintain all your code in the lovely new Creator 3.x IDE, but at the same time build the project for both PSoC5 and PSoC5 LP based boards. In fact, even if you only target PSoC5 and not 5LP you can still do all your code editing in the new IDE. You never again need to use ‘batch find’ just to jump to a declaration!
The third option is to have two projects, one in Creator 2.2 for your PSoC5 boards, and one in Creator 3.0 for your PSoC5LP Boards, but – and here’s the deal – you have only one set of source code and it lives in both projects. You make all your source code changes using the Creator 3.0 IDE and your Creator 2.x project is automatically kept in-step. Since both are sharing the same source files you don’t have to do anything to keep them both in sync.
So here’s is my step-by step guide to help you understand the process of getting a single code base to work for both PSoC5 and PSoC5 LP based boards, and getting to use Creator 3 to maintain the code for both.
In this guide I’m going to demonstrate all the steps required by taking a simple existing PSoC5 Project in Creator 2.2 and going through all the steps to allow me to build the same code for two versions of a board, one containing a PSoC5 and one containing a PSoC5LP device. The project is a simple LCD Clock which shows hours/minutes/seconds on and LCD display, while at the same time counting the number of times a couple of push buttons are pressed, and lighting a couple of LEDs whenever either of the buttons are pressed. The boards I’m using a 2 x Cypress CY8KIT-050 Development kits, one has a PSoC5 the other a 5LP. The choice of Switches, LEDS and LCD along with an RTC allows me to demonstrate the following:
- Digital Input Pins
- Digital Output Pins
- LCD Display
- Real Time Clock (RTC)
- External crystals for both Main Oscillator (24 MHz) and RTC (32.678 KHz)
…and shows that they all still work afterwards.
You don’t need two dev kits, you should be able to follow the steps using your own boards. I decided to use the two kits as it shows two otherwise identical boards, with just the PSoC Chip different between them.
You must have Creator 2.2 and Creator 3.0 installed. They can be downloaded for free from the following locations:
- PSoC Creator latest version (Currently 3.0) can be found here.
- PSoC Creator version 2.2 can be found here.
First ensure that your project is targeting the PSoC5 Device, and that it opens, builds and programs without error from PSoC Creator 2.0
Now locate the top level project folder on your disk and take a backup of it and all it’s contents, so that you can easily restore it again, should anything go wrong. The project I am using I’m calling ‘LCD_Clock’. You can download the original project from here, which was the starting point for this guide, before any of the other steps were carried out.
Step 1 – Duplicate the project folder and rename it.
The first thing to do is copy the entire project folder and place it side by side with the existing project. Rename the new folder to something useful. I called my original project LCD_Clock_5 and the new folder LCD_Clock_5LP.
Step 2 – Open the new project in Creator v3.0
The next step is to open the project from the new folder using Creator 3.0, do not open the original project in Creator 3.0 – we will keep this one for re-opening later in Creator 2.2. We must use the project from the new folder because Creator 3.0 will immediately try to update the project for the new version of the IDE.
When you open the project in v3.0 the first thing that will happen is that Creator will identify that the project targets a PSoC5 device, and notify you that the part has been trimmed from the Cypress product catalog, and prompt you to select a new alternative device. It will recommend an alternative based on the original parts properties. In my case the original part was CY8C5568AXI-060 and it recommended the new part CY8C5868AX-LP032. If the recommended part does not match exactly with the actual chip you’ll be using, click on ‘choose another replacement’ in the dialog and use the part selector to chose the exact part.
In my case, the new dev kit I was using actually had a slightly different part than was being suggested, so I used the component selector to select the correct part – CY8C5868AX-LP035. Click on OK to accept the new recommended device. For me this dialog then re-appeared and I had to select the part again. The reason it appeared twice for me was because in the project are two configurations, Release and Debug and you must select the part for each configuration. This is not obvious and is not shown in the dialog anywhere.
Step 3 – Component Update
Once you have selected a new device part number, Creator will prompt you to update the components in your project. These are the Library Components which are used in your Top Design, such as Pins, RTC, Character LCD etc.
Leave all the settings as they are and click Next for a summary of all the components which will be updated. At this stage you can un-tick the option ‘Archive before committing’ as you already have a copy of the original project – remember we took that in the ‘Preparation’ step above.
Step 4 – Rename the Project and Workspace
This step is important just to ensure that there can be no confusion between the project targeting the 5LP and the project (which we haven’t touched yet, and still lives peacefully at home in it’s original location) which targets the 5.
In the project explorer window, right-click on the Project Name and select ‘Rename’, give the project a useful name, in my case I selected ‘LCD_Clock_5LP’.
Do the same for the Workspace Name.
Step 5 – Correct any Build Errors
You might think that the project should be able to build and run without any errors, after all we haven’t changed any design or source code. However we have selected a new part, and the new 5LP parts do have some differences between their sibling 5 parts.
So hit ‘build’ and see if there are any build errors before continuing.
In my case there were several errors, all of which seemed related to the clock settings. Lets correct these errors before we go any further. It happens that my project uses the external crystal (XTAL) and that there are some new dependencies with XTAL in 5LP. If your project doesn’t use the external XTAL you may not see these errors or you may see a totally different set.
So we need to correct these build errors. To do this, lets take a look at our clock settings.
In the Project Explorer window, open your design wide rules window by double-clicking on your project’s .cydwr file. In my case this file is named ‘LCD_Clock_5LP.cydwr’. This will take you to the Design Rules editor. At the bottom of the page click on the ‘Clocks’ tab, and then double click on any of the clock entries.
Here we can see that the red bang is on the ‘Watchdog’ parameter in the ‘Reference Levels’ section. Currently it is set to 0 and hovering the mouse over the red bang we see a message that reads “When the XTAL is running at 16 MHz or faster, the watchdog reference level must be 3 or greater’.
Now we can see that all the red-bang marks have gone away and Creator is happy with our clock settings.
This highlights that although the 5 and 5LP are pin and source compatible, there are some silicon differences, and you should make yourself aware of these and ensure there are no pitfalls that could scupper your project. For more details on the differences between 5 and 5LP read the migration guide which you can find here.
Now we can try to build the project again, and hey-presto, we get a clean build. Now we have this new project targeted for the new 5LP device and giving a clean build. Program it to a board with 5LP on board and confirm that it works as expected.
Step 6 – Quick review of where we are now.
Now we have 2 projects, in two folders. One, the original project, which we haven’t touched yet except to backup and copy, which still targets the PSoC5 device, and a new project in a new folder, which targets the 5LP equivalent device. We have corrected any build errors that crept in due to 5 vs 5LP silicon differences, and we have renamed the project and the workspace. All of the above steps are normal steps that you would take if you were migrating your design and your project from 5 to 5LP, and from Creator 2.2 to Creator 3.0.
In the next few steps we will go back to our original PSoC 5 project and make some changes so that it finds it’s code in a new place, where both the 5 and 5LP workspaces can use the same code.
Step 7 – Deleting the source code from the Creator 2.2 Project.
What we will do now, is remove the non-generated code from the project, and replace it with links to the same code in the new project. This will make both projects share the same physical files on disk, so when we edit the code in one project it will be changed in the other project too. We could of course edit the code in any of the Creator versions, but that defeats the purpose of using the new editor with old PSoC5 projects!
We will not delete any of the Generated Code, as they may be different between versions of Creator. We won’t be sharing any of the generated code between projects, and we won’t be sharing the Top Design or Design Wide Rules files, because these will be version specific. The non-generated code – i.e. the code which YOU have written can easily be shared between projects.
Close Creator 3.0 and ensure you have Creator 2.2 loaded, with the PSoC 5 project open.
If you have all your code in a single main.c file, then this step will be quick for you! If, like me, you like to sub-devide your code into various .h and .c files, then there is just a little more work to do.
In my sample LCD_Clock_5 project, I have two header files and two C files. These are:
To begin, right-click on each file in the project explorer under ‘Header Files’ and select ‘Remove from <Project Name>’
For each file you will see this warning dialog asking you if you wish to permanently delete the files from disk. Answer YES for each file. Remember we took a back-up of the project back at the start, so don’t worry about deleting these files.
This will remove the file reference from the project, as well as physically removing the file from the disk. That way there can be no confusion over which files we are actually working with.
Repeat this process by highlighting each file in the ‘Source File’ section of the project explorer as well. You should now have deleted all the .h and .c files from your project – but remember do not delete anything from the ‘Generated Source’ section!
Step 8 – Adding in references to the same files in the new PSoC5LP project.
Now we will replace the deleted files with references to the same files over in the other, 5LP Project.
Still working in the Creator 2.2 project, right-click on ‘Header Files’ in the project explorer and select ‘Add’ and then ‘Existing Item…’ and browse to the source folder in your new 5LP project. Select each header file, the same ones we just deleted from the ‘5’ project, and click ‘Open’. This will add a reference for each of these files to the project.
Do the same thing for each Source (.c) file by right-clickin on ‘Source Files’ and select ‘Add’ and then ‘Existing Item…’, browse to the source files and click ‘Open’
You now have two projects, one in Creator 2.2 Targeting the PSoC5 chip and on in Creator 3.0 Targeting the 5LP chip. They both have their own, version specific, Top Design, Design Rules and Gnerated Code, but they are sharing the user edited source code.
Step 9 -The Build Settings.
If you try to build the project now, in Creator 2.2 you’ll see that the build fails, and the output window says ‘fatal error: device.h: No such file or directory’ – don’t panic! This is to be expected, and we are going to resolve this issue now. Whats wrong here is that Creator has not told the compiler the explicit paths to the header files we added. It only looks under the current project folder, despite the fact we added references to the actual files over in the new project. We can easily resolve this issue.
Click in the field beside ‘Additional Include Directories’ and add a new entry by clicking on the ‘…’ button.
Select ‘New’ in the dialog that appears and either type the path to the header files in the 5LP project, or use the ‘…’ button to browse for them. Click on OK and your Additional Include Directories should now include a path to the header files in the 5LP project. Click OK to dismiss the dialogs and save the new settings.
Now if you build the project, you should get a clean build with no errors.
Step 10 – Sit back, enjoy your handiwork and develop for PSoC5 using Creator 3.
You should now have two projects, one in Creator 2.2 that targets the PSoC5 chip and one in Creator 3.0 that targets the 5LP device. Both should build without errors and any changes you make in the source code of one project should be immediately reflected in the source of the other, after all they are the same sources!
You can now use the nice new features of Creator 3.0 to edit code which runs on the PSoC 5.
Use creator 3.0 for all your source code edits, and to build for, and program, PSoC5LP devices. When you want to build for and program PSoC5 devices open the project in Creator 2.2 and build the project and program your devices.
One last thing.
Only the source files (.h and .c) can be edited in both projects by opening them just once, in Creator 3.0 and making the edits. Unfortunately if you make any changes to the TopDesign or Design-Wide rules, you’ll have to do that in both projects.