Well, I did not get a visit from any of the VPs I was being rude about yesterday, so I can start showing you some of the ways to do cool projects with ModusToolbox. I usually dive straight into the IDE for things like this but I have lots of options with ModusToolbox so I will start with a simple command-line example instead. This will demonstrate the four fundamental steps involved in making a program.

  1. Clone a starter project from GitHub
  2. Pull down all the required libraries - startup code, board support, CapSense and so on
  3. Build
  4. Program

If you have installed ModusToolbox 2.0 already, then you can follow all these steps (only step 4 requires a kit). If you have not installed ModusToolbox… what the heck are you waiting for???

ModusToolbox includes a convenient "modus-shell", which is just a cygwin DLL with the path set up for the make and compiler executables. I start that by running cygwin.bat from the ModusToolbox\tools_2.0\modus-shell folder. That launches the shell in your home directory.

Clone a Project

All the ModusToolbox firmware is distributed as libraries in the cypresssemiconductorco repo on GitHub (yes, there are three consecutive 's' in there!). To get started you just have to clone an example from that site. As is traditional, I picked "hello world", and it takes just a few seconds to download.

yfs@YFS-T550 ~

$ mkdir MyFirstProject

 

yfs@YFS-T550 ~

$ cd MyFirstProject

 

yfs@YFS-T550 ~/MyFirstProject

$ git clone https://github.com/cypresssemiconductorco/mtb-example-psoc6-hello-world

Cloning into 'mtb-example-psoc6-hello-world'...

remote: Enumerating objects: 15, done.

remote: Counting objects: 100% (15/15), done.

remote: Compressing objects: 100% (13/13), done.

remote: Total 15 (delta 0), reused 12 (delta 0), pack-reused 0

Unpacking objects: 100% (15/15), done.

 

yfs@YFS-T550 ~/MyFirstProject

$ cd mtb-example-psoc6-hello-world

 

yfs@YFS-T550 ~/MyFirstProject/mtb-example-psoc6-hello-world

$ ls -la

total 64

drwxr-xr-x 1 yfs 1049089     0 Nov 1 15:40 .

drwxr-xr-x 1 yfs 1049089     0 Nov 1 15:40 ..

drwxr-xr-x 1 yfs 1049089     0 Nov 1 15:40 .git

drwxr-xr-x 1 yfs 1049089     0 Nov 1 15:40 images

drwxr-xr-x 1 yfs 1049089     0 Nov 1 15:40 libs

-rw-r--r-- 1 yfs 1049089 12443 Nov  1 15:40 LICENSE

-rw-r--r-- 1 yfs 1049089 10161 Nov  1 15:40 main.c

-rw-r--r-- 1 yfs 1049089  5207 Nov 1 15:40 Makefile

-rw-r--r-- 1 yfs 1049089 17480 Nov  1 15:40 README.md

 

What do you get? Well, there’s main.c and a Makefile, which is pretty much the whole application for “hello world”! Then there is README.md, which is a markdown file that tells you all about the application. You can read that file as plain text or open it in a markdown viewer. When you do that the document is nicely formatted and includes the pictures in the “images” folder. Then is also a LICENSE file, of course, and a “.git” folder, which contains all the clever stuff to support updating and pushing and pulling and cloning and tickling and tweaking and, oh you know, all that git stuff.

Pull in Libraries

The most interesting folder, though, is “libs”. Take a peak in there and you’ll see two files with the extension “.lib” (in this example). These files contain a hash of the GitHub repos and branch for all the extra firmware needed by the application. We use a make rule “getlibs” to pull in those libraries.

yfs@YFS-T550 ~/MyFirstProject/mtb-example-psoc6-hello-world

$ ls -la libs

total 6

drwxr-xr-x 1 yfs 1049089 0 Nov  1 15:40 .

drwxr-xr-x 1 yfs 1049089 0 Nov  1 15:40 ..

-rw-r--r-- 1 yfs 1049089 67 Nov 1 15:40 retarget-io.lib

-rw-r--r-- 1 yfs 1049089 82 Nov 1 15:40 TARGET_CY8CPROTO-062-4343W.lib

 

yfs@YFS-T550 ~/MyFirstProject/mtb-example-psoc6-hello-world

$ make getlibs

Tools Directory: C:/Users/yfs/ModusToolbox/tools_2.0

 

Initializing import: mtb-example-psoc6-hello-world

 

==============================================================================

= Importing libraries =

==============================================================================

