{"id":109,"date":"2014-03-25T20:51:27","date_gmt":"2014-03-25T20:51:27","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=109"},"modified":"2015-07-19T08:39:47","modified_gmt":"2015-07-19T15:39:47","slug":"arm-kinetis","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/kinetis\/","title":{"rendered":"Creating Freescale Kinetis projects with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to develop a basic project for a Freescale Kinetis microcontroller (we will use TWR-KD40D100M module here) using Visual Studio, the built-in OSBDM\/OSJTAG circuit and an external JTAG\/SWD programmer.<\/p>\n<p>Before we begin, ensure that <a href=\"\/download\">VisualGDB 4.1<\/a> or later is installed.<\/p>\n<ol>\n<li>Start Visual Studio. Open File-&gt;New-&gt;Project. Select VisualGDB Embedded Project Wizard and enter your project name and location: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/01-newprj.png\" alt=\"01-newprj\" width=\"700\" height=\"394\" \/><\/a><\/li>\n<li>The first page allows selecting project type. We do not need to change anything here now:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/02-embedded.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/02-embedded.png\" alt=\"02-embedded\" width=\"702\" height=\"528\" \/><\/a><\/li>\n<li>On the second page select the arm-eabi toolchain. If it&#8217;s not installed, VisualGDB will allow downloading and installing it automatically. Select the <strong> MK40DX256xxx10<\/strong> device (TWR-K40D100M uses PK10DX256VMD10 MCU that is equivalent to MK10DX256VMD10): <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/03-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/03-device.png\" alt=\"03-device\" width=\"702\" height=\"528\" \/><\/a><\/li>\n<li>If you don&#8217;t see Freescale devices in the list, click &#8220;Download support for more devices&#8221; and select &#8220;Freescale Kinetis&#8221; from the list:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/04-kinetis-bsp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/04-kinetis-bsp.png\" alt=\"04-kinetis-bsp\" width=\"500\" height=\"300\" \/><\/a><\/li>\n<li>Once you continue to the next page VisualGDB will test the ARM toolchain to ensure that it can build valid projects for the selected device:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/05-test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/05-test.png\" alt=\"05-test\" width=\"484\" height=\"294\" \/><\/a><\/li>\n<li>The next page allows customizing the generated project. As the TWR-K40D100M board has a green LED connected to PTC9, select &#8220;PTC&#8221; and &#8220;9&#8221; as the LED port group and port number:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/06-ledport.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/06-ledport.png\" alt=\"06-ledport\" width=\"702\" height=\"528\" \/><\/a><\/li>\n<li>The last page allows selecting the debug method. We will use the OpenOCD tool to debug our board using on-board OSJTAG\/OSBDM interface. Click &#8220;Install support for additional debug methods&#8221; and select OpenOCD:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/07-openocd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/07-openocd.png\" alt=\"07-openocd\" width=\"488\" height=\"307\" \/><\/a><\/li>\n<li>Select &#8220;OSBDM&#8221; as the interface and press &#8220;Test selected OpenOCD settings&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/08-openocd-config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/08-openocd-config.png\" alt=\"08-openocd-config\" width=\"702\" height=\"586\" \/><\/a><\/li>\n<li>VisualGDB will run OpenOCD and ensure that it can find your device:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/13-tested.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/13-tested.png\" alt=\"13-tested\" width=\"663\" height=\"542\" \/><\/a><\/li>\n<li>You can also switch to the manual mode and change OpenOCD scripts explicitly:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/10a-manual.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/10a-manual.png\" alt=\"10a-manual\" width=\"702\" height=\"655\" \/><\/a><\/li>\n<li>If OpenOCD refuses to find your device, you may need to install the LibUSB driver for it manually:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/09-driver.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/09-driver.png\" alt=\"09-driver\" width=\"609\" height=\"450\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to complete the wizard. VisualGDB will generate a basic Visual Studio project. Press Ctrl-Shift-B to build it:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/14-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/14-build.png\" alt=\"14-build\" width=\"698\" height=\"614\" \/><\/a><\/li>\n<li>Press F5 to start debugging. The green LED will start blinking slowly. Put a breakpoint on the PCOR line and wait until it is hit:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/15-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/15-bkpt.png\" alt=\"15-bkpt\" width=\"698\" height=\"614\" \/><\/a><\/li>\n<li>See how the green LED on the right side of the board is currently off:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/led_off.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/led_off.png\" alt=\"led_off\" width=\"700\" height=\"488\" \/><\/a><\/li>\n<li>Press F10 to step over the line. See how the green LED turns on:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/led_on.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/led_on.png\" alt=\"led_on\" width=\"700\" height=\"536\" \/><\/a><\/li>\n<li>\u00a0Currently we have built our project to go into the<br \/>\nFLASH memory. It means that the previous FLASH contents were<br \/>\nreplaced by our test program, taking some time and consuming<br \/>\nrewrite cycles. We can avoid it by making the program run<br \/>\nfrom SRAM. Stop debugging by pressing Shift-F5, right-click<br \/>\non the project in Solution Explorer and select VisualGDB<br \/>\nProject Properties. Click &#8220;Change settings&#8221; and select<br \/>\n&#8220;SRAM&#8221; in the bottom of the page:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/16-sram.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/16-sram.png\" alt=\"16-sram\" width=\"700\" height=\"613\" \/><\/a><\/li>\n<li>Press OK, rebuild your project and start debugging it. Put a breakpoint somewhere and examine the <strong>$pc<\/strong> value ($pc is the program counter register that holds the address of the current instruction). You will see that it points inside the SRAM region as our program is now running from SRAM:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/17-rampc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/17-rampc.png\" alt=\"17-rampc\" width=\"698\" height=\"614\" \/><\/a><\/li>\n<li>Using OpenOCD with the built-in OSJTAG\/OSBDM interface can be slow and instable. As an alternative you can use a third-party JTAG\/SWD programmer\/debugger. In this tutorial we will show how to use Segger J-Link to debug your firmware. Open VisualGDB Project Properties, go to Debug Settings page, click &#8220;Install Support for additional debug methods&#8221; and select Segger J-Link:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/18-getsegger.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-18\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/18-getsegger.png\" alt=\"18-getsegger\" width=\"488\" height=\"307\" \/><\/a><\/li>\n<li>Specify the path to your Segger tools and select the SWD interface:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/19-segger.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-19\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/19-segger.png\" alt=\"19-segger\" width=\"700\" height=\"545\" \/><\/a><\/li>\n<li>Connect the debugger to the OSJTAG port on the board using the Cortex adapter. Press F5 to start your debugging session: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/segger.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/arm\/kinetis\/segger.png\" alt=\"segger\" width=\"700\" height=\"255\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to develop a basic project for a Freescale Kinetis microcontroller (we will use TWR-KD40D100M module here)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[53,57],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/109"}],"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=109"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/109\/revisions\/193"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}