{"id":5128,"date":"2019-07-23T20:50:26","date_gmt":"2019-07-24T03:50:26","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=5128"},"modified":"2019-07-23T20:50:26","modified_gmt":"2019-07-24T03:50:26","slug":"debugging-linux-projects-on-stm32mp1-devices","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/stm32mp1\/","title":{"rendered":"Debugging Linux projects on STM32MP1 Devices"},"content":{"rendered":"<p>This tutorial shows how to build and debug a basic Linux project for the STM32MP1 device running the OpenSTLinux distro. We will create a basic C++ application and will show how to debug and profile it from Visual Studio with VisualGDB.<\/p>\n<p>Building the Linux projects for the STM32MP1 devices requires a cross-toolchain (also known as SDK) that matches the SD card image used by your board. You can obtain the SDK using one of the following methods:<\/p>\n<ul>\n<li>Build an SD card image and a matching SDK from sources. Follow our <a href=\"https:\/\/visualgdb.com\/tutorials\/linux\/stm32mp1\/sdk\">STM32MP1 SDK building tutorial<\/a> for detailed steps. This requires setting up a separate Linux VM and normally takes several hours, but allows customizing your SD card layout by editing the bitbake scripts.<\/li>\n<li>Alternatively, download prebuilt SD card images and a toolchain from our <a href=\"https:\/\/github.com\/sysprogs\/oe-manifest\/releases\">Github page<\/a>, then install the Linux cross-toolchain on your Linux VM.<\/li>\n<\/ul>\n<p>It is also possible to use a Windows cross-toolchain to build STM32MP1 Linux applications, however this tutorial will show how to use the Linux-based cross-toolchain, as it is the only toolchain type that can be produced fully automatically using BitBake.<\/p>\n<ol>\n<li>Start Visual Studio and launch the VisualGDB&#8217;s Linux project wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/01-wizard.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5129\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/01-wizard.png\" alt=\"\" width=\"1024\" height=\"710\" \/><\/a><\/li>\n<li>Specify the location and name for the project you are creating:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/02-prjname-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5130\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/02-prjname-2.png\" alt=\"\" width=\"1024\" height=\"710\" \/><\/a><\/li>\n<li>On the first page of the wizard select &#8220;Create a new project -&gt; Application -&gt; MSBuild&#8221;: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/03-msbuild-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5131\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/03-msbuild-1.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the second page select the Linux machine where you have installed the OpenSTLinux SDK. If you haven&#8217;t done this yet, follow <a href=\"https:\/\/visualgdb.com\/tutorials\/linux\/stm32mp1\/sdk\">this tutorial<\/a> to build it from sources. Then click &#8220;Specify a Yocto environment file&#8221; in the toolchain selector:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/04-yocto-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5142\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/04-yocto-1.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Point VisualGDB to the <strong>environment-setup<\/strong> script that is a part of the SDK:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/05-conf.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5133\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/05-conf.png\" alt=\"\" width=\"486\" height=\"294\" \/><\/a><\/li>\n<li>VisualGDB will import the environment setup file and will display a summary of the compilation and debugging tools. As the Yocto environment setup files specify the tools via environment variables, most of the tool paths will simply reference those variables (e.g. ${CC}): <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/06-summary.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5134\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/06-summary.png\" alt=\"\" width=\"805\" height=\"429\" \/><\/a><\/li>\n<li>Connect the power and the network to your STM32MP1 board and wait for it to start. Alternatively, you can connect the ST-Link&#8217;s USB connector and use the serial terminal to find out the board&#8217;s IP address and host name (the default hostname should be simply <strong>stm32mp1<\/strong>):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/netconn.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5143\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/netconn.jpg\" alt=\"\" width=\"1280\" height=\"610\" \/><\/a><\/li>\n<li>In the VisualGDB Project Wizard check the &#8220;Deploy the project to another Linux computer&#8221; checkbox and select an SSH connection for your STM32MP1 board. If you are using the default SD card images, the host name for the board will be <strong>stm32mp1<\/strong>, the user name should be <strong>root<\/strong> and the password should be blank:\u00a0 <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/07-deploy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5135\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/07-deploy.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Proceed with the default settings for storing the source code and click &#8220;Finish&#8221; to create the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/08-access.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5136\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/08-access.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Once VisualGDB generates the project, set a breakpoint in the main() function and press F5 to build and run it. Ensure that you see the output from the project in the <strong>gdbserver<\/strong> window:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/09-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5137\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/09-output.png\" alt=\"\" width=\"1135\" height=\"808\" \/><\/a><\/li>\n<li>The OpenSTLinux distro includes the valgrind profiler, so you can easily analyze the performance of your application. Select Analyze-&gt;Analyze Performance with VisualGDB-&gt;Profile withotu debugging:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/10-profile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5138\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/10-profile.png\" alt=\"\" width=\"1135\" height=\"808\" \/><\/a><\/li>\n<li>This will launch a profiling session, showing the amount of CPU time spent in each function and each line of the code:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/11-report.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5139\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/11-report.png\" alt=\"\" width=\"1135\" height=\"808\" \/><\/a><\/li>\n<li>Note that if you are using the default settings, starting a debug session will take several seconds. If you switch the GDB Session window to the &#8220;All GDB Interaction&#8221; mode, you will see that most time is spent by gdb downloading shared libraries from the target:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/12-symbols-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5144\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/12-symbols-1.png\" alt=\"\" width=\"1135\" height=\"808\" \/><\/a><\/li>\n<li>This can be eliminated by explicitly specifying <strong>sysroot<\/strong> &#8211; the location of the build machine containing copies of various system headers and libraries. Normally it would be located under the <strong>sysroots\/cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnueabi<\/strong> subfolder inside the OpenSTLinux SDK. Add the &#8220;<strong>set sysroot &lt;sysroot path&gt;<\/strong>&#8221; command to the additional GDB commands field in VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/13-sysroot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5141\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/13-sysroot.png\" alt=\"\" width=\"1020\" height=\"676\" \/><\/a>Now the debug sessions will start much faster because gdb will use the libraries from the sysroot folder instead of downloading them from the STM32MP1 board.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to build and debug a basic Linux project for the STM32MP1 device running the OpenSTLinux distro.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[33,187],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5128"}],"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=5128"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5128\/revisions"}],"predecessor-version":[{"id":5145,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5128\/revisions\/5145"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=5128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=5128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=5128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}