Git is git version 2.17.0, found at /usr/bin/git

 

Searching application directories...

Application directories search complete.

 

Searching libs directory...

Found 2 file(s)

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/retarget-io.lib

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/TARGET_CY8CPROTO-062-4343W.lib

Libraries were processed. Re-evaluating libs directory...

Found 8 file(s)

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/TARGET_CY8CPROTO-062-4343W/libs/capsense.lib

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/TARGET_CY8CPROTO-062-4343W/libs/core-lib.lib

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/TARGET_CY8CPROTO-062-4343W/libs/psoc6cm0p.lib

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/TARGET_CY8CPROTO-062-4343W/libs/psoc6hal.lib

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/TARGET_CY8CPROTO-062-4343W/libs/psoc6make.lib

    Processing file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/libs/TARGET_CY8CPROTO-062-4343W/libs/psoc6pdl.lib

Libraries were processed. Re-evaluating libs directory...

Found 8 file(s)

libs directory search complete.

 

==============================================================================

= Import complete =

==============================================================================

 

yfs@YFS-T550 ~/MyFirstProject/mtb-example-psoc6-hello-world

$ ls -la libs

total 46

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:13 .

drwxr-xr-x 1 yfs 1049089 0 Nov  1 15:40 ..

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:12 capsense

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:12 core-lib

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:12 psoc6cm0p

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:13 psoc6hal

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:13 psoc6make

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:14 psoc6pdl

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:12 retarget-io

-rw-r--r-- 1 yfs 1049089 67 Nov 1 15:40 retarget-io.lib

drwxr-xr-x 1 yfs 1049089 0 Nov  1 16:12 TARGET_CY8CPROTO-062-4343W

-rw-r--r-- 1 yfs 1049089 82 Nov 1 15:40 TARGET_CY8CPROTO-062-4343W.lib

 

When you look at the libs folder now you have all the Board and Chip support firmware in TARGET_CY8CPROTO-062-4343W and the retarget-io library to enable STDIO output to printf(). Note that the TARGET library, which is known as the BSP, automatically pulls in other libraries that it depends up; core-lib, psoc6hal, psoc6pdl and so on.

Build

So now we have used make to complete the application. The cool part is that we can also use make to update the library versions, or add more, or remove one that you no longer want. The next step is to see if it works… it’s really complicated. Not really, just type “make build”.

yfs@YFS-T550 ~/MyFirstProject/mtb-example-psoc6-hello-world

$ make build

Tools Directory: C:/Users/yfs/ModusToolbox/tools_2.0

 

Initializing build: mtb-example-psoc6-hello-world Debug CY8CPROTO-062-4343W GCC_ARM

 

Auto-discovery in progress...

-> Found 150 .c file(s)

-> Found 34 .S file(s)

-> Found 16 .s file(s)

-> Found 0 .cpp file(s)

-> Found 0 .o file(s)

-> Found 4 .a file(s)

-> Found 367 .h file(s)

-> Found 0 .hpp file(s)

-> Found 0 resource file(s)

Applying filters...

Auto-discovery complete

 

==============================================================================

= Building application =

==============================================================================

