Skip navigation
Home > All Places > Topics > Cypress Community Blogs > ModusToolbox Blog > Blog > Authors DheerajK_81

ModusToolbox Blog

4 Posts authored by: DheerajK_81 Moderator

Welcome to the second session of the ModusToolbox Training Series!

 

In the last session, we set up ModusToolbox, got an overview of the software but we didn't exactly get our hands dirty by creating any applications.

 

In this session, we are going to learn all about Digital Peripherals on the PSoC6 and how you can interact with them using the HAL, the PDL, and the BSP. This session comes packed with plenty of exercises and by the end of it, you will have sufficient knowledge to create applications on our own!

 

Duration: 90 mins

 

Hardware:

The exercises created as part of this training series have been tested to work on the following boards. The exercises might need minor modifications if being used for a different board.

 

Contents:

  1. A quick recap of Session 1
  2. What’s new in ModusToolbox 2.1?
  3. Introduction to Digital Peripherals
    1. PSoC 6 Device Architecture
    2. PSoC 6 Digital Peripherals
      • Programmable Digital
      • Fixed Function Digital
  4. High-Speed Input / Output Matrix (HSIOM)
  5. Smart-IO
    1. Smart-IO Configurator
    2. Look-up table (LUT)
    3. Using Smart-IO in your application
    4. Exercises
  6. TCPWM
    1. Overview
    2. Counter functionality
    3. Understanding HAL
    4. Using Timer in your application using HAL and PDL
    5. Using Counter in your application using PDL
    6. Using PWM in your application using HAL and PDL
    7. Exercises on TCPWM
  7. Serial Communication Blocks (SCB)
    1. Introduction to UART / SPI / I2C
    2. Using SCBs in your application using HAL and PDL
    3. Exercises on SCBs
  8.   Resources

 

Using the Training Material:

The presentation used in the video is attached to the blog. Jump to 4:15s in the video to skip the general introductions and get right to the training.

 

The training material and exercises are hosted here: ModusToolbox Training Session2 Github Repository

 

The file Exercises_ReadMe.pdf attached to the blog highlights the steps to import the exercises into ModusToolbox and use them.

 

In the next session, we will learn about Cypress's industry-leading capacitive touch sensing solution CapSense and how we can create exciting applications using it in ModusToolbox.

 

Have any Questions?

Feel free to drop in your queries in the Cypress Developer Community.

ModusToolbox software is a set of multi-platform development tools and libraries that lets you create interesting applications on your favorite Cypress kits. Due to its vastness, understanding all the features and aspects that come with it might be a challenge! They say a picture speaks a thousand words, so having a video series, you can only imagine how helpful they will be to accelerate this process and we have done just that.

 

Introducing the ModusToolbox Training Series!

 

In the first session, we will have a deep dive into the world of ModusToolbox and understand all the features and capabilities on a high level!

 

Duration: 90 mins

 

Pre-Requisites:

  • Download ModusToolbox™ 2.1 from here.
  • Follow the steps to install it here.
  • Once installed, follow the steps mentioned in the Getting Started Guide to create your first application.

 

Note:

  • If there are firewall restrictions, you need to follow a couple more steps to get your environment configured as mentioned here.
  • If the user name on your system contains spaces or special characters, follow the steps mentioned in the User Guide to install ModusToolbox at a custom location.
  • If application creation fails, please refer to this KBA to get your environment cleaned.
  • Once the application is built, program the kit.
  • If you’ve reached this stage, great! You’re ready for the training!

 

(OPTIONAL) To understand the training better, take some time to go through the following material:

 

Hardware:

The exercises created as part of this training series have been tested to work on the following boards. The exercises might need minor modifications if being used for a different board.

 

Contents:

  1. Introduction to ModusToolbox 2.0
    1. What is ModusToolbox?
    2. What comes with the installer?
    3. Design Goals
    4. Where is the SDK?
  2. Core Tools
    1. Build Infrastructure
      1. Introduction
      2. Creating a project
      3. Autodiscover and project creation
      4. Libraries, .lib files and make getlibs
  • Library Manager
  • Creating an executable
  • Building code from within the IDE
  • Program and Debug
  1. Configurators and Tools
    1. Introduction
    2. New configurators and tools
    3. Utilities
    4. ModusToolbox IDE
  2. Software Enablement
    1. Introduction
    2. Low-level resources
    3. Peripheral Driver Library (PDL)
    4. Hardware Abstraction Layer (HAL)
    5. Board Support Package (BSP)
    6. PDL, HAL, BSP, what do you use?
    7. Middleware
    8. Code examples
  3. Supported Ecosystems
    1. PSoC6 MCU and Bluetooth SoC Ecosystem
    2. MbedOS Ecosystem
    3. Amazon FreeRTOS Ecosystem
    4. Amazon FreeRTOS Libraries
  4. Resources

 

Using the Training Material:

The presentation used in the video is attached to the blog. All the materials that will be part of this training series can be found here: ModusToolbox Training Github Repository

 

This being an introductory session does not have any exercises. In the next session, we will look at the Digital Peripherals in PSoC6 and some cool exercises to crystallize your learnings.

 

Have any Questions?

Feel free to drop in your queries in the Cypress Developer Community.

In the last blog, we created an EmptyPSoC6 application using the Command Line interface.

 

Today we will see how to build, program, and debug the ModusToolbox application all from the command line.  We will write code using Hardware Abstraction Layer (HAL) APIs and also have a short sneak peek into the Visual Studio Code (VSCode) features unlocked with ModusToolbox 2.1.

 

If you didn't already know, ModusToolbox 2.1 is now available and it comes with loads of new features. Click here to find out what’s new.

 

Let's begin! Navigate to the directory where you created your application in the modus-shell command-line.

        

