How to Create a TrustZone®-based Touch Project Using MPLAB® Code Configurator (MCC) Harmony
Objective
The following procedure shows how to create a secure touch project with the MPLAB® Code Configurator (MCC) Harmony platform, where touch sensors and their parameters can be graphically added and tuned. The resulting project supports the MPLAB XC32 compiler in MPLAB X IDE. The step-by-step procedure for generating a secure self-capacitance touch project using MCC Harmony has been elaborated here. This project uses the onboard touch button present on the PIC32CMLS00 Curiosity Nano Evaluation board.
Materials
Hardware Tools
| Tool | About | Purchase |
|---|---|---|
| PIC32CM LS00 CNano | PIC32CM LS00 Curiosity Nano+ Touch Evaluation Kit | Microchip Technology | EV41C56A | Microchip Technology |
Software Tools
- MPLAB X IDE with MCC plugin installed
Procedure
This secure touch project has been created for the onboard button with shield enabled. The touch peripheral will be designated as secure in this project.
This step-by-step elaborates on the features of TrustZone®, which uses two projects: secure and non-secure projects. These projects work together on the same MCU and offer security isolation between the trusted and the non-trusted resources in the device.
Open MPLAB X IDE.
Click File > New Project in MPLAB X IDE.
Choose the project.
In the New Project window, select Application Project(s) and click Next.
Select the device.
Choose the device for which the project needs to be generated and click Next.
Select the compiler.
Choose the latest compiler for 32-bit devices and click Next.
Update the project settings.
Enter the Location, Folder, and Path for the project and click Finish.
MPLAB Harmony is opened along with the Project Graph. Three projects can be seen:
- Project group
- Secure project
- Non-secure project
By default, once a project is created, the non-secure project is set as the main project and MCC is opened. If it does not open, right-click on the non-secure project and click Set as Main project.
In the Device Resources pane, select Touch Library.
A pop-up window appears asking for PTC and RTC activation. Click Yes.
Now, Touch Library, RTC, and PTC are added to the Project Graph.
Launch Touch Configurator by selecting it from the Plugins drop-down.
Choose the technology.
Choose Self-Cap technology and add 1 button, as this project is developed for the onboard touch button present.
An Information pop-up indicating that the clock for CPU and peripherals is set appears. Click Ok.
The pin assignment can be done in Configure > Sensor Pins. With respect to the following table, in touch configurator, the pins can be selected.
| Pins | |
|---|---|
| Touch button | PA22 |
| Driven Shield for Touch | PA21 |
| LED | PA15 |
Tune sensor parameters.
For tuning the touch parameters, select Config > Sensor Parameters and tune according to the application.
Tune the common parameters.
For tuning the touch parameters, select Config > Common Parameters and tune according to the application.
Enable Driven Shield then select the corresponding shield pin from the dropdown.
Frequency Hop can be enabled by navigating to Config > Frequency Hop and then sliding the Enable Frequency Hop button.
Enable the data streamer by enabling the Enable Touch Tuning Data connection option. A detailed description of how to configure the data streamer is provided in the "Tuning Options for Touch in MPLAB® Code Configurator (MCC) Melody and Harmony" page.
Click on the Summary tab to review the project configuration and find versions of library modules.
Now add SERCOM3 for visualizing data using MPLAB Data Visualizer. Connect SERCOM3 block's UART to Touch block's UART.
Configure SERCOM settings by selecting the correct pad for TX and RX.
Configure Touch and SERCOM3 as Secure Peripheral as shown.
Configure the pins and assign SERCOM pins as NON-SECURE from the drop-down.
Once the project is configured, click on Project Resources > Generate to generate the code.
A "generation complete" message can be seen as shown.
The main project can then be built and checked for errors.
Include touch_process() and the code for LED in the main while(1) loop inside the secure project.
Now right-click on the secure project and select Make and Program device.
The project is flashed in the device, and touch detection can be seen in MPLAB Data Visualizer.