Building 144 file(s)

    Compiling app file startup_psoc6_02_cm4.S

    Compiling app file cy_syslib_gcc.S

    Compiling app file cycfg.c

    Compiling app file cycfg_capsense.c

    Compiling app file cycfg_clocks.c

    Compiling app file cycfg_peripherals.c

    Compiling app file cycfg_pins.c

    Compiling app file cycfg_qspi_memslot.c

    Compiling app file cycfg_routing.c

    Compiling app file cycfg_system.c

    Compiling app file cybsp.c

    Compiling app file system_psoc6_cm4.c

    Compiling app file cy_capsense_centroid.c

    Compiling app file cy_capsense_control.c

    Compiling app file cy_capsense_csd.c

    Compiling app file cy_capsense_csx.c

    Compiling app file cy_capsense_filter.c

    Compiling app file cy_capsense_processing.c

    Compiling app file cy_capsense_sensing.c

    Compiling app file cy_capsense_structure.c

    Compiling app file cy_capsense_tuner.c

    Compiling app file psoc6_01_cm0p_sleep.c

    Compiling app file psoc6_02_cm0p_sleep.c

    Compiling app file psoc6_03_cm0p_sleep.c

    Compiling app file cyhal_adc.c

    Compiling app file cyhal_analog_common.c

    Compiling app file cyhal_crc.c

    Compiling app file cyhal_crypto_common.c

    Compiling app file cyhal_dac.c

    Compiling app file cyhal_flash.c

    Compiling app file cyhal_gpio.c

    Compiling app file cyhal_hwmgr.c

    Compiling app file cyhal_i2c.c

    Compiling app file cyhal_interconnect.c

    Compiling app file cyhal_lptimer.c

    Compiling app file cyhal_not_implemented.c

    Compiling app file cyhal_pwm.c

    Compiling app file cyhal_qspi.c

    Compiling app file cyhal_rtc.c

    Compiling app file cyhal_scb_common.c

    Compiling app file cyhal_sdhc.c

    Compiling app file cyhal_spi.c

    Compiling app file cyhal_system.c

    Compiling app file cyhal_tcpwm_common.c

    Compiling app file cyhal_timer.c

    Compiling app file cyhal_trng.c

    Compiling app file cyhal_uart.c

    Compiling app file cyhal_udb_sdio.c

    Compiling app file cyhal_usb_dev.c

    Compiling app file cyhal_utils.c

    Compiling app file cyhal_wdt.c

    Compiling app file cyhal_psoc6_01_104_m_csp_ble.c

    Compiling app file cyhal_psoc6_01_104_m_csp_ble_usb.c

    Compiling app file cyhal_psoc6_01_116_bga_ble.c

    Compiling app file cyhal_psoc6_01_116_bga_usb.c

    Compiling app file cyhal_psoc6_01_124_bga.c

    Compiling app file cyhal_psoc6_01_124_bga_sip.c

    Compiling app file cyhal_psoc6_01_43_smt.c

    Compiling app file cyhal_psoc6_01_68_qfn_ble.c

    Compiling app file cyhal_psoc6_01_80_wlcsp.c

    Compiling app file cyhal_psoc6_02_100_wlcsp.c

    Compiling app file cyhal_psoc6_02_124_bga.c

    Compiling app file cyhal_psoc6_02_128_tqfp.c

    Compiling app file cyhal_psoc6_02_68_qfn.c

    Compiling app file cyhal_psoc6_03_100_tqfp.c

    Compiling app file cyhal_psoc6_03_49_wlcsp.c

    Compiling app file cyhal_psoc6_03_68_qfn.c

    Compiling app file cy_ble_clk.c

    Compiling app file cy_canfd.c

    Compiling app file cy_crypto.c

    Compiling app file cy_crypto_core_aes_v1.c

    Compiling app file cy_crypto_core_aes_v2.c

    Compiling app file cy_crypto_core_cmac_v1.c

    Compiling app file cy_crypto_core_cmac_v2.c

    Compiling app file cy_crypto_core_crc_v1.c

    Compiling app file cy_crypto_core_crc_v2.c

    Compiling app file cy_crypto_core_des_v1.c

    Compiling app file cy_crypto_core_des_v2.c

    Compiling app file cy_crypto_core_ecc_domain_params.c

    Compiling app file cy_crypto_core_ecc_ecdsa.c

    Compiling app file cy_crypto_core_ecc_key_gen.c

    Compiling app file cy_crypto_core_ecc_nist_p.c

    Compiling app file cy_crypto_core_hmac_v1.c

    Compiling app file cy_crypto_core_hmac_v2.c

    Compiling app file cy_crypto_core_hw.c

    Compiling app file cy_crypto_core_hw_v1.c

    Compiling app file cy_crypto_core_mem_v1.c

    Compiling app file cy_crypto_core_mem_v2.c

    Compiling app file cy_crypto_core_prng_v1.c

    Compiling app file cy_crypto_core_prng_v2.c

    Compiling app file cy_crypto_core_rsa.c

    Compiling app file cy_crypto_core_sha_v1.c

    Compiling app file cy_crypto_core_sha_v2.c

    Compiling app file cy_crypto_core_trng_v1.c

    Compiling app file cy_crypto_core_trng_v2.c

    Compiling app file cy_crypto_core_vu.c

    Compiling app file cy_crypto_server.c

    Compiling app file cy_csd.c

    Compiling app file cy_ctb.c

    Compiling app file cy_ctdac.c

    Compiling app file cy_device.c

    Compiling app file cy_dma.c

    Compiling app file cy_dmac.c

    Compiling app file cy_efuse.c

    Compiling app file cy_flash.c

    Compiling app file cy_gpio.c

    Compiling app file cy_i2s.c

    Compiling app file cy_ipc_drv.c

    Compiling app file cy_ipc_pipe.c

    Compiling app file cy_ipc_sema.c

    Compiling app file cy_lpcomp.c

    Compiling app file cy_lvd.c

    Compiling app file cy_mcwdt.c

    Compiling app file cy_pdm_pcm.c

    Compiling app file cy_profile.c

    Compiling app file cy_prot.c

    Compiling app file cy_rtc.c

    Compiling app file cy_sar.c

    Compiling app file cy_scb_common.c

    Compiling app file cy_scb_ezi2c.c

    Compiling app file cy_scb_i2c.c

    Compiling app file cy_scb_spi.c

    Compiling app file cy_scb_uart.c

    Compiling app file cy_sd_host.c

    Compiling app file cy_seglcd.c

    Compiling app file cy_smartio.c

    Compiling app file cy_smif.c

    Compiling app file cy_smif_memslot.c

    Compiling app file cy_sysanalog.c

    Compiling app file cy_sysclk.c

    Compiling app file cy_sysint.c

    Compiling app file cy_syslib.c

    Compiling app file cy_syspm.c

    Compiling app file cy_systick.c

    Compiling app file cy_tcpwm_counter.c

    Compiling app file cy_tcpwm_pwm.c

    Compiling app file cy_tcpwm_quaddec.c

    Compiling app file cy_trigmux.c

    Compiling app file cy_usbfs_dev_drv.c

    Compiling app file cy_usbfs_dev_drv_io.c

    Compiling app file cy_usbfs_dev_drv_io_dma.c

    Compiling app file cy_wdt.c

    Compiling app file cy_retarget_io.c

    Compiling app file main.c

    Linking output file mtb-example-psoc6-hello-world.elf