To add code, we will be editing the main.c file using VSCode editor. ModusToolbox 2.1 adds support for VSCode making code development easier. Although it can be used as a fully-fledged IDE, we will be using the VSCode editor only to write code.

Using the command line, navigate to the application directory and run the command

>> make vscode

This command generates json files for debug/program launches, IntelliSense, and custom tasks. Once the command has finished execution, follow the instructions to open the files in VSCode as highlighted below. For more details, refer Section 7.3 Export to VS Code in the ModusToolbox User Guide here.

Once set up, open main.c. We will be developing using HAL APIs. So, type in “cyhal_gpio_” and press CTRL+SPACE. You will see the auto-complete feature offering suggestions.

Based on the hardware driver you want to interact with, type “cyhal_<driver>” to get the API suggestions.

 

Add the following code in main.c:

int main(void)
{
 cy_rslt_t result;

    /* Initialize the device and board peripherals */
 result = cybsp_init() ;
    if (result != CY_RSLT_SUCCESS)
    {
 CY_ASSERT(0);
    }

 __enable_irq();

    /* Initialize the USER LED (LED1) as OUTPUT pin in strong drive mode */
    cyhal_gpio_init(CYBSP_USER_LED, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);

    for (;;)
    {
        cyhal_gpio_toggle(CYBSP_USER_LED);
        cyhal_system_delay_ms(500);
    }
}

 

Save the file. In the command line typemake buildto build your application.

Using the HAL APIs makes the code portable and device agnostic. make provides various options to control the build. To verify that the same code works for a different target board, you can add other BSPs by using the Library Manager. To invoke it run the command

>> make modlibs

 

Now select all the BSPs you want to test the code with and click Apply as shown below.

This will import all the necessary files for the BSPs selected into your application directory.

 

To build the application for a particular target, run the command

>> make build TARGET=<board_name>

Example usage:make build TARGET=CY8CPROTO_062_4343W”.

 

Once the build is complete, the hex file will be generated for the target at this path:

<app_dir>\build\<board_name>\Debug

 

To program the kit i.e CY8CKIT-062-BLE, type

>> make program TARGET=CY8CKIT-062-BLE

 

You should observe the LED blinking on the kit.

 

To start a debug session, you can type

>> make debug TARGET=CY8CKIT-062-BLE

This will start a server which the GDB clients can connect to for debugging as shown below:

You can now open another terminal to use GDB to connect to the target for debugging. GDB is available with GNU Arm Toolchain which comes packaged with ModusToolbox in the path: “ModusToolbox\tools_2.1\gcc-7.2.1\bin\

 

We covered just a few options in make. As an exercise, explore the various options by running the command:

>> make help

Here are a couple of things to try additionally:

  • Program another BSP target without modifying the code and check if the LED is blinking. Run the following command for clues:
    >> make help CY_HELP=TARGET
  • Build the application using a Release build profile and then program the target. Run the following command for clues:
    >> make help CY_HELP=CONFIG
  • Identify the command that programs the application without rebuilding. Run it and check if it works as expected.

 

In summary, we learned how to create an application from scratch, write the application code using HAL APIs, build the application, program it and finally debug it, all without using an IDE.

 

In the next blog, we will see how to open the configurators and write code using the Peripheral Driver Library (PDL) APIs, all using the powerful make command-line options.

Having a GUI makes developing applications more intuitive. The visual feedback and ease of use are really helpful. But, sometimes, I like to use the command line to learn what is happening in the background.

 

So, this blog will be focusing on what happens when you create projects using the Command Line Interface. I’ll show you things you would never usually think about, to give you a different perspective so that you can learn something new.

 

We are going to look into the project-creator-cli tool. But before that, there are some things you need to know about ModusToolbox. It uses Cygwin under the hood and all tools are verified to be compatible with *NIX terminal environments. Based on the OS you are using, you need to keep this in mind:

  • All Linux terminal applications are compatible.
  • All macOS terminal applications (including the Apple-provided Terminal App) are compatible.
  • On Windows, you need to run the “Cygwin.bat” script available inside the “tools_2.0\modus-shell” directory. The Windows “Command Prompt” and “Power Shell” aren’t tested/supported/known to be compatible.

 

Okay, now we are all set. The project-creator-cli tool comes packaged with ModusToolbox and as the name suggests it creates a project.

 

This is the first step you will take while creating any ModusToolbox application. Every command-line tool comes with a “--help” (dash dash help) option to provide information on what it can do. I like playing with my toys first and then looking at the user manual. You can refer to the docs folder for usage documentation but I do that only when I get stuck.

 

So, type in “project-creator-cli.exe --help” to get the list of options. 

Before I can pass in all the arguments, I need information on what kind of values I can provide. As the help info suggests, I can list the boards and applications using the “--list-boards” and “--list-apps <board>” and I’m going to do just that.


Okay great. Now that I have all the information I need, I can pass in the arguments. I’m going to ignore the optional arguments.

>> ./project-creator-cli.exe --board-id CY8CPROTO-062-4343W --app-id mtb-example-psoc6-empty-app

cmd.png

 

The project will be created in the user profile directory by default as shown in the figure above. The project folder will have the same name as the application name.

 

Here is an assignment for you to try over the weekend - Try out the “-d” and “-n” options to create the application in your target directory and to specify the application names respectively.

 

When you create a new application using the Eclipse IDE, this is exactly what happens in the background. Based on the target and application template selected, it passes them as arguments to the backend process that creates the project. That’s the beauty of the command line. It is hard work, but you understand how things flow. I hope this gave you a new perspective and you learned something new today. Stay tuned for more such content!

 

PS: This was my first blog. You will see more from me in the coming few weeks. I am planning to write about building and programming an application all from the command line next. Let me know if you would like to add something else as well.

Filter Blog

By date:
By tag: