{"id":6792,"date":"2020-10-13T12:17:52","date_gmt":"2020-10-13T19:17:52","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=6792"},"modified":"2020-10-13T12:17:52","modified_gmt":"2020-10-13T19:17:52","slug":"porting-mbed-projects-to-custom-boards","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/mbed\/customboards\/","title":{"rendered":"Porting Mbed Projects to Custom Boards"},"content":{"rendered":"<p>This tutorial shows how to port mbed projects to custom boards. We will create a basic project targeting the <strong>STM32F4Discovery<\/strong> board using the Mbed project wizard and will show how to create a custom project-wide board definition based on it.<\/p>\n<p>Before you begin, install VisualGDB 5.5 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Mbed Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/wiz.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6793\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/wiz.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Enter the name and location of the project you would like to create:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/01-name.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6794\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/01-name.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Proceed with the default option of creating a new project that will include its own mbed checkout: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/02-checkout.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6795\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/02-checkout.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>On the next page of the wizard select your mbed target. In this tutorial we will target the STM32F4Discovery board, so select <strong>DISCO_F407VG<\/strong> from the list:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/03-target-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6796\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/03-target-1.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>The next page of the wizard allows selecting debug settings. Connect your development board via USB and let VisualGDB detect the settings automatically:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/04-stlink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6797\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/04-stlink.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a> When done, click &#8220;Finish&#8221; to generate the project.<\/li>\n<li>Build the project by pressing Ctrl-Shift-B. If you get an error on the <strong>sleep_for()<\/strong> line, try changing &#8220;500ms&#8221; to just &#8220;500&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/05-pins.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6798\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/05-pins.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a>Note how the <strong>main()<\/strong> function toggles the <strong>LED1<\/strong> pin that is defined differently for each target. Try using the Go-to-Definition command to locate the definition of LED1 in <strong>&lt;mbed checkout&gt;\\targets\\&lt;&#8230;&gt;\\TARGET_DISCO_F407VG\\PeripheralPins.h<\/strong>.<\/li>\n<li>The <strong>TARGET_DISCO_F407VG<\/strong> folder under <strong>&lt;mbed checkout&gt;\\targets<\/strong> contains files specific to the STM32F4Discovery board . Mbed will automatically select the source and header files from it once you select DISCO_F407VG as your target. However, as the folder is a part of the mbed repository and is not checked into your project&#8217;s source control, any changes made to files in it won&#8217;t be saved properly. In order to make changes to board-specific files, we will first need to clone it under the project directory. Right-click on the project in Solution Explorer and select &#8220;<strong>Target a Custom Board<\/strong>&#8220;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/06-board.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6799\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/06-board.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<li>VisualGDB will ask for the new target name. Once you click OK, VisualGDB will copy the target files in the <strong>&lt;Project Directory&gt;\\TARGET_&lt;New Target&gt;<\/strong> directory:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/07-clone.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6800\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/07-clone.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<li>VisualGDB will also copy the target definition to the <strong>&lt;Project Directory&gt;\\custom_targets.json<\/strong> file so that mbed-cli tools can find it. Once the target is cloned, VisualGDB will create a separate solution configuration for the cloned board: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/08-created.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6801\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/08-created.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<li>Switch the solution configuration to <strong>MY_F407_BOARD <\/strong>and go to the definition of LED1. Note how it is now defined in the <strong>&lt;Project Directory&gt;\\TARGET_MY_F407_BOARD\\PinNames.h<\/strong> file. Add a custom <strong>MY_CUSTOM_LED<\/strong> definition after the last LED: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/09-names.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6802\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/09-names.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<li>Now you can change the main program to toggle <strong>MY_CUSTOM_LED<\/strong> instead of <strong>LED1<\/strong>: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/10-led.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6803\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/10-led.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a>You can now freely edit source files in the <strong>TARGET_MY_F407_BOARD<\/strong> folder, as they are now a part of your project and can be checked into source control together with it<\/li>\n<li>When targeting custom boards, the <strong>mbed-cli<\/strong> build tools will load various board-specific parameters from the <strong>&lt;Project Directory&gt;\\custom_targets.json<\/strong> file. You can edit the file to customize the board configuration:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/11-targets.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6804\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/11-targets.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<li>You can remove the platform for the original STM32F4Discovery board by right-clicking on the project node in Solution Explorer and selecting <strong>Add-&gt;Manage mbed boards<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/12-boards.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6805\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/12-boards.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to port mbed projects to custom boards. We will create a basic project targeting the STM32F4Discovery<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[115,84],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6792"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=6792"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6792\/revisions"}],"predecessor-version":[{"id":6806,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6792\/revisions\/6806"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=6792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=6792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=6792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}