I have recently shown you two of the most helpful starter templates in ModusToolbox - PioneerKitApp and PioneerKitAppFreeRTOS. Just as an FYI, if you have the PSoC 6 prototyping kit instead, there are equivalent templates for that kit called ProtoKitApp and ProtoKitAppFreeRTOS. All of these templates set up some kit basics for you so that you can jump straight into writing your application code. Essential peripherals like clocks, debugging, LED and button pins, CapSense, plus the I2C and UART bridge peripherals are all pre-configured in the design.modus file. If you do not like our configuration, you are very welcome to launch the configurators and modify the setup the way you need it. How should you go about that?
Well, the short answer is to just double-click on the design.modus file and have a good time! But, since I am feeling a little more helpful that that today, a walk-through of how to set up peripherals from scratch might be good. I'll start with a new project and will use (yet) another project template - EmptyPSoC6App. This template sets up the barest of bare minima - just the clocks and debug.
In the EmptyPSoC6App_config project, find and double-click on design-modus to open the device configurator. There are five panels in the GUI - Peripherals, Pins, Platform, Peripheral Clocks, and DMA. Switch to the Platform tab and you will see the very minimal setup from the template.
In the Resource panel (left) you will see Debug, Power and System Clocks. If you just select each of them in turn you will see, in the Parameters panel (right), that SWD and SWO are enabled for debugging, the power supply is set to 3.3V, and the PLL is configured to generate a frequency of 144MHz. For your early projects there is probably no reason to change any of these values so I'll move on to configuring an LED and button.
Switch over to the Pins tab and open the tree display to see the pins in Port 13. Click on the checkbox next to pin 7 to start setting up the pin. Conveniently, this pin is attached to an LED on both of our Pioneer kits and prototyping kit so this should work on whatever board you have. Start by giving the pin a name (or alias if you want to be fancy) - I am using "LED". Then set the Drive Mode of the pin to "Strong Drive. Iinput buffer off" using the drop-down menu in the parameters panel.
Next repeat that basic sequence for Port 0. Pin 5 is connected to a push button (again, thanks to my pal Ronak who designs all these boards, it is the same pin on all kits) with I am calling "SW". To configure the input choose "Resistive Pull-Up. Input buffer on" drive mode so that my active-low button reads 1 when up and 0 when pressed. Save the edits and switch back to the IDE.
In the EmptyPSoC6App_mainapp project, open the Source folder and double-click on main.c to open it in the editor and write the following code in the infinite loop.
state = Cy_GPIO_Read( SW_PORT, SW_PIN );
Cy_GPIO_Write( LED_PORT, LED_PIN, state );
That is all we need to prove that our configuration works. In the IDE Quick Panel click on "EmptyPSoC6App Program (KitProg3)" and, if you did everything right, it will build the application and program the kit. When you press and hold the button, the LED will turn on...
So, there are the basics for device configuration with ModusToolbox. Next time I'll show you the firmware that makes all this work and get a little more fancy with some PWM tricks and fun with the serial communication blocks.