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 type “make build” to 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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We use cookies and similar technologies (also from third parties) to collect your device and browser information for a better understanding on how you use our online offerings. This enables us to optimize and personalize your experience with Infineon and to provide you with additional services and information based on your individual profile. Details are available in our privacy policy where you can also change your preferences on cookies at any time.
By technically required cookies we mean cookies without those the technical provision of the online service cannot be ensured. These include e.g. cookies supporting essential services like a smooth reproduction of video or audio footage. So called ‘functional cookies’ are also assigned belonging to this category. Functional cookies store information in order to provide you comfortable use of our online services (e.g. language selection). The legal basis for the processing of personal data by means of cookies of this category is Infineon’s legitimate interest. This includes, among other things, the interest in having a professional external presentation as well as an optimal balancing of the loads on the server due to technical reasons.
By performance and marketing cookies we mean cookies which are technically not required. We use performance and marketing cookies only if you have given us your prior consent. With such cookies, we collect information about how users interact with our website and which pages have been visited. This helps us to understand user activity on our website on an aggregated as well as on a personal level to provide you relevant content and services.