This example demonstrates how flash protection can be configured in the XMC™ 4000 series of devices.
Note: This code example involves programming the user configuration blocks (UCB), which can only be programmed only a limited number of times. See the Design and implementation section before proceeding with this code example.
- ModusToolbox™ v3.0 or later (tested with v3.3)
- SEGGER J-Link software
- Programming language: C
- Associated parts: XMC™ 4000 series MCU parts
- GNU Arm® embedded compiler v11.3.1 (
GCC_ARM
) - Default value ofTOOLCHAIN
- XMC4700 relax kit (
KIT_XMC47_RELAX_V1
) - Default value ofTARGET
- XMC4200 Platform2GO XTREME Kit (
KIT_XMC_PLT2GO_XMC4200
) - XMC4300 relax EtherCAT Kit (
KIT_XMC43_RELAX_ECAT_V1
) - XMC4400 Platform2GO XTREME Kit (
KIT_XMC_PLT2GO_XMC4400
) - XMC4800 relax EtherCAT kit (
KIT_XMC48_RELAX_ECAT_V1
)
This example uses the board's default configuration. See the kit user guide to ensure that the board is configured correctly.
Install a terminal emulator if you don't have one. Instructions in this document use Tera Term.
This example requires no additional software or tools.
The ModusToolbox™ tools package provides the Project Creator as both a GUI tool and a command line tool.
Use Project Creator GUI
-
Open the Project Creator GUI tool.
There are several ways to do this, including launching it from the dashboard or from inside the Eclipse IDE. For more details, see the Project Creator user guide (locally available at {ModusToolbox™ install directory}/tools_{version}/project-creator/docs/project-creator.pdf).
-
On the Choose Board Support Package (BSP) page, select a kit supported by this code example. See Supported kits.
Note: To use this code example for a kit not listed here, you may need to update the source files. If the kit does not have the required resources, the application may not work.
-
On the Select Application page:
a. Select the Applications(s) Root Path and the Target IDE.
Note: Depending on how you open the Project Creator tool, these fields may be pre-selected for you.
b. Select this code example from the list by enabling its check box.
Note: You can narrow the list of displayed examples by typing in the filter box.
c. (Optional) Change the suggested New Application Name and New BSP Name.
d. Click Create to complete the application creation process.
Use Project Creator CLI
The 'project-creator-cli' tool can be used to create applications from a CLI terminal or from within batch files or shell scripts. This tool is available in the {ModusToolbox™ install directory}/tools_{version}/project-creator/ directory.
Use a CLI terminal to invoke the 'project-creator-cli' tool. On Windows, use the command-line 'modus-shell' program provided in the ModusToolbox™ installation instead of a standard Windows command-line application. This shell provides access to all ModusToolbox™ tools. You can access it by typing "modus-shell" in the search box in the Windows menu. In Linux and macOS, you can use any terminal application.
The following example will clone the Flash protection application with the desired name "MyFlashProtection" configured for the KIT_XMC47_RELAX_V1 BSP into the specified working directory, C:/mtb_projects:
project-creator-cli --board-id KIT_XMC47_RELAX_V1 --app-id mtb-example-xmc-flash-protection --user-app-name MyFlashProtection --target-dir "C:/mtb_projects"
Update the above paragraph and commands to match your CE.
The 'project-creator-cli' tool has the following arguments:
Argument | Description | Required/optional |
---|---|---|
--board-id |
Defined in the field of the BSP manifest | Required |
--app-id |
Defined in the field of the CE manifest | Required |
--target-dir |
Specify the directory in which the application is to be created if you prefer not to use the default current working directory | Optional |
--user-app-name |
Specify the name of the application if you prefer to have a name other than the example's default name | Optional |
Note: The project-creator-cli tool uses the
git clone
andmake getlibs
commands to fetch the repository and import the required libraries. For details, see the "Project creator tools" section of the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).
After the project has been created, you can open it in your preferred development environment.
Eclipse IDE
If you opened the Project Creator tool from the included Eclipse IDE, the project will open in Eclipse automatically.
For more details, see the Eclipse IDE for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_ide_user_guide.pdf).
Visual Studio (VS) Code
Launch VS Code manually, and then open the generated {project-name}.code-workspace file located in the project directory.
For more details, see the Visual Studio Code for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_vscode_user_guide.pdf).
Keil µVision
Double-click the generated {project-name}.cprj file to launch the Keil µVision IDE.
For more details, see the Keil µVision for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_uvision_user_guide.pdf).
IAR Embedded Workbench
Open IAR Embedded Workbench manually, and create a new project. Then select the generated {project-name}.ipcf file located in the project directory.
For more details, see the IAR Embedded Workbench for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_iar_user_guide.pdf).
Command line
If you prefer to use the CLI, open the appropriate terminal, and navigate to the project directory. On Windows, use the command-line 'modus-shell' program; on Linux and macOS, you can use any terminal application. From there, you can run various make
commands.
For more details, see the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).
-
Connect the board to your PC using a micro-USB cable through the debug USB connector.
-
Open a terminal program and select the JLINK CDC UART COM port. Configure the terminal with a baud rate of 115200, data bits of 8, stop bit of 1, and with parity and flow control set to none.
-
Program the board using one of the following:
Using Eclipse IDE
-
Select the application project in the Project Explorer.
-
In the Quick Panel, scroll down, and click <Application Name> Program (JLink).
In other IDEs
Follow the instructions in your preferred IDE.
Using CLI
From the terminal, execute the
make program
command to build and program the application using the default toolchain to the default target. The default toolchain is specified in the application's Makefile but you can override this value manually:make program TOOLCHAIN=<toolchain>
Example:
make program TOOLCHAIN=GCC_ARM
-
-
Once programmed, open your serial terminal software. You should see the shell application displayed as shown follows:
Figure 1. Shell application
-
Do the following to install flash read protection using the shell application.
-
Type
status
to get the status of flash protection and UCB program count.>> status
Figure 2. Protection status
-
Type
install <password0> <password1>
to install flash protection.The device will reset after this command for the changes to take effect.
For example:
>> install 1234 5678
Figure 3. Install protection
-
Check the status to see if the flash protection is successful. The UCB program count will also be displayed.
>> status
Figure 4. Protection status
-
Type
disable <password0> <password1>
to disable the flash protection temporarily. Use the same credentials used in Step 2.>> disable 1234 5678
Figure 5. Disable protection
-
Type
resume
to re-enable the flash protection installed earlier.>> resume
Figure 6. Resume protection
-
Type
uninstall <password0> <password1>
to uninstall flash protection. Use the same credentials used in Step 2.The device will reset after this command for the changes to take effect.
>> uninstall 1234 5678
Figure 7. Uninstall protection
-
Check the status to see if flash protection was uninstalled successfully.
>> status
Figure 8. Protection status
-
You can debug the example to step through the code.
In Eclipse IDE
Use the <Application Name> Debug (JLink) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ user guide.
In other IDEs
Follow the instructions in your preferred IDE.
User configuration blocks (UCB) are used to configure the flash read/write protection on the XMC4000 series of devices. Three UCBs can be programmed to achieve this: UCB0, UCB1, and UCB2.
In this code example, UCB0 is programmed to implement global flash read protection. The code example firmware flow is illustrated below:
Figure 9. Firmware flow diagram
The code example uses a shell application to take input commands from the user to perform five different operations:
Command | Arguments | Description |
---|---|---|
install |
<pwd0> <pwd1> |
Programs global flash read protection on the flash rows with passwords pwd0 and pwd1 |
uninstall |
<pwd0> <pwd1> |
Removes flash protection with previously configured passwords |
disable |
<pwd0> <pwd1> |
Disables flash protection temporarily with previously configured passwords |
resume |
None | Re-enables previously configured flash protection |
status |
None | Displays the flash protection status |
Note: The protection installation is modified by erasing and programming the UCBs with dedicated command sequences as described in the firmware flow diagram. The erase and re-program of the UCBs can be performed up to four times. Exceeding this limit may make the device unusable.
The code example uses a custom design.modus file because it uses the universal serial interface channel (USIC) block to implement the shell application. The following settings were modified in the default design.modus file.
Figure 10. USIC (UART) settings
Figure 11. UART Rx pin settings
Figure 12. UART Tx pin settings
You can debug the example to step through the code. In the IDE, use the <Application Name> Debug (JLink) configuration in the Quick Panel. For more details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ software user guide.
Resources | Links |
---|---|
Kit guides | XMC4700 relax kit V1 |
Code examples | Using ModusToolbox™ software on GitHub |
Device documentation | XMC4000 family datasheets XMC4000 family technical reference manuals |
Development kits | XMC™ MCU eval boards |
Libraries on GitHub | mtb-xmclib-cat3 – XMC™ MCU peripheral library (XMCLib) and docs |
Tools | Eclipse IDE for ModusToolbox™ software – ModusToolbox™ software is a collection of easy-to-use software and tools enabling rapid development with Infineon MCUs, covering applications from embedded sense and control to wireless and cloud-connected systems using AIROC™ Wi-Fi and Bluetooth® connectivity devices. |
Infineon provides a wealth of data at www.infineon.com to help you select the right device, and quickly and effectively integrate it into your design.
For XMC™ MCU devices, see 32-bit XMC™ industrial microcontroller based on Arm® Cortex®-M.
Document title: CE232719 - XMC™ MCU: Flash protection
Version | Description of change |
---|---|
1.0.0 | New code example |
1.1.0 | Added support for new kits |
2.0.0 | Updated to support ModusToolbox™ software v3.0; CE will not be backward compatible with previous versions of ModusToolbox™ software |
2.1.0 | Added support for new kits |
2.1.1 | Updated README |
2.2.0 | Updated code to use retarget-io-cat3 middleware for shell operations |
All other trademarks or registered trademarks referenced herein are the property of their respective owners.
© 2024 Infineon Technologies AG
All Rights Reserved.
The information given in this document shall in no event be regarded as a guarantee of conditions or characteristics. With respect to any examples or hints given herein, any typical values stated herein and/or any information regarding the application of the device, Infineon Technologies hereby disclaims any and all warranties and liabilities of any kind, including without limitation, warranties of non-infringement of intellectual property rights of any third party.
For further information on technology, delivery terms and conditions and prices, please contact the nearest Infineon Technologies Office (www.infineon.com).
Due to technical requirements, components may contain dangerous substances. For information on the types in question, please contact the nearest Infineon Technologies Office.
Infineon Technologies components may be used in life-support devices or systems only with the express written approval of Infineon Technologies, if a failure of such components can reasonably be expected to cause the failure of that life-support device or system or to affect the safety or effectiveness of that device or system. Life support devices or systems are intended to be implanted in the human body or to support and/or maintain and sustain and/or protect human life. If they fail, it is reasonable to assume that the health of the user or other persons may be endangered.