==============================================================================

= Build complete =

==============================================================================

 

Calculating memory consumption: CY8C624ABZI-D44 GCC_ARM -Og

 

--------------------------------------------------

  | Section Name         |  Address |  Size     |

--------------------------------------------------

  | .cy_m0p_image        |  0x10000000 |  5068     |

  | .text                |  0x10002000 |  37276    |

  | .ARM.exidx           |  0x1000b19c |  8        |

  | .copy.table          |  0x1000b1a4 |  24       |

  | .zero.table          |  0x1000b1bc |  8        |

  | .data                |  0x080022e0 |  1888     |

  | .cy_sharedmem        | 0x08002a40   |  8 |

  | .noinit              |  0x08002a48 |  148      |

  | .bss                 |  0x08002adc |  996      |

  | .heap                |  0x08002ec0 |  1030464  |

--------------------------------------------------

 

  Total Internal Flash (Available) 2097152

  Total Internal Flash (Utilized)           47412

 

  Total Internal SRAM (Available) 1046528

  Total Internal SRAM (Utilized) 1033504

 

Program

The last step is obviously to program the kit. Plug a CY8CPROTO-062-4343W kit into the USB port and give your computer a few moments to install the drivers for it. Then open a serial terminal like PuTTY or TeraTerm and set them up for the “KitProg3 USB-UART COMxx” port in the Windows Device Manager. The baud rate is 115200.

If you do not have that kit… don’t worry, next time I’ll show you how easy it is to switch applications onto different kits.

To program the kit just type “make program”. This will check that the build is up to date (and build again if necessary) and then download the program using the CMSIS-DAP protocol to the board. If you are super impatient, like me, then you can use “make qprogram” instead and that is quicker (hence the ‘q’) because it skips the build check.

yfs@YFS-T550 ~/MyFirstProject/mtb-example-psoc6-hello-world

$ make program

Tools Directory: C:/Users/yfs/ModusToolbox/tools_2.0

 

Initializing build: mtb-example-psoc6-hello-world Debug CY8CPROTO-062-4343W GCC_ARM

 

Auto-discovery in progress...

-> Found 150 .c file(s)

-> Found 34 .S file(s)

-> Found 16 .s file(s)

-> Found 0 .cpp file(s)

-> Found 0 .o file(s)

-> Found 4 .a file(s)

-> Found 367 .h file(s)

-> Found 0 .hpp file(s)

-> Found 0 resource file(s)

Applying filters...

Auto-discovery complete

 

==============================================================================

= Building application =

==============================================================================

Building 144 file(s)

==============================================================================

= Build complete =

==============================================================================

 

Calculating memory consumption: CY8C624ABZI-D44 GCC_ARM -Og

 

--------------------------------------------------

  | Section Name         |  Address |  Size     |

   --------------------------------------------------

  | .cy_m0p_image        |  0x10000000 |  5068     |

  | .text                |  0x10002000 |  37276    |

  | .ARM.exidx           |  0x1000b19c |  8        |

  | .copy.table          |  0x1000b1a4 |  24       |

  | .zero.table          |  0x1000b1bc |  8        |

  | .data                |  0x080022e0 |  1888     |

  | .cy_sharedmem        |  0x08002a40 |  8        |

  | .noinit              |  0x08002a48 |  148      |

  | .bss                 |  0x08002adc |  996      |

  | .heap                |  0x08002ec0 |  1030464  |

--------------------------------------------------

 

  Total Internal Flash (Available) 2097152

  Total Internal Flash (Utilized)           47412

 

  Total Internal SRAM (Available) 1046528

  Total Internal SRAM (Utilized) 1033504

 

Programming target device...

Open On-Chip Debugger 0.10.0+dev-2.2.0.249 (2019-09-10-10:57)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.org/doc/doxygen/bugs.html

adapter speed: 1500 kHz

adapter speed: 1000 kHz

** Auto-acquire enabled, use "set ENABLE_ACQUIRE 0" to disable

cortex_m reset_config sysresetreq

cortex_m reset_config vectreset

Info : Using CMSIS loader 'CY8C6xxA_SMIF' for bank 'psoc6_smif0_cm0' (footprint 6105 bytes)

Warn : SFlash programming allowed for regions: USER, TOC, KEY

Info : CMSIS-DAP: SWD  Supported

Info : CMSIS-DAP: FW Version = 2.0.0

Info : CMSIS-DAP: Interface Initialised (SWD)

Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1

Info : CMSIS-DAP: Interface ready

Info : VTarget = 3.332 V

Info : kitprog3: acquiring PSoC device...

Info : clock speed 1000 kHz

Info : SWD DPIDR 0x6ba02477

Info : psoc6.cpu.cm0: hardware has 4 breakpoints, 2 watchpoints

Info : psoc6.cpu.cm0: external reset detected

***************************************

** Silicon: 0xE402, Family: 0x102, Rev.: 0x11 (A0)

** Detected Device: CY8C624ABZI-S2D44A0

** Detected Main Flash size, kb: 2048

** Flash Boot version 3.1.0.45

** Chip Protection: NORMAL

***************************************

Info : psoc6.cpu.cm4: hardware has 6 breakpoints, 4 watchpoints

Info : psoc6.cpu.cm4: external reset detected

Info : Listening on port 3333 for gdb connections

Info : Listening on port 3334 for gdb connections

Warn : Only resetting the Cortex-M core, use a reset-init event handler to reset any peripherals or configure hardware srst support.

Info : kitprog3: acquiring PSoC device...

target halted due to debug-request, current mode: Thread

xPSR: 0x41000000 pc: 0x00000190 msp: 0x080ff800

** Device acquired successfully

** psoc6.cpu.cm4: Ran after reset and before halt...

target halted due to debug-request, current mode: Thread

xPSR: 0x01000000 pc: 0x0000012a msp: 0x080ff800

** Programming Started **

auto erase enabled

Info : Flash write discontinued at 0x100013cc, next section at 0x10002000

Info : Padding image section 0 at 0x100013cc with 52 bytes (bank write end alignment)

[100%] [################################] [ Erasing     ]

[100%] [################################] [ Programming ]

Info : Padding image section 1 at 0x1000b92c with 212 bytes (bank write end alignment)

[100%] [################################] [ Erasing     ]

[100%] [################################] [ Programming ]

wrote 44544 bytes from file C:/Users/yfs/MyFirstProject/mtb-example-psoc6-hello-world/build/CY8CPROTO-062-4343W/Debug/mtb-example-psoc6-hello-world.hex in 5.370537s (8.100 KiB/s)

** Programming Finished **

** Verify Started **

verified 44280 bytes in 0.267027s (161.939 KiB/s)

** Verified OK **

** Resetting Target **

Warn : Only resetting the Cortex-M core, use a reset-init event handler to reset any peripherals or configure hardware srst support.

shutdown command invoked

 

You should see the red LED blinking at about 1Hz. That’s just way too slow for me and it drives me nuts - I always open main.c in an editor and speed that up! In the terminal emulator you should see this. You can turn the LED blinking on and off by pressing the Enter key.

My First ModusToolbox 2_0 Design PuTTY.png

 

Congratulations! If you followed along then you just created, built, and programmed your first ModusToolbox application.