Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Starter Templates for ModusToolbox

Starter Templates for ModusToolbox

markgsaunders
Employee
Employee
50 sign-ins 10 solutions authored 5 solutions authored

I previously wrote about using the New Application wizard in ModusToolbox and showed you the BlinkyLED project. Now I want to show you another template that I believe will be more useful to you in the long run. It is called PioneerKitApp and it supports both the PSoC 6 Pioneer kits - CY8CKIT-062-BLE and CY8CKIT-062-WIFI-BT. When you highlight the template in the wizard it tells you the following about the project.

 

Basic peripheral configuration for the PSoC 6 Pioneer kits (CY8CKIT-062-*). Debug is enabled and platform clocks are set for high performance (144MHz CLK_FAST for CM4 core and 72MHz CLK_SLOW for CM0+) but with a peripheral-friendly CLK_PERI frequency (72MHz). In addition the user LEDs and switch, KitProg3 UART and I2C bridges, and CapSense buttons and slider are  configured.

ModusToolbox templates

My job involves creating a lot of projects and almost every one of them blinks an LED or prints a message to the UART at some point. Depending upon how well my day is going the message might be "PSoC Rocks!" or, if things aren't going so well, something a little less repeatable! But I digress, the point is that I get really fed up of configuring pins and UARTs every day.  So I created a template and my boss told I should share it with you.

 

When you create the application ModusToolbox opens up the file setup_readme.txt automatically. This file describes all the settings I made in the configurator tools... clocks, pins, UART, I2C and CapSense. This means I can start programming without even opening the configurators. For example, here is a program to print a message and toggle an LED. I wrote this code immediately after creating the application without worrying about configuring peripherals, adding middleware (to support printf), picking libraries, choosing part numbers, setting include paths, or any of that nonsense.

 

#include "cy_device_headers.h"

#include "cycfg.h"

#include "cycfg_capsense.h"

#include "stdio.h"

 

int main(void)

{

    int count = 0;

    cy_stc_scb_uart_context_t uart_context;

    init_cycfg_all();

    __enable_irq();

 

    Cy_SCB_UART_Init( KIT_UART_HW, &KIT_UART_config, &uart_context );

    Cy_SCB_UART_Enable( KIT_UART_HW );

 

    for(;;)

    {

        Cy_GPIO_Inv( KIT_LED1_PORT, KIT_LED1_PIN );

        printf( "Message #%d\r\n", ++count );

        Cy_SysLib_Delay( 500 );

    }

}

 

Let's dig in a little. First of all, notice that I am using printf(), which is defined in the usual C stdio.h header file. This is supported by the retarget_io middleware package that adds three files to the application - retarget_io.c, stdio_user.c and stdio_user.h - which you can see highlighted in the project here.

ModusToolbox printf

The "user" files are placed into the Source folder because they are intended to be user-modifiable. In the template I already did that to choose the serial block for the KitProg3 serial-USB bridge (so I can see the output in a PC terminal emulator like teraterm). Here are the settings I made in stdio_user.h.

 

#include "cycfg.h"

/* Must remain uncommented to use this utility */

#define IO_STDOUT_ENABLE

#define IO_STDIN_ENABLE

#define IO_STDOUT_UART      KIT_UART_HW

#define IO_STDIN_UART       KIT_UART_HW

 

Where did that KIT_UART_HW macro come from? Or the KIT_LED_PORT macro for that matter? Well, they got set up in the device configurator. Here is a screenshot of the device configurator, where I have called the serial communication block #3 "KIT_UART" and given it the personality UART_v1.0 (I could have used I2C or SPI instead).

ModusToolbox templates and printf middleware

The configurator generates the KIT_UART_HW macro and the KIT_UART_config variable automatically, so writing the code is easy and fast. I did a similar thing for the LEDs, giving the orange LED the alias "KIT_LED1" so that the tool generates the PORT and PIN macros for me.

ModusToolbox configuration

Next time, I'll show you a variation of this template that sets up FreeRTOS for you so you can get multi-tasking in no time at all.

519 Views
1 Comment
Authors