Hello Embedded Developers,

 

In this post, I’ll run through a quick example of using ModusToolbox from the Windows command line.  First, let me point you to a couple of reference documents.

  1. Running ModusToolbox from the Command Line – This is shipped with ModusToolbox in the $Install/docs folder and can be found on cypress.com as well (just follow the link).  You will want to refer to this document for additional information, especially if you want to run under Linux or MacOS instead of Windows.  There is also documentation of several make variables available with ModusToolbox.
  2. Cypress Programmer 2.1 OpenOCD CLI User Guide – This is also shipped with ModusToolbox but is located in the $Install/tools/openocd-2.1/docs directory (it’s also on cypress.com). Specifically, you may want to review the Usage Examples chapter.   The path name may vary slightly base on which version of ModusToolbox you have installed.

 

One clarification before I get started: I am not going to cover running configurators or the Mbed command line flow in this post. We will do that separately.

 

OK, first let’s get our Windows environment setup

 

1. We need GNU make.  For Windows, Cypress recommends using a standard make distribution, such as found in Cygwin (uname -r returns “2.11.1(0.329/5/3)” for me).  I use Cygwin64 Terminal to do all my Windows command line stuff.

 

2.  ModusToolbox looks for an environment variable called CYSDK that points to the ModusToolbox installation. I have the following two lines in my Cygwin .bash_profile

 

CYSDK=C:/Users/mdl/ModusToolbox_1.1

export CYSDK

 

Now, let’s build an application

I’ll start with the simple Blinky Application found in $INSTALL\libraries\psoc6sw-1.1\examples\Blinky (see screenshot that follows).

 

  1. Copy that whole directory over into a clean workspace.  Let’s say the new location is C:\Users\<User>\Desktop\BlinkyLED. You can run right from the install location, but I prefer to leave that alone.
  2. Open a Cygwin terminal and go to that directory.
  3. Once I am in the directory, I just type make. The output will look something like this.

 

Be aware that the first build will take a lot longer than subsequent builds for this same project as the shared library, PSoC6_PDL.a, gets compiled the first time.

 

Note: Now is a good time to point out one of my favorite ModusToolbox make variables, DEBUG.  If I experience weird or unexpected behavior, make DEBUG=true is my best friend (observe that DEBUG in all caps and true is all lowercase).

 

4. After a successful build, you’ll see a directory named “build” has been created.  If you’re curious, take a look at the contents of that directory. For example, an ELF file has been created in build/PSoC6_cm4_dual/Debug/mainapp

The file [project name]_mainapp_final.elf in that directory is what we will use to program our device.

5. Optionally edit main.c in the Source directory. For example, I might want to change the blink rate of the LED.  If you edit this file, you obviously need to go up one level in the hierarchy and type make again.

6. As discussed in the Running ModusToolbox from the Command Line document, we have built several handy make targets into ModusToolbox. Let’s use one now!

  1. Plug in your target board (I’m using a CY8CKIT-062-BLE for this example)
  2. type make program (this will program your board with the elf file you just created).

 

Successful programming will end with output that look something like the following.

 

That’s it. You are ready to try some examples on your own.

 

For reference, here is a portion of my .bash_profile. A few notes about it:

  • My user name for this example is “mdl”
  • My ModusToolbox is installed in C:\Users\mdl\ModusToolbox_1.1
  • It’s easy to get tripped up setting CYSDK if you are not careful.  Pay close attention to this.

 

####### excerpt from the .bash_profile file for my Cygwin terminal

 

# Set up environment variable used by ModusToolbox tools

export CYSDK=C:/Users/mdl/ModusToolbox_1.1

 

# I want to run several ModusToolbox tools from the command line

# The following is how I manage that. You don’t have to use this variable

MTB_TOOLS=/cygdrive/c/Users/mdl/ModusToolbox_1.1/tools

 

# Add the ModusToolbox Device Configurator

PATH=$MTB_TOOLS/device-configurator-1.1:$PATH

 

# To Add CapSense Configurator, uncomment the next line

#PATH=$MTB_TOOLS/capsense-configurator-1.1:$PATH

 

# To Add the Bluetooth Configurator, uncomment the next line

#PATH=$MTB_TOOLS/bt-configurator-1.1:$PATH

 

# To Add USB Configurator, uncomment the next line

#PATH=$MTB_TOOLS/usbdev-configurator-1.1:$PATH

 

# You can add similar lines for QSPI, SmartIO, etc.

 

# Add the FW Loader utility (used for various things such as updating kits to Kitprog3)

PATH=$MTB_TOOLS/fw-loader-2.1/bin:$PATH

 

####### End excerpt from the .bash_profile

 

In future posts, we’ll show things like running the configurators from the command line and using the Mbed flow.  Let me know in the comments if there is something specific you would like to see.

 

--Matt