Difference between revisions of "How to debug a user space application with STM32CubeIDE/User space shared library project"

[unchecked revision] [quality revision]
(Merge articles)
m
 

This article proposes to manage a shared library, dynamically linked with a Linux® user space application on STM32 MPU.

BackToNavigationTree button.png

1 Create a user space shared library project[edit]

In the Cortex®-A7 sub-project context, named here MP157C-DK2_CA7, right-click and select Create a userspace Project...

User space project wizard shortcut

A Shared Library project type, in C language, is selected. Note that the user space project uses by default the SDK version associated to the Cortex®-A7 sub-project.

User space shared library creation

2 Build[edit]

  • Select your project, right-click and then Build Project.
Shared library build


3 Update myExe project sources & properties, in order to use mySharedLib[edit]

Hereafter is an updated code for main() to call mySharedLib function say_hello().
You must also reference mySharedLib project inside myExe properties: C/C++ General > Paths and Symbols > References, as depicted below.

Executable source & properties update

4 Preparing Debug Configuration[edit]

You can check boot messages via Linux® console opened with butterfly icon, but remember this console cannot be shared outside STM32CubeIDE (minicom,...).

CubeIDELinuxConsole.png

In order to debug user space application, your target must be Linux® booted and network connected.

In order to check network connection, start the Target Status widget in the bottom right corner of the window.

Target Status - green


Check also How to set up proxy and P2P Ethernet connection with STM32CubeIDE if you are in that case.


5 Linux® deployment configuration[edit]

To run or debug the executable myExe and its shared library mySharedLib, it is required to download the shared library object (.so) to the STM32MP15xx device. Select the shared library project, right-click Run as... > Run Configurations, then select STM32 Cortex-A Linux Deployment'.

Run configuration shortcut


Linux deployment configuration

6 Debug Configuration[edit]

Select your project, right-click Debug as... > Debug Configurations, then select STM32 Cortex-A Remote Application'.

The default connection proposed is "MPU SSH", corresponding to the target IP address discovered by the Target Status widget. The default destination directory is /home/root.
For the executable myExe to load the mySharedLib dynamic library, a setup of LD_LIBRARY_PATH with the path to mySharedLib is needed before starting debug.

Debug configuration setup

7 Debug: stepping into mySharedLib[edit]

Click Debug :

  1. Executable is downloaded to the target,
  2. GDBServer is launched on the target,
  3. GDBClient is launched on the workstation and can exchange via the network with GDBServer.
User space shared library debug
Info white.png Information
In case of error; stop any GDBServer running on the target before launching a new debug session.


BackToNavigationTree button.png



This article proposes to manage a shared library, dynamically linked with a Linux<sup>®</sup> user space application on STM32 MPU.<br><br>

[[File:BackToNavigationTree button.png|200px|link=How to debug a user space application with STM32CubeIDE]]

==Create a user space shared library project==
In the Cortex<sup>®</sup>-A7 sub-project context, named here '''MP157C-DK2_CA7''', right-click and select '''''Create a userspace Project...'''''<br>
<br>


[[File:UserSpaceShortCut.png|400px|thumb|center|'''User space project wizard shortcut''']]

A ''Shared Library'' project type, in C language, is selected. Note that the user space project uses by default the SDK version associated to the Cortex<sup>®</sup>-A7 sub-project.<br>
<div class="res-img">

[[File:CubeIDEUserSpaceSharedLibCreation.png|center|'''User space shared library creation''']]</div>

==Build==
*Select your project, right-click and then '''''Build Project'''''.

[[File:CubeIDEUserSpaceSharedLibBuild.png|600px|thumb|center|'''Shared library build''']]<br>

==Update myExe project sources & properties, in order to use mySharedLib==
Hereafter is an updated code for main() to call mySharedLib function say_hello(). <br>

You must also reference mySharedLib project inside myExe properties: ''C/C++ General'' > ''Paths and Symbols'' > ''References'',  as depicted below.<div class="res-img">

[[File:CubeIDEUserSpaceSharedLibExeBuild.png|center|'''Executable source & properties update''']]</div>


==Preparing ''Debug Configuration''==
You can check boot messages via Linux<sup>®</sup> console opened with butterfly icon, but remember this console cannot be shared outside STM32CubeIDE (minicom,...).
[[File:CubeIDELinuxConsole.png|200px|frame|center]] 
In order to debug user space application, your target must be Linux<sup>®</sup> booted and network connected. <br><br>


In order to check network connection, start the '''''Target Status''''' widget in the bottom right corner of the window.
[[File:CubeIDE-UserSpace-Debug1.png|500px|frame|center|'''Target Status - green''']]
{{ReviewsComments | [[User:Ludovic Bergonzi|Ludovic Bergonzi]] ([[User talk:Ludovic Bergonzi|talk]]) 12:31, 30 May 2021 (CEST) <br /> Same remark about the butterfly wrning not understood.<br> LRa: Revisited}}
<br>
<br>
Check also [[How to set up proxy and P2P Ethernet connection with STM32CubeIDE|How to set up proxy and P2P Ethernet connection with STM32CubeIDE]] if you are in that case. <br>


==''Linux<sup>®</sup> deployment configuration''==
To run or debug the executable ''myExe'' and its shared library ''mySharedLib'', it is required to download the shared library object (.so) to the STM32MP15xx device.  
Select the shared library project, right-click ''Run as...'' > ''Run Configurations'', then select '''STM32 Cortex-A Linux Deployment''''.  <br>
<div class="res-img">

[[File:CubeIDEUserSpaceSharedLibRun.png|center|'''Run configuration shortcut''']]</div>
<br>
<div class="res-img">

[[File:CubeIDEUserSpaceSharedLibRunSetup.png|center|'''Linux deployment configuration''']]</div>


==''Debug Configuration''==
Select your project, right-click ''Debug as...'' > ''Debug Configurations'', then select '''STM32 Cortex-A Remote Application''''.  <br>


The default connection proposed is "MPU SSH", corresponding to the target IP address discovered by the Target Status widget. The default destination directory is ''/home/root''. <br>

For the executable ''myExe'' to load the ''mySharedLib'' dynamic library, a setup of LD_LIBRARY_PATH with the path to ''mySharedLib''  is needed before starting debug. <br>
<div class="res-img">

[[File:CubeIDEUserSpaceSharedLibExeDebugSetup.png|center|'''Debug configuration setup''']]</div>

==Debug: stepping into mySharedLib==
Click '''''Debug''''' :
# Executable is downloaded to the target,
# ''GDBServer'' is launched on the target,
# ''GDBClient'' is launched on the workstation and can exchange via the network with ''GDBServer''.
<div class="res-img">

[[File:CubeIDEUserSpaceSharedLibExeDebug.png|center|'''User space shared library debug''']]</div>


{{Info| In case of error; stop any ''GDBServer'' running on the target before launching a new debug session.}}<br>

[[File:BackToNavigationTree button.png|200px|link=How to debug a user space application with STM32CubeIDE]]
<noinclude>

{{PublicationRequestId | 19680 (LudovicB)  |2021-04-20 }}</noinclude>
Line 33: Line 33:
 
In order to check network connection, start the '''''Target Status''''' widget in the bottom right corner of the window.
 
In order to check network connection, start the '''''Target Status''''' widget in the bottom right corner of the window.
 
[[File:CubeIDE-UserSpace-Debug1.png|500px|frame|center|'''Target Status - green''']]
 
[[File:CubeIDE-UserSpace-Debug1.png|500px|frame|center|'''Target Status - green''']]
 
{{ReviewsComments | [[User:Ludovic Bergonzi|Ludovic Bergonzi]] ([[User talk:Ludovic Bergonzi|talk]]) 12:31, 30 May 2021 (CEST) <br /> Same remark about the butterfly wrning not understood.
 
<br> LRa: Revisited}}
 
   
 
<br>
 
<br>