{"id":2568,"date":"2017-04-07T12:38:30","date_gmt":"2017-04-07T19:38:30","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=2568"},"modified":"2017-04-07T12:40:11","modified_gmt":"2017-04-07T19:40:11","slug":"creating-firmware-for-bluetooth-le-devices-with-mbed","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/mbed\/nordic\/","title":{"rendered":"Creating firmware for Bluetooth LE devices with mbed"},"content":{"rendered":"<p>This tutorial shows how to create a basic virtual UART-over-Bluetooth LE device using VisualGDB and the ARM mbed framework. Before you begin, install the latest VisualGDB and update the mbed package to 5.4.2 or later via Tools-&gt;VisualGDB Package Manager.<\/p>\n<p>In this tutorial we will use a Nordic NRF52_DK board and and Android phone to connect to the board via Bluetooth LE.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2569\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/01-newprj.png\" alt=\"01-newprj\" width=\"887\" height=\"577\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/01-newprj.png 887w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/01-newprj-300x195.png 300w\" sizes=\"(max-width: 887px) 100vw, 887px\" \/><\/a><\/li>\n<li>Select &#8220;Create a new project -&gt; MSBuild -&gt; Embedded Binary&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/02-prjtype.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2570\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/02-prjtype.png\" alt=\"02-prjtype\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/02-prjtype.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/02-prjtype-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>On the next page select &#8220;Use ARM mbed&#8221; and pick your board from the list. We will use the Nordic NRF52_DK board, however the same steps should work for any other nRF5x-based board supported by mbed:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/03-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2571\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/03-device.png\" alt=\"03-device\" width=\"822\" height=\"773\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/03-device.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/03-device-300x282.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a>It is recommended to select &#8220;Newlib-nano&#8221; as the C library and check the &#8220;provide default stubs for system calls&#8221; checkbox to reduce the binary size.<\/li>\n<li>On the &#8220;Sample Selection&#8221; page pick the &#8220;Bluetooth LE UART Console&#8221; sample and press &#8220;Next&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/04-sample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2572\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/04-sample.png\" alt=\"04-sample\" width=\"822\" height=\"597\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/04-sample.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/04-sample-300x218.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Choose a debug method corresponding to your target. Nordic development boards have an integrated Segger J-Link that can be configured as shown below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/05-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2573\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/05-debug.png\" alt=\"05-debug\" width=\"822\" height=\"597\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/05-debug.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/05-debug-300x218.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a>Note that J-Link won&#8217;t automatically detect the exact device name from the mbed target name (like nRF52_DK), so it needs to be selected manually.<\/li>\n<li>Press &#8220;Finish&#8221; to create the project build it with Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06a-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2574\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06a-build.png\" alt=\"06a-build\" width=\"1057\" height=\"722\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06a-build.png 1057w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06a-build-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06a-build-1024x699.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06a-build-130x90.png 130w\" sizes=\"(max-width: 1057px) 100vw, 1057px\" \/><\/a><\/li>\n<li>If the build fails due to inline variable declarations in C files, open VS Project Properties and switch the C language standard to C99:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06-c99.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2575\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06-c99.png\" alt=\"06-c99\" width=\"822\" height=\"558\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06-c99.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/06-c99-300x204.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Connect your Nordic board and press F5 to start debugging. On your Android device launch the <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.nordicsemi.nrfUARTv2&amp;hl=en\">Nordic UART app<\/a> and connect to the virtual UART device:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/07-ble-devices.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2576\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/07-ble-devices-576x1024.png\" alt=\"07-ble-devices\" width=\"250\" height=\"444\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/07-ble-devices-576x1024.png 576w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/07-ble-devices-169x300.png 169w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/07-ble-devices.png 720w\" sizes=\"(max-width: 250px) 100vw, 250px\" \/><\/a><\/li>\n<li>Once you connect to the device, you should see the &#8220;ping&#8221; messages sent by the firmware:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/08-ping.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2577\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/08-ping.png\" alt=\"08-ping\" width=\"250\" height=\"444\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/08-ping.png 720w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/08-ping-169x300.png 169w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/08-ping-576x1024.png 576w\" sizes=\"(max-width: 250px) 100vw, 250px\" \/><\/a><\/li>\n<li>Modify the periodicCallback() function as follows to replace the &#8220;ping&#8221; messages with &#8220;hello&#8221; messages having increasing numbers:\n<pre class=\"\">int g_Counter = 0;\r\n\r\nvoid periodicCallback(void)\r\n{\r\n\u00a0\u00a0 \u00a0led1 = !led1;\r\n\u00a0\u00a0\u00a0 if (uart)\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 char tmp[32];\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sprintf(tmp, \"Hello %d\\n\", g_Counter++);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 uart-&gt;writeString(tmp);\r\n\u00a0\u00a0\u00a0 }\r\n}<\/pre>\n<p>Then press F5 to start debugging:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/09-newcode.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2578\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/09-newcode.png\" alt=\"09-newcode\" width=\"1057\" height=\"722\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/09-newcode.png 1057w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/09-newcode-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/09-newcode-1024x699.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/09-newcode-130x90.png 130w\" sizes=\"(max-width: 1057px) 100vw, 1057px\" \/><\/a><\/li>\n<li>Reconnect to the board from your Android device and see how the displayed messages have changed:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/10-hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2579\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/10-hello.png\" alt=\"10-hello\" width=\"250\" height=\"444\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/10-hello.png 720w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/10-hello-169x300.png 169w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/10-hello-576x1024.png 576w\" sizes=\"(max-width: 250px) 100vw, 250px\" \/><\/a><\/li>\n<li>If you try setting a breakpoint in the periodicCallback() function, it will trigger, but you won&#8217;t be able to continue debugging as the nRF5x watchdog will trigger an internal error: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/11-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2580\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/11-bkpt.png\" alt=\"11-bkpt\" width=\"1057\" height=\"722\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/11-bkpt.png 1057w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/11-bkpt-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/11-bkpt-1024x699.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/11-bkpt-130x90.png 130w\" sizes=\"(max-width: 1057px) 100vw, 1057px\" \/><\/a><\/li>\n<li>To avoid this, we recommend using alternate debugging techniques like Live Variables (right-click on g_Counter to plot its value in real-time) and real-time watch that can show the executed functions in real time:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/12-livevar.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2581\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/12-livevar.png\" alt=\"12-livevar\" width=\"1057\" height=\"722\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/12-livevar.png 1057w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/12-livevar-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/12-livevar-1024x699.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/12-livevar-130x90.png 130w\" sizes=\"(max-width: 1057px) 100vw, 1057px\" \/><\/a><\/li>\n<li>Open VisualGDB Project Properties and go to the Embedded Frameworks page. You will see various mbed libraries and features (like BLE or LWIP) displayed as embedded frameworks. Checking the corresponding frameworks will automatically add them to your project: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/13-frameworks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2582\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/13-frameworks.png\" alt=\"13-frameworks\" width=\"786\" height=\"594\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/13-frameworks.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/13-frameworks-300x227.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>You can also easily retarget an mbed project to a different platform or edit settings like baud rate via the first page of VisualGDB project properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/dev.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2583\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/dev.png\" alt=\"dev\" width=\"901\" height=\"783\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/dev.png 901w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/04\/dev-300x261.png 300w\" sizes=\"(max-width: 901px) 100vw, 901px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create a basic virtual UART-over-Bluetooth LE device using VisualGDB and the ARM mbed framework. Before<\/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":[53,96,133,56,115,95],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2568"}],"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=2568"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2568\/revisions"}],"predecessor-version":[{"id":2584,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2568\/revisions\/2584"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=2568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=2568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=2568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}