Author: VivekK_11 Version: **
Translation - Japanese: Mbed OS アプリケーションで ModusToolbox コンフィグレータツールを使う - KBA228797- Community Translated (JA)
This article explains how to use ModusToolbox™ Configurator tools to modify the device configuration in PSoC 6 MCU-based Mbed OS applications. The article uses a CapSense® application as an example to explain that use case. This article applies to Mbed OS versions 5.14.0 or above, and ModusToolbox version 2.0 or above.
Default Device Configuration in PSoC 6 MCU-based Mbed OS Applications
Cypress PSoC 6 MCU-based development kits contain hardware (device) initialization/configuration code in the Mbed OS application folder \mbed-os\targets\TARGET_Cypress\TARGET_PSOC6\TARGET_TARGET_NAME\. For example, device configuration code of CY8CPROTO-062-4343W is present in \mbed-os\targets\TARGET_Cypress\TARGET_PSOC6\TARGET_CY8CPROTO_062_4343W\. The important files in that folder are listed below.
- Board Support Package (BSP) source files: The BSP source files (cybsp.c, cybsp.h) contain the hardware (BSP) initialization function cybsp_init(). The cybsp_init() function of a target is called by the mbed_sdk_init() function as part of the application startup code. See https://os.mbed.com/docs/mbed-os/latest/reference/bootstrap.html for boot sequence details. The mbed_sdk_init() function definition for PSoC 6 MCU-based targets can be found in the mbed_overrides.c file in \mbed-os\targets\TARGET_Cypress\TARGET_PSOC6\ .
- COMPONENT_BSP_DESIGN_MODUS: This folder contains the ModusToolbox Configurator-based configuration files, and the corresponding generated code as listed below.
- Device Configurator generated code: The device configuration file is named design.modus, and the corresponding generated files are in the GeneratedSource folder. The cybsp_init() function in cybsp.c calls the init_cycfg_system() function that is part of the Device Configurator-generated code in the cycfg_system.c file. The function init_cycfg_system() initializes the device core clock system, flash memory wait states, and other system level settings per the Device Configurator-generated cycfg_system.c file.
- CapSense Configurator generated code: The CapSense configuration file is named design.cycapsense, and the corresponding generated files are in the GeneratedSource folder. The CapSense files are not generated by default in the GeneratedSource folder because not all PSoC 6 MCU applications require the CapSense feature.
- QSPI Interface Configurator generated code: The QSPI configuration file is named design.cyqspi, and the corresponding generated files are in the GeneratedSource folder.
When a PSoC 6 MCU-based Mbed OS application is compiled, the build system includes the source files in the COMPONENT_BSP_DESIGN_MODUS folder of the specific target. This is done by adding the setting “components_add”: [“BSP_DESIGN_MODUS”] for the PSoC 6 MCU-based targets in the \mbed-os\targets\targets.json file. See https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-build-rules.html for more information on using the component type label directories for the build process.
Custom Device Configuration in PSoC 6 MCU-based Mbed OS Applications
A PSoC 6 mcu-based Mbed OS application may require a custom device configuration instead of the default configuration code available in the target folder as explained in the previous section. An example is the usage of the CapSense middleware component to allow the use of the PSoC 6 MCU CapSense feature in an Mbed OS application. An Mbed OS example application based on CapSense is available in the Cypress GitHub repository. The CapSense example uses the buttons and slider whose settings are generated by modifying two types of configurator-related files as explained below.
- Device configurator (design.modus) to enable and configure the CapSense block as needed for the application, and regenerating the corresponding GeneratedSource files.
- CapSense configurator (design.cycapsense) to configure the Button and Slider widget settings as required for the end application, and regenerating the corresponding GeneratedSource files.
This process requires modifications to the default COMPONENT_BSP_DESIGN_MODUS component of the target in the Mbed OS folder. One option is to directly edit the files in this folder using the applicable configurators and regenerating the files. However, this is not a preferred solution beccause anytime you move between different Mbed OS versions or share projects, the process must be repeated.
A better solution is to have a modified COMPONENT_ BSP_DESIGN_MODUS component as part of the application top-level folder to reflect the changes required for the application for each required target. This approach is followed in the Mbed OS CapSense example at Cypress GitHub repository where the custom configuration for each target is placed inside the folder COMPONENT_CUSTOM_BSP_DESIGN_MODUS. To include this custom BSP configuration in the build process of a target, the mbed_app.json file in the top-level application folder contains the setting "target.components_add": ["CUSTOM_BSP_DESIGN_MODUS"] under each of the applicable targets. To also prevent the Mbed OS build process from including the default COMPONENT_BSP_DESIGN_MODUS component for the target, the mbed_app.json file also contains the setting "target.components_remove": ["BSP_DESIGN_MODUS"] to exclude the folder from the build process.
An example of how the mbed_app.json file will look like after the above changes is given below for the target
Some code examples using this approach are listed below for reference.
- mbed-os-example-capsense – This code example demonstrates CapSense buttons and slider for PSoC 6 MCU with Mbed OS using CapSense Middleware Library.
- mbed-os-example-csdadc - This code example demonstrates the usage of CSD analog-to-digital converter (ADC) for PSoC 6 MCU with Mbed OS using the CSDADC Middleware Library.
- mbed-os-example-csdidac - This code example demonstrates using the CSD current digital-to-analog converter (IDAC) as a current source and a current sink.