{"id":18346382,"url":"https://github.com/infineon/mtb-example-xmc-flash-protection","last_synced_at":"2025-04-09T22:43:52.293Z","repository":{"id":82063373,"uuid":"383988854","full_name":"Infineon/mtb-example-xmc-flash-protection","owner":"Infineon","description":"This example demonstrates how flash protection can be configured in the XMC 4000 series of devices.","archived":false,"fork":false,"pushed_at":"2025-03-27T07:00:54.000Z","size":587,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-27T08:22:36.795Z","etag":null,"topics":["kit-xmc-plt2go-xmc4200","kit-xmc-plt2go-xmc4400","kit-xmc43-relax-ecat-v1","kit-xmc45-relax-v1","kit-xmc47-relax-v1","kit-xmc48-relax-ecat-v1","peripherals"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Infineon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-08T03:22:52.000Z","updated_at":"2025-03-27T07:00:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"d16f7ad3-815e-43ce-a0fd-f701ae25132b","html_url":"https://github.com/Infineon/mtb-example-xmc-flash-protection","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infineon%2Fmtb-example-xmc-flash-protection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infineon%2Fmtb-example-xmc-flash-protection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infineon%2Fmtb-example-xmc-flash-protection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infineon%2Fmtb-example-xmc-flash-protection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Infineon","download_url":"https://codeload.github.com/Infineon/mtb-example-xmc-flash-protection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125242,"owners_count":21051762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kit-xmc-plt2go-xmc4200","kit-xmc-plt2go-xmc4400","kit-xmc43-relax-ecat-v1","kit-xmc45-relax-v1","kit-xmc47-relax-v1","kit-xmc48-relax-ecat-v1","peripherals"],"created_at":"2024-11-05T21:11:20.631Z","updated_at":"2025-04-09T22:43:52.280Z","avatar_url":"https://github.com/Infineon.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XMC\u0026trade; MCU: Flash protection\n\nThis example demonstrates how flash protection can be configured in the XMC™ 4000 series of devices.\n\n**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](#design-and-implementation) section before proceeding with this code example.\n\n## Requirements\n\n- [ModusToolbox\u0026trade;](https://www.infineon.com/modustoolbox) v3.0 or later (tested with v3.4)\n- [SEGGER J-Link software](https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack)\n- Programming language: C\n- Associated parts: [XMC\u0026trade; 4000 series MCU](https://www.infineon.com/cms/en/product/microcontroller/32-bit-industrial-microcontroller-based-on-arm-cortex-m/32-bit-xmc4000-industrial-microcontroller-arm-cortex-m4/) parts\n\n## Supported toolchains (make variable 'TOOLCHAIN')\n\n- GNU Arm® embedded compiler v11.3.1 (`GCC_ARM`) - Default value of `TOOLCHAIN`\n\n## Supported kits (make variable 'TARGET')\n\n- [XMC4700 relax kit](https://www.infineon.com/cms/en/product/evaluation-boards/kit_xmc47_relax_v1/) (`KIT_XMC47_RELAX_V1`) - Default value of `TARGET`\n- [XMC4200 Platform2GO XTREME Kit](https://www.infineon.com/cms/en/product/evaluation-boards/kit_xmc_plt2go_xmc4200/) (`KIT_XMC_PLT2GO_XMC4200`)\n- [XMC4300 relax EtherCAT Kit](https://www.infineon.com/cms/en/product/evaluation-boards/kit_xmc43_relax_ecat_v1/) (`KIT_XMC43_RELAX_ECAT_V1`)\n- [XMC4400 Platform2GO XTREME Kit](https://www.infineon.com/cms/en/product/evaluation-boards/kit_xmc_plt2go_xmc4400/) (`KIT_XMC_PLT2GO_XMC4400`)\n- [XMC4800 relax EtherCAT kit](https://www.infineon.com/cms/en/product/evaluation-boards/kit_xmc48_relax_ecat_v1/) (`KIT_XMC48_RELAX_ECAT_V1`)\n\n## Hardware setup\n\nThis example uses the board's default configuration. See the kit user guide to ensure that the board is configured correctly.\n\n## Software setup\n\nInstall a terminal emulator if you don't have one. Instructions in this document use [Tera Term](https://teratermproject.github.io/index-en.html).\n\nThis example requires no additional software or tools.\n\n## Using the code example\n\n### Create the project\n\nThe ModusToolbox\u0026trade; tools package provides the Project Creator as both a GUI tool and a command line tool.\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eUse Project Creator GUI\u003c/b\u003e\u003c/summary\u003e\n\n1. Open the Project Creator GUI tool.\n\n   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](https://www.infineon.com/ModusToolboxProjectCreator) (locally available at *{ModusToolbox\u0026trade; install directory}/tools_{version}/project-creator/docs/project-creator.pdf*).\n\n2. On the **Choose Board Support Package (BSP)** page, select a kit supported by this code example. See [Supported kits](#supported-kits-make-variable-target).\n\n   \u003e **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.\n\n3. On the **Select Application** page:\n\n   a. Select the **Applications(s) Root Path** and the **Target IDE**.\n\n   \u003e **Note:** Depending on how you open the Project Creator tool, these fields may be pre-selected for you.\n\n   b.\tSelect this code example from the list by enabling its check box.\n\n   \u003e **Note:** You can narrow the list of displayed examples by typing in the filter box.\n\n   c. (Optional) Change the suggested **New Application Name** and **New BSP Name**.\n\n   d. Click **Create** to complete the application creation process.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eUse Project Creator CLI\u003c/b\u003e\u003c/summary\u003e\n\nThe '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\u0026trade; install directory}/tools_{version}/project-creator/* directory.\n\nUse a CLI terminal to invoke the 'project-creator-cli' tool. On Windows, use the command-line 'modus-shell' program provided in the ModusToolbox\u0026trade; installation instead of a standard Windows command-line application. This shell provides access to all ModusToolbox\u0026trade; 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.\n\nThe following example will clone the [Flash protection](https://github.com/Infineon/mtb-example-xmc-flash-protection) application with the desired name \"MyFlashProtection\" configured for the *KIT_XMC47_RELAX_V1* BSP into the specified working directory, *C:/mtb_projects*:\n\n   ```\n   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\"\n   ```\n\n\u003cmark\u003eUpdate the above paragraph and commands to match your CE.\n\nThe 'project-creator-cli' tool has the following arguments:\n\nArgument | Description | Required/optional\n---------|-------------|-----------\n`--board-id` | Defined in the \u003cid\u003e field of the [BSP](https://github.com/Infineon?q=bsp-manifest\u0026type=\u0026language=\u0026sort=) manifest | Required\n`--app-id`   | Defined in the \u003cid\u003e field of the [CE](https://github.com/Infineon?q=ce-manifest\u0026type=\u0026language=\u0026sort=) manifest | Required\n`--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\n`--user-app-name`| Specify the name of the application if you prefer to have a name other than the example's default name | Optional\n\n\u003e **Note:** The project-creator-cli tool uses the `git clone` and `make getlibs` commands to fetch the repository and import the required libraries. For details, see the \"Project creator tools\" section of the [ModusToolbox\u0026trade; tools package user guide](https://www.infineon.com/ModusToolboxUserGuide) (locally available at {ModusToolbox\u0026trade; install directory}/docs_{version}/mtb_user_guide.pdf).\n\n\u003c/details\u003e\n\n\n\n### Open the project\n\nAfter the project has been created, you can open it in your preferred development environment.\n\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eEclipse IDE\u003c/b\u003e\u003c/summary\u003e\n\nIf you opened the Project Creator tool from the included Eclipse IDE, the project will open in Eclipse automatically.\n\nFor more details, see the [Eclipse IDE for ModusToolbox\u0026trade; user guide](https://www.infineon.com/MTBEclipseIDEUserGuide) (locally available at *{ModusToolbox\u0026trade; install directory}/docs_{version}/mt_ide_user_guide.pdf*).\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eVisual Studio (VS) Code\u003c/b\u003e\u003c/summary\u003e\n\nLaunch VS Code manually, and then open the generated *{project-name}.code-workspace* file located in the project directory.\n\nFor more details, see the [Visual Studio Code for ModusToolbox\u0026trade; user guide](https://www.infineon.com/MTBVSCodeUserGuide) (locally available at *{ModusToolbox\u0026trade; install directory}/docs_{version}/mt_vscode_user_guide.pdf*).\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eArm\u0026reg; Keil\u0026reg; µVision\u0026reg;\u003c/b\u003e\u003c/summary\u003e\n\nDouble-click the generated *{project-name}.cprj* file to launch the Arm\u0026reg; Keil\u0026reg; µVision\u0026reg; IDE.\n\nFor more details, see the [Arm\u0026reg; Keil\u0026reg; µVision\u0026reg; for ModusToolbox\u0026trade; user guide](https://www.infineon.com/MTBuVisionUserGuide) (locally available at *{ModusToolbox\u0026trade; install directory}/docs_{version}/mt_uvision_user_guide.pdf*).\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eIAR Embedded Workbench\u003c/b\u003e\u003c/summary\u003e\n\nOpen IAR Embedded Workbench manually, and create a new project. Then select the generated *{project-name}.ipcf* file located in the project directory.\n\nFor more details, see the [IAR Embedded Workbench for ModusToolbox\u0026trade; user guide](https://www.infineon.com/MTBIARUserGuide) (locally available at *{ModusToolbox\u0026trade; install directory}/docs_{version}/mt_iar_user_guide.pdf*).\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eCommand line\u003c/b\u003e\u003c/summary\u003e\n\nIf 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.\n\nFor more details, see the [ModusToolbox\u0026trade; tools package user guide](https://www.infineon.com/ModusToolboxUserGuide) (locally available at *{ModusToolbox\u0026trade; install directory}/docs_{version}/mtb_user_guide.pdf*).\n\n\u003c/details\u003e\n\n\n\n## Operation\n\n1. Connect the board to your PC using a micro-USB cable through the debug USB connector.\n\n2. 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.\n\n3. Program the board using one of the following:\n\n   \u003cdetails\u003e\u003csummary\u003e\u003cb\u003eUsing Eclipse IDE\u003c/b\u003e\u003c/summary\u003e\n\n      1. Select the application project in the Project Explorer.\n\n      2. In the **Quick Panel**, scroll down, and click **\\\u003cApplication Name\u003e Program (JLink)**.\n   \u003c/details\u003e\n\n   \u003cdetails\u003e\u003csummary\u003e\u003cb\u003eIn other IDEs\u003c/b\u003e\u003c/summary\u003e\n\n   Follow the instructions in your preferred IDE.\n   \u003c/details\u003e\n\n\n   \u003cdetails\u003e\u003csummary\u003e\u003cb\u003eUsing CLI\u003c/b\u003e\u003c/summary\u003e\n\n     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:\n      ```\n      make program TOOLCHAIN=\u003ctoolchain\u003e\n      ```\n\n      Example:\n      ```\n      make program TOOLCHAIN=GCC_ARM\n      ```\n   \u003c/details\u003e\n\n\n4. Once programmed, open your serial terminal software. You should see the shell application displayed as shown follows:\n\n   **Figure 1. Shell application**\n\n   ![](images/shell_start.png)\n\n4. Do the following to install flash read protection using the shell application.\n\n   1. Type `status` to get the status of flash protection and UCB program count.\n\n      ```\n      \u003e\u003e status\n      ```\n\n      **Figure 2. Protection status**\n\n      ![](images/shell_status1.png)\n\n   2. Type `install \u003cpassword0\u003e \u003cpassword1\u003e` to install flash protection.\n\n      The device will reset after this command for the changes to take effect.\n\n      For example:\n\n      ```\n      \u003e\u003e install 1234 5678\n      ```\n\n      **Figure 3. Install protection**\n\n      ![](images/shell_install.png)\n\n   3. Check the status to see if the flash protection is successful. The UCB program count will also be displayed.\n\n      ```\n      \u003e\u003e status\n      ```\n\n      **Figure 4. Protection status**\n\n      ![](images/shell_status2.png)\n\n   4. Type `disable \u003cpassword0\u003e \u003cpassword1\u003e` to disable the flash protection temporarily. Use the same credentials used in Step 2.\n\n      ```\n      \u003e\u003e disable 1234 5678\n      ```\n\n      **Figure 5. Disable protection**\n\n      ![](images/shell_disable.png)\n\n   5. Type `resume` to re-enable the flash protection installed earlier.\n\n      ```\n      \u003e\u003e resume\n      ```\n\n      **Figure 6. Resume protection**\n\n      ![](images/shell_resume.png)\n\n   6. Type `uninstall \u003cpassword0\u003e \u003cpassword1\u003e` to uninstall flash protection. Use the same credentials used in Step 2.\n\n      The device will reset after this command for the changes to take effect.\n\n      ```\n      \u003e\u003e uninstall 1234 5678\n      ```\n\n      **Figure 7. Uninstall protection**\n\n      ![](images/shell_uninstall.png)\n\n   7. Check the status to see if flash protection was uninstalled successfully.\n\n      ```\n      \u003e\u003e status\n      ```\n\n      **Figure 8. Protection status**\n\n      ![](images/shell_status3.png)\n\n\u003cbr\u003e\n\n\n## Debugging\n\n\nYou can debug the example to step through the code.\n\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eIn Eclipse IDE\u003c/b\u003e\u003c/summary\u003e\n\nUse the **\\\u003cApplication Name\u003e Debug (JLink)** configuration in the **Quick Panel**. For details, see the \"Program and debug\" section in the [Eclipse IDE for ModusToolbox\u0026trade; user guide](https://www.infineon.com/MTBEclipseIDEUserGuide).\n\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eIn other IDEs\u003c/b\u003e\u003c/summary\u003e\n\nFollow the instructions in your preferred IDE.\n\u003c/details\u003e\n\n\n\n## Design and implementation\n\n*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.\n\nIn this code example, UCB0 is programmed to implement global flash read protection. The code example firmware flow is illustrated below:\n\n**Figure 9. Firmware flow diagram**\n\n![](images/block_diagram.png)\n\nThe code example uses a shell application to take input commands from the user to perform five different operations:\n\nCommand | Arguments | Description\n------- | --------- | -----------------\n`install` | `\u003cpwd0\u003e \u003cpwd1\u003e` |  Programs global flash read protection on the flash rows with passwords `pwd0` and `pwd1`\n`uninstall` | `\u003cpwd0\u003e \u003cpwd1\u003e` | Removes flash protection with previously configured passwords\n`disable` | `\u003cpwd0\u003e \u003cpwd1\u003e` | Disables flash protection temporarily with previously configured passwords\n`resume` | None | Re-enables previously configured flash protection\n`status` | None | Displays the flash protection status\n\n\u003cbr\u003e\n\n**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.**\n\n\n## Resources and settings\n\nThe 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.\n\n**Figure 10. USIC (UART) settings**\n\n![](images/design_modus.png)\n\n\n**Figure 11. UART Rx pin settings**\n\n![](images/rx.png)\n\n\n**Figure 12. UART Tx pin settings**\n\n![](images/tx.png)\n\n## Debugging\nYou can debug the example to step through the code. In the IDE, use the **\\\u003cApplication Name\u003e Debug (JLink)** configuration in the **Quick Panel**. For more details, see the \"Program and debug\" section in the [Eclipse IDE for ModusToolbox\u0026trade; software user guide](https://www.infineon.com/MTBEclipseIDEUserGuide).\n\n\n## Related resources\nResources | Links\n----------|--------\nKit guides  | [XMC4700 relax kit V1](https://www.infineon.com/dgdl/Infineon-Board_User_Manual_XMC4700_XMC4800_Relax_Kit_Series-UM-v01_02-EN.pdf?fileId=5546d46250cc1fdf01513f8e052d07fc)\nCode examples  | [Using ModusToolbox\u0026trade; software](https://github.com/Infineon/Code-Examples-for-ModusToolbox-Software) on GitHub\nDevice documentation | [XMC4000 family datasheets](https://www.infineon.com/cms/en/product/microcontroller/32-bit-industrial-microcontroller-based-on-arm-cortex-m/32-bit-xmc4000-industrial-microcontroller-arm-cortex-m4/#document-group-myInfineon-49) \u003cbr\u003e [XMC4000 family technical reference manuals](https://www.infineon.com/cms/en/product/microcontroller/32-bit-industrial-microcontroller-based-on-arm-cortex-m/32-bit-xmc4000-industrial-microcontroller-arm-cortex-m4/#document-group-myInfineon-44)\nDevelopment kits | [XMC\u0026trade; MCU eval boards](https://www.infineon.com/cms/en/product/microcontroller/32-bit-industrial-microcontroller-based-on-arm-cortex-m/#boards)\nLibraries on GitHub | [mtb-xmclib-cat3](https://github.com/Infineon/mtb-xmclib-cat3) – XMC\u0026trade; MCU peripheral library (XMCLib) and docs\nTools | [Eclipse IDE for ModusToolbox\u0026trade; software](https://www.infineon.com/modustoolbox) – ModusToolbox\u0026trade; 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\u0026trade; Wi-Fi and Bluetooth® connectivity devices.\n\n## Other resources\n\nInfineon 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.\n\nFor XMC\u0026trade; MCU devices, see [32-bit XMC™ industrial microcontroller based on Arm® Cortex®-M](https://www.infineon.com/cms/en/product/microcontroller/32-bit-industrial-microcontroller-based-on-arm-cortex-m/).\n\n## Document history\n\nDocument title: *CE232719* - *XMC\u0026trade; MCU: Flash protection*\n\n Version | Description of change\n ------- | ---------------------\n 1.0.0   | New code example |\n 1.1.0   | Added support for new kits |\n 2.0.0   | Updated to support ModusToolbox™ software v3.0; CE will not be backward compatible with previous versions of ModusToolbox™ software |\n 2.1.0   | Added support for new kits |\n 2.1.1   | Updated README |\n 2.2.0   | Updated code to use retarget-io-cat3 middleware for shell operations |\n 2.2.1   | Removed a redundant function prototype |\n------\n\nAll other trademarks or registered trademarks referenced herein are the property of their respective owners.\n\n© 2025 Infineon Technologies AG\n\nAll Rights Reserved.\n\n### Legal disclaimer\n\nThe 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.\n\n### Information\n\nFor further information on technology, delivery terms and conditions and prices, please contact the nearest Infineon Technologies Office (www.infineon.com).\n\n### Warnings\n\nDue to technical requirements, components may contain dangerous substances. For information on the types in question, please contact the nearest Infineon Technologies Office.\n\nInfineon 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.\n\n-------------------------------------------------------------------------------\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfineon%2Fmtb-example-xmc-flash-protection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfineon%2Fmtb-example-xmc-flash-protection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfineon%2Fmtb-example-xmc-flash-protection/lists"}