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


Moderator First comment on KBA First comment on blog 5 questions asked

Build, Program and Debug your ModusToolbox Application using the Command Line Interface (CLI)

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)





    /* Initialize the USER LED (LED1) as OUTPUT pin in strong drive mode */


    for (;;)






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:


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.