Difference between revisions of "Modify, rebuild and reload a firmware"

[quality revision] [quality revision]
m
m (Import an existing example in STM32CubeIDE)
 

Template:ArticleMainWriter

Applicable for STM32MP15x lines

1 Overview[edit]

This stage explains how to modify, rebuild and reload a an STM32MP1 Arm® Cortex®-M4 coprocessor firmware.

It proposes to customize the STM32MP1 Cube Package Application application example "OpenAMP_TTY_Echo using the MPU feature integrated in SW4STM32 IDE.

2 Open SW4STM32 IDE[edit]

  • Open System Workbench for STM32 IDE
File:SW4STM32 workspace.png
SW4STM32 workspace

3 Connect a console to the board[edit]

  • It's very convenient to use the serial console integrated in SW4STM32
File:SW4STM32 workspace serial disconnect 1.png
SW4STM32 Open the serial device by clicking this item
  • Connection is ok if you can see Linux log or prompt.
File:SW4STM32 workspace serial disconnect 2.png
SW4STM32 Serial Consol is ready
  • If for personal reason you prefer using another terminal ( ssh, minicom), it's then recommended to stop the Target Status Widget using the Serial port in SW4STM32 by right click on the bottom right corner then stop
  • It will avoid the following repetitive pattern in your Linux console

root@stm32mp1:~# ifconfig; echo __END__:$?
eth0      Link encap:Ethernet  HWaddr 00:80:E1:42:45:69  
          inet addr:10.48.1.143  Bcast:10.48.3.255  Mask:255.255.252.0
          inet6 addr: fe80::280:e1ff:fe42:4569/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:37 errors:0 dropped:1 overruns:0 frame:0
          TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5776 (5.6 KiB)  TX bytes:3146 (3.0 KiB)
          Interrupt:63 Base address:0xc000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:344 errors:0 dropped:0 overruns:0 frame:0
          TX packets:344 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:22880 (22.3 KiB)  TX bytes:22880 (22.3 KiB)

usb0      Link encap:Ethernet  HWaddr 4A:06:6C:16:19:EC  
          inet addr:192.168.7.2  Bcast:192.168.7.255  Mask:255.255.255.0
          inet6 addr: fe80::4806:6cff:fe16:19ec/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:396 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:115397 (112.6 KiB)

__END__:0

4 Import an existing example in SW4STM32 IDE

" using STM32CubeIDE.

2 Disconnect the "minicom" console[edit]

  • If "minicom" is already opened, please disconnect it to use the STM32CubeIDE built-in serial console.
 Ctrl + A then Q

3 Open STM32CubeIDE[edit]

  • Start STM32CubeIDE
STM32CubeIDE Starter Screen


  • Choose a workspace (default is fine)
  • Notice information provided in the "Information Center page" and close it. (you can open it later on)
STM32CubeIDE Information Center Page


  • Go into your workspace projet view


STM32CubeIDE Project View

4 Import an existing example in STM32CubeIDE[edit]

  • Open the import screen File > Import... and select Existing Project into Workspace
File:SW4STM32 import.png SW4STM32
STM32CubeIDE import screen
  • Browse and select OpenAMP_TTY_echo application example
  • If you are using STM32MP157C-DK2 Discovery kit
  • in the folder matching your board :

$HOME/STM32MPU_workspace/

STM32MP15

STM32MP1-Ecosystem-

v1

v4.

0

1.0/Developer-Package/STM32Cube_FW_MP1_V1.

0

6.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo

If you are using STM32MP157x-EV1 Evaluation board

/STM32CubeIDE

or

$HOME/STM32MPU_workspace/

STM32MP15

STM32MP1-Ecosystem-

v1

v4.

0

1.0/Developer-Package/STM32Cube_FW_MP1_V1.

0

6.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo

  • Click finish
  • /STM32CubeIDE


    • STM32CubeIDE brings a specific project structure for dual core devices such as STM32MP1. A top level project contains sub-projects for each core.
    • Here OpenAMP_TTY_echo top project contains OpenAMP_TTY_echo_CM4 sub project. Keep the 2 projects selected and click on "Finish".
    STM32CubeIDE project selection
    • The OpenAMP_TTY_echo project is open opened and you can browse inside using the left pan
    File:SW4STM32 workspace project open
    • .
    pngSW4STM32 workspace with project open
    OpenAMP_TTY_echo project structure

    5 Build the firmware[edit]

    • Click the build Select project OpenAMP_TTY_Echo_CM4 and click the Build button (the little hammer in the toolbar)
    File:SW4STM32 workspace project build.png
    SW4STM32 build the project
    Build
    STM32CubeIDE build the project


    • "Build" is finished with no error
    File:SW4STM32 workspace project build finished.png
    SW4STM32 build finished with no error

    6 Upload the firmware through Linux console[edit]

    • If you are using STM32MP157C-DK2 Discovery kit
    cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    • If you are using STM32MP157x-EV1 Evaluation board
    cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    • Upload your firmware example into the board
    scp Debug/OpenAMP_TTY_echo.elf root@<board ip address>:/lib/firmware

    7 Start the firmware through Linux console[edit]

    • Verify that no firmware is currently runnig
    cat /sys/class/remoteproc/remoteproc0/state offline

    If offline is displayed, that means that no firmware is currently running. If running is displayed, a firmware is currently running. You shoul then stop it using the following command

    echo stop > /sys/class/remoteproc/remoteproc0/state
    • Set the firmware name to be executed
    echo -n OpenAMP_TTY_echo.elf > /sys/class/remoteproc/remoteproc0/firmware
    • Start the firmware
    echo start > /sys/class/remoteproc/remoteproc0/state
    • Verify that the firmware is runnig
    cat /sys/class/remoteproc/remoteproc0/state running

    8 Upload and start the firmware with SW4STM32[edit]

    Thanks to the STM32-CoPro-MPU which complete SW4STM32 from version 2.8.0, SW4STM32 can manage to load and start a STM32MP1 Arm® Cortex®-M4 coprocessor firmware.

    For doing so open the Debug Configuration ot the OpenAMP_TTY_echo and select "Thru Linux core (Production mode)

    The inet Address of the board should be already filled. Else try to update it thanks to the button on the right

    File:SW4STM32 Production Mode.png
    Select Production mode in Startup pane of Debug Configuration
    When configuration is ok the "Debug" button on the bottom right turn
    STM32CubeIDE build finished with no error

    6 Check connection to the target[edit]

    STM32CubeIDE requires to be connected to Linux running on STM32MP1 device though serial connection.
    This connection is automatically detected and configured when you have put cable on ST-Link port and board has booted.

    You can check you can get Linux log and prompt by clicking on the "STM32 butterfly" button :

    STM32CubeIDE Serial Console button

    Connection is correct if Linux log or prompt are displayed in the console windows.

    STM32CubeIDE Linux Prompt

    Your board might be connected to the PC by Ethernet, either using RJ45 (point to point or VLAN) or USB0 EthernetOverUSB gadget (point to point connection with PC using TypeA-TypeC cable). Screenshot below uses the second solution.

    When serial connection is established, STM32CubeIDE automatically detects the board IP address and displays sit in the "Serial Target widget status" window in bottom right part of the screen.

    STM32Cube Serial Target widget status

    In case different status such as "busy" or "console in use", check you have no other terminal connected and close the console.

    7 Start Debug Session[edit]

    • Select your OpenAMP_TTY_echo_CM4 project
    • Right click on Debug As > Debug configurations... to open the Debug Configurations panel
    • If not already created, create your debug configuration by double clicking on STM32 C/C++ Application and open "Debugger" pane.
    Select Production mode in Startup pane of Debug Configuration
    • Check IP address is correctly filled (1). Else, you can force detection using button on the right (2).
    • Make sure the "Thru Linux core (production mode)" is selected (3)
    • When configuration is correct, the "Debug" button (5) turns to active and you can launch the debug session. Else, error message appears in area (4).

    The Debug in Production Mode STM32CubeIDE needs to use serial connection to the board to manage firmware download.
    If the console is opened, it will request your approval to close it. Answer "yes".

    SSH password popup


    The debug in "production mode" adds the cortex-M firmware transfer to the embedded Linux. This means also in In case of network usage, some specific pop-up appearingappears:

    • the SSH Password is to complete must be completed: the default one is "root".
    SSH password popup
    • the RSA key is to must be approved.
    RSA key popup


    After download of the firmware SW4STM32 will start it and switch , firmware download, STM32CubeIDE switches into Debug Perspective.

    In "production mode", the firmware is not break at main. GDB is simply attached to the running target. You can then use all features of the debugger.

    Info white.png Information
    To benefit of the best GDB debug experience it's recommended to upgrade the onboard ST-Link version with the latest release. You can simply do it from STM32CubeIDE using menu "Help -> ST-Link Upgrade"


    For further information and support on new MPU feature in SW4STM32, refer to Help menu of SW4STM32 "Micro Processor Unit (MPU) Family - MCU support "

    9

    , refer to STM32CubeIDE documentation avaialble in my.st.com

    8 Test the firmware[edit]

    The OpenAMP_TTY_echo_CM firmware do the following:

    • CPU2(CM4) initialize OPenAMP initializes OpenAMP MW which initializes/configures IPCC peripheral through HAL and setup openamp-rpmsg framework infrastructure,
    • CPU2(CM4) creates 2 rpmsg channels for 2 virtual UART instances (UART0 and UART1),
    • CPU2(CM4) is waiting for messages from CPU1(CA7) on these both channels,
    • When CPU2(CM4) receives a message on 1 Virtual UART instance/rpmsg channel, it sends the message back to CPU1(CA7) on the same Virtual UART instance

    If you have used SW4STM32 to load and start the firmware you should reopen the serial console. Reopen the Serial console of STM32CubeIDE and enter following commands :

    • Initialize the ttyRPMSG0 configuration
     stty -onlcr -echo -F /dev/ttyRPMSG0
    
    • Read constantly the ttyRPMSG0 channel in background
     cat /dev/ttyRPMSG0 &
    
    • Send a message on one ttyRPMSG0 channel and recieve receive the echo on the same ttyRPMSG0 channel
     echo "Hello Virtual UART0" > /dev/ttyRPMSG0
    Hello Virtual UART0
    
    • You can perform the same steps with the ttyRPMSG1 channel
    • After playing a while you can Terminate the STM32CubeIDE debug session will stop the firmware
    echo stop > /sys/class/remoteproc/remoteproc0/state
    • If using SW4STM32 just terminate the debug session
    10
    • .

    9 Modify the firmware[edit]

    The original firmware example receives a message for the host on one channel end sent back and acknolegde by returning the same message to the host on the same channel.

    As this is not so obvious on which channel the message is received, we propose you to modify the firmware in order to add an indication to know what is the channel that is receiving the message. Please

    For that, please modify main.c original code as follow:

    File:SW4STM32 workspace project modification.png
    SW4STM32 main.c file modification
      /* Infinite loop */
      /* USER CODE BEGIN WHILE */
      while (1)
      {
    
        OPENAMP_check_for_message();
    
        /* USER CODE END WHILE */
        if (VirtUart0RxMsg) {
          char msg_to_transmit[MAX_BUFFER_SIZE];
          int msg_size = 0;
          VirtUart0RxMsg = RESET;
    
          msg_size = snprintf(msg_to_transmit, MAX_BUFFER_SIZE, "Channel RPMSG0: ");
          msg_size += snprintf(msg_to_transmit + msg_size, MAX_BUFFER_SIZE, "%s\n", VirtUart0ChannelBuffRx);
          log_info("size of the message to transmit = %d bytes\n", msg_size);
          VIRT_UART_Transmit(&huart0, (uint8_t*)msg_to_transmit, msg_size);
        }
    
        if (VirtUart1RxMsg) {
          char msg_to_transmit[MAX_BUFFER_SIZE];
          uint16_t msg_size = 0;
          VirtUart1RxMsg = RESET;
    
          msg_size = snprintf(msg_to_transmit, MAX_BUFFER_SIZE, "Channel RPMSG1: ");
          msg_size += snprintf(msg_to_transmit + msg_size, MAX_BUFFER_SIZE, "%s\n", VirtUart1ChannelBuffRx);
          log_info("size of the message to transmit = %d bytes\n", msg_size);
          VIRT_UART_Transmit(&huart1, (uint8_t*)msg_to_transmit, msg_size);
        }
        /* USER CODE BEGIN 3 */
      }
      /* USER CODE END 3 */
    
    • Save your modifications
    11 Rebuild, reload and test
    • .

    10 Testing the modified firmware[edit]

    1110.1 Rebuild Relaunch debug session[edit]

    • Click the build button (the little hammer in the toolbar)
    • Wait the end of the build

    11.2 Reload though Linux console[edit]

    • If you are using STM32MP157C-DK2 Discovery kit
    cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    • If you are using STM32MP157x-EV1 Evaluation board
    cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    • Upload your firmware example into the board
    scp Debug/OpenAMP_TTY_echo.elf root@<board ip address>:/lib/firmware

    11.3 Start through Linux console[edit]

    • Verify that no firmware is currently running
    cat /sys/class/remoteproc/remoteproc0/state offline

    If "offline" is displayed, that means that no firmware is currently running. If "running" is displayed, a firmware is currently running. You should then stop it using the following command:

    echo stop > /sys/class/remoteproc/remoteproc0/state
    • Set the firmware name to be executed
    echo -n OpenAMP_TTY_echo.elf > /sys/class/remoteproc/remoteproc0/firmware
    • Start the firmware
    echo start > /sys/class/remoteproc/remoteproc0/state
    • Verify that the firmware is runnig
    cat /sys/class/remoteproc/remoteproc0/state running

    11.4 Reload and start with SW4STM32[edit]

    Just relaunch the debug session but reply "No" to following popup in order to force load of the updated firmware.

    File:Force Load of the updated binary.png
    Force Load of the updated firmware
    11.5
    • By clicking on the "Debug" button, STM32CubeIDE relaunches the debug session after performing an incremental build to take into account your modification .
    • If everything is correct, you will be back switch to "Debug Perspective" windows after reload of the new firmware.

    10.2 Test[edit]

    • Initialize the ttyRPMSG0 and ttyRPMSG1 configurations
     stty -onlcr -echo -F /dev/ttyRPMSG0
     stty -onlcr -echo -F /dev/ttyRPMSG1
    
    • Read constantly the ttyRPMSG0 and ttyRPMSG1 channels in background
     cat /dev/ttyRPMSG0 &
     cat /dev/ttyRPMSG1 &
    
    • Send a message on one ttyRPMSG0 channel and check the echo log
     echo "Hello Virtual UART0" > /dev/ttyRPMSG0
    Channel RPMSG0: Hello Virtual UART0
    
    • Send a message on one ttyRPMSG1 channel and check the echo log
     echo "Hello Virtual UART1" > /dev/ttyRPMSG1
    Channel RPMSG1: Hello Virtual UART1
    


    Info white.png Information
    When the firmware is running, you can output log from the firmware by using the following command:
    cat /sys/kernel/debug/remoteproc/remoteproc0/trace0
    • After playing a while you can stop the firmware
    echo stop > /sys/class/remoteproc/remoteproc0/state


    • For SW4STM32, just terminate the debug sessionTerminate the STM32CubeIDE debug session.
    <noinclude>
    
    {{ArticleMainWriter | VincentA}}
    [[Category:Sub-articles]]
    __NOTOC__</noinclude>
    
    {{ApplicableFor
    |MPUs list=STM32MP15x
    |MPUs checklist=STM32MP13x, STM32MP15x
    }}</noinclude>
    ==Overview==
    This stage explains how to modify, rebuild and reload aan STM32MP1 Arm® Cortex®-M4 coprocessor firmware.
    
    It proposes to customize the STM32MP1 Cube Package Applicationapplication example "OpenAMP_TTY_Echo" using the MPU feature integrated in SW4STM32 IDE.
    
    ==Open SW4STM32 IDE==
    * Open System Workbench for STM32 IDE
    [[File: SW4STM32_workspace.png|thumb|upright=2|center|link=|SW4STM32 workspace]]
    
    ==Connect a console to the board ==
    
    * It's very convenient to use the serial console integrated in SW4STM32  
    [[File: SW4STM32_workspace_serial_disconnect_1.png|thumb|upright=2|center|link=|SW4STM32 Open the serial device by clicking this item]]
    
    * Connection is ok if you can see Linux log or prompt. 
    [[File: SW4STM32_workspace_serial_disconnect_2STM32CubeIDE.
    
    ==Disconnect the "minicom" console==
    * If "minicom" is already opened, please disconnect it to use the STM32CubeIDE built-in serial console.
     {{PC$}} Ctrl + A then Q
    
    ==Open STM32CubeIDE ==
    * Start STM32CubeIDE
    [[File:STM32CubeIDE Starter.png|thumb|upright=2|center|link=|SW4STM32 Serial Consol is ready ]]
    
    * If for personal reason you prefer using another terminal ( ssh, minicom), it's then recommended to stop the Target Status Widget using the Serial port in SW4STM32 by right click on the bottom right corner then stop 
    
    [[File:Stop Serial widget zoom.png|thumb|upright=2|center|link=Stop the Target Status Widget]]
    
    * It will avoid the following repetitive pattern in your Linux console<pre>
    
    root@stm32mp1:~# ifconfig; echo __END__:$?
    eth0      Link encap:Ethernet  HWaddr 00:80:E1:42:45:69  
              inet addr:10.48.1.143  Bcast:10.48.3.255  Mask:255.255.252.0
              inet6 addr: fe80::280:e1ff:fe42:4569/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:37 errors:0 dropped:1 overruns:0 frame:0
              TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:5776 (5.6 KiB)  TX bytes:3146 (3.0 KiB)
              Interrupt:63 Base address:0xc000 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:344 errors:0 dropped:0 overruns:0 frame:0
              TX packets:344 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:22880 (22.3 KiB)  TX bytes:22880 (22.3 KiB)
    
    usb0      Link encap:Ethernet  HWaddr 4A:06:6C:16:19:EC  
              inet addr:192.168.7.2  Bcast:192.168.7.255  Mask:255.255.255.0
              inet6 addr: fe80::4806:6cff:fe16:19ec/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:396 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:115397 (112.6 KiB)
    
    __END__:0</pre>
    
    STM32CubeIDE Starter Screen]]
    
    * Choose a workspace (default is fine) 
    
    * Notice information provided in the "Information Center page" and close it. (you can open it later on) 
    
    [[File:STM32CubeIDE_info.png|800px|link=|center|STM32CubeIDE Information Center Page]]
    
    
    * Go into your workspace projet view 
    
    
    [[File:STM32CubeIDE Default.png|800px|link=|center|STM32CubeIDE Project View]]
    ==Import an existing example in SW4STM32 IDE==STM32CubeIDE==
    * Open the import screen  '''File > Import...''' and select '''Existing Project into Workspace''' 
    [[File: SW4STM32_importSTM32CubeIDE Import.png|thumb|upright=2|center|link=|SW4STM32STM32CubeIDE import screen]]
    * Browse and select '''OpenAMP_TTY_echo''' application example :* If you are using STM32MP157C-DK2 Discovery kit
    ::'''$HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2in the folder matching your board :
    
    ''$HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v4.1.0/Developer-Package/{{EcosystemRelease/Package | revision=latest | package=STM32CubeMP1 | request=path}}/Projects/'''STM32MP157C-DK2'''/Applications/OpenAMP/OpenAMP_TTY_echo'''
    :* If you are using STM32MP157x-EV1 Evaluation board
    ::'''$HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/STM32CubeIDE'' 
    
    or 
    
    ''$HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v4.1.0/Developer-Package/{{EcosystemRelease/Package | revision=latest | package=STM32CubeMP1 | request=path}}/Projects/'''STM32MP157C-EV1'''/Applications/OpenAMP/OpenAMP_TTY_echo'''
    * Click finish
    * /STM32CubeIDE'' 
    
    * STM32CubeIDE brings a specific project structure for dual core devices such as STM32MP1. A top level project contains sub-projects for each core. 
    * Here '''OpenAMP_TTY_echo''' top project contains '''OpenAMP_TTY_echo_CM4''' sub project. Keep the 2 projects selected and click on "Finish". 
    
    [[File:STMCubeIDE import project.png|thumb|upright=2|center|link=|STM32CubeIDE project selection]]
    
    * The '''OpenAMP_TTY_echo''' project is openopened and you can browse inside using the left pan
    .
    [[File: SW4STM32_workspace_STMCubeIde project_open structure.png|thumb|upright=2|center|link=|SW4STM32 workspace with project openOpenAMP_TTY_echo project structure]]
    
    ==Build the firmware==
    * Click the buildSelect project '''OpenAMP_TTY_Echo_CM4''' and click the '''Build''' button (the little hammer in the toolbar)
    [[File: SW4STM32_workspace_project_build.png|thumb|upright=2|center|link=|SW4STM32 build the project]]
    
    * BuildSTM32CubeIDE Build.png|800px|center|link=|STM32CubeIDE build the project]]
    
    * "Build" is finished with no error
    [[File: SW4STM32_workspace_project_build_finished.png|thumb|upright=2|center|link=|SW4STM32STM32CubeIDE Build complete.png|800px|center|link=|STM32CubeIDE build finished with no error]]
    
    ==Upload the firmware through Linux console ==
    * If you are using STM32MP157C-DK2 Discovery kit
     {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    * If you are using STM32MP157x-EV1 Evaluation board
     {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    * Upload your firmware example into the board
     {{PC$}} scp Debug/OpenAMP_TTY_echo.elf root@<board ip address>:/lib/firmware
    
    ==Start the firmware through Linux console ==
    * Verify that no firmware is currently runnig
     {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
     offline
    If offline is displayed, that means that no firmware is currently running. If running is displayed, a firmware is currently running. You shoul then stop it using the following command
     {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
    * Set the firmware name to be executed
     {{Board$}} echo -n OpenAMP_TTY_echo.elf > /sys/class/remoteproc/remoteproc0/firmware
    * Start the firmware
     {{Board$}} echo start > /sys/class/remoteproc/remoteproc0/state
    * Verify that the firmware is runnig
     {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
     running
    
    == Upload and start the firmware with SW4STM32 ==
    
    Thanks to the STM32-CoPro-MPU which complete SW4STM32 from version 2.8.0, SW4STM32 can manage to load and start a STM32MP1 Arm® Cortex®-M4 coprocessor firmware. 
    
    For doing so open the Debug Configuration ot the OpenAMP_TTY_echo and select "Thru Linux core (Production mode) 
    
    The inet Address of the board should be already filled. Else try to update it thanks to the button on the right
    
    [[File:SW4STM32 Production Mode.png|thumb|upright=4|Check connection to the target ==
    
    STM32CubeIDE requires to be connected to Linux running on STM32MP1 device though serial connection.<br>
    
    This connection is automatically detected and configured when you have put cable on ST-Link port and board has booted. 
    
    You can check you can get Linux log and prompt by clicking on the "STM32 butterfly" button : 
    
    [[File:STM32CubeIDE ConsoleButton.png|thumb|upright=2|center|link=|STM32CubeIDE Serial Console button]]
    
    Connection is correct if Linux log or prompt are displayed in the console windows.
    {{ReviewsComments|-- [[User:Nathalie Sangouard|Nathalie Sangouard]] ([[User talk:Nathalie Sangouard|talk]]) 11:54, 21 February 2020 (CET)<br />Below, Image is fuzzy, to be reworked }}
    [[File:STM32CubeIDE prompt.png|600px|center|link=|STM32CubeIDE Linux Prompt]]
    Your board might be connected to the PC by Ethernet, either using RJ45  (point to point or VLAN) or USB0 EthernetOverUSB gadget (point to point connection with PC using TypeA-TypeC cable). Screenshot below uses the second solution. 
    
    When serial connection is established, STM32CubeIDE automatically detects the board IP address and displays sit in the "Serial Target widget status" window in bottom right part of the screen. 
    
    [[File:STM32CubeIDE Serial widget.png|thumb|upright=2|center|link=|STM32Cube Serial Target widget status]]
    
    In case different status such as "busy" or "console in use", check you have no other terminal connected and close the console.
    
    ==Start Debug Session ==
    
    *Select your '''OpenAMP_TTY_echo_CM4''' project
    
    *Right click on '''Debug As > Debug configurations...''' to open the ''Debug Configurations'' panel
    
    *If not already created, create your debug configuration by double clicking on '''STM32 C/C++ Application''' and open "Debugger" pane. 
    
    [[File:STM32CubeIDE Debug conf numbered.png|800px|center|link=|Select Production mode in Startup pane of Debug Configuration]]
    When configuration is ok the "Debug" button on the bottom right turn * Check IP address is correctly filled (1). Else, you can force detection using button on the right (2).
    * Make sure the "Thru Linux core (production mode)" is selected (3) 
    * When configuration is correct, the "Debug" button (5) turns to active and you can launch the debug session. 
    
    
    The Debug in Production ModeElse, error message appears in area (4). 
    
    STM32CubeIDE needs to use serial connection to the board to manage firmware download. <br>
    
    If the console is opened, it will request your approval to close it. Answer "yes". 
    
    [[File:STM32CubeIDE prompt close active console.png|thumb|upright=2|center|link=|SSH password popup]]
    
    The debug in "production mode" adds the cortex-M firmware transfer to the embedded Linux. This means also in In case of network usage, some specific pop-up appearingappears: 
    
    * the ''SSH Password is to complete'' must be completed: the default one is "root".
    
    [[File:DebugCfg-Launch-PM-EnterPwd.png|thumb|upright=2|center|link=|SSH password popup]]
    
    * the ''RSA key is to '' must be approved. 
    
    [[File:DebugCfg-Launch-PM-RSA.png|thumb|upright=2|center|link=|RSA key popup]]
    
    
    After , firmware download of the firmware SW4STM32 will start it and switch into Debug Perspective. , STM32CubeIDE switches into ''Debug Perspective''. <br>
    
    
    In "production mode", the firmware is not break at main. GDB is simply attached to the running target. You can then use all features of the debugger. 
    For further information and support on new MPU feature in SW4STM32, refer to Help menu of SW4STM32 "Micro Processor Unit (MPU) Family - MCU support "
    {{Info| To benefit of the best GDB debug experience it's recommended to upgrade the onboard ST-Link version with the latest release. You can simply do it from STM32CubeIDE using menu "Help -> ST-Link Upgrade"}}
    
    For further information,  refer to STM32CubeIDE documentation avaialble in [https://my.st.com/content/my_st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-ides/stm32cubeide.html my.st.com]
    ==Test the firmware==
    The '''OpenAMP_TTY_echo_CM''' firmware do the following:
    *CPU2(CM4) initialize OPenAMPinitializes OpenAMP MW which initializes/configures IPCC peripheral through HAL and setup openamp-rpmsg framework infrastructure,
    
    *CPU2(CM4) creates 2 rpmsg channels for 2 virtual UART instances (UART0 and UART1),
    
    *CPU2(CM4) is waiting for messages from CPU1(CA7) on these both channels,
    
    *When CPU2(CM4) receives a message on 1 Virtual UART instance/rpmsg channel, it sends the message back to CPU1(CA7) on the same Virtual UART instance
    If you have used SW4STM32 to load and start the firmware you should reopen the serial console. 
    Reopen the Serial console of STM32CubeIDE and enter following commands : * Initialize the ttyRPMSG0 configuration
     {{Board$}} stty -onlcr -echo -F /dev/ttyRPMSG0
    * Read constantly the ttyRPMSG0 channel in background
     {{Board$}} cat /dev/ttyRPMSG0 &
    * Send a message on one ttyRPMSG0 channel and recievereceive the echo on the same ttyRPMSG0 channel
     {{Board$}} echo "Hello Virtual UART0" > /dev/ttyRPMSG0
     Hello Virtual UART0
    * You can perform the same steps with the ttyRPMSG1 channel
    
    
    * After playing a while you can stop the firmware
     {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
    
    * If using SW4STM32 just terminate the debug session
    * Terminate the STM32CubeIDE debug session will stop the firmware.
    ==Modify the firmware==
    The original firmware example receives a message for the host on one channel end sent back and acknolegde by returning the same message to the host on the same channel.<br>
    
    
    As this is not so obvious on which channel the message is received, we propose you to modify the firmware in order to add an indication to know what is the channel that is receiving the message.<br>
    
    Please 
    
    
    For that, please modify main.c original code as follow:[[File: SW4STM32_workspace_project_modification.png|thumb|upright=2|center|link=|SW4STM32 main.c file modification]]
    
    /* Infinite loop */
       /* USER CODE BEGIN WHILE */
       while (1)
       {
    
         OPENAMP_check_for_message();
    
         /* USER CODE END WHILE */
         if (VirtUart0RxMsg) {
           {{highlight|char msg_to_transmit[MAX_BUFFER_SIZE];}}
           {{highlight|int msg_size &#61; 0;}}
           VirtUart0RxMsg = RESET;
    
           {{highlight|msg_size &#61; snprintf(msg_to_transmit, MAX_BUFFER_SIZE, "Channel RPMSG0: ");}}
           {{highlight|msg_size +&#61; snprintf(msg_to_transmit + msg_size, MAX_BUFFER_SIZE, "%s\n", VirtUart0ChannelBuffRx);}}
           {{highlight|log_info("size of the message to transmit &#61; %d bytes\n", msg_size);}}
           {{highlight|VIRT_UART_Transmit(&huart0, (uint8_t*)msg_to_transmit, msg_size);}}
         }
    
         if (VirtUart1RxMsg) {
           {{highlight|char msg_to_transmit[MAX_BUFFER_SIZE];}}
           {{highlight|uint16_t msg_size &#61; 0;}}
           VirtUart1RxMsg = RESET;
    
           {{highlight|msg_size &#61; snprintf(msg_to_transmit, MAX_BUFFER_SIZE, "Channel RPMSG1: ");}}
           {{highlight|msg_size +&#61; snprintf(msg_to_transmit + msg_size, MAX_BUFFER_SIZE, "%s\n", VirtUart1ChannelBuffRx);}}
           {{highlight|log_info("size of the message to transmit &#61; %d bytes\n", msg_size);}}
           {{highlight|VIRT_UART_Transmit(&huart1, (uint8_t*)msg_to_transmit, msg_size);}}
         }
         /* USER CODE BEGIN 3 */
       }
       /* USER CODE END 3 */
    
    * Save your modifications
    
    
    ==Rebuild, reload and test the modified firmware==
    ===Rebuild===
    * Click the build button (the little hammer in the toolbar)
    * Wait the end of the build
    
    ===Reload though Linux console ===
    * If you are using STM32MP157C-DK2 Discovery kit
     {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    * If you are using STM32MP157x-EV1 Evaluation board
     {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
    * Upload your firmware example into the board
     {{PC$}} scp Debug/OpenAMP_TTY_echo.elf root@<board ip address>:/lib/firmware
    
    ===Start through Linux console ===
    * Verify that no firmware is currently running
     {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
     offline
    If "offline" is displayed, that means that no firmware is currently running. If "running" is displayed, a firmware is currently running. You should then stop it using the following command:
     {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
    * Set the firmware name to be executed
     {{Board$}} echo -n OpenAMP_TTY_echo.elf > /sys/class/remoteproc/remoteproc0/firmware
    * Start the firmware
     {{Board$}} echo start > /sys/class/remoteproc/remoteproc0/state
    * Verify that the firmware is runnig
     {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
     running
    
    ===Reload and start with SW4STM32 ===
    
    Just relaunch the debug session but reply "No" to following popup in order to force load of the updated firmware. 
    
    [[File:Force Load of the updated binary.png|thumb|upright=2|center|link=|Force Load of the updated firmware]]
    
    ===Test.
    
    ==Testing the modified firmware==
    ===Relaunch debug session ===
    * By clicking on the "Debug" button, STM32CubeIDE relaunches the debug session after performing an incremental build to take into account your modification .
    
    * If everything is correct, you will be back switch to "Debug Perspective" windows after reload of the new firmware.
    
    ===Test ===
    * Initialize the ttyRPMSG0 and ttyRPMSG1 configurations
     {{Board$}} stty -onlcr -echo -F /dev/ttyRPMSG0
     {{Board$}} stty -onlcr -echo -F /dev/ttyRPMSG1
    * Read constantly the ttyRPMSG0 and ttyRPMSG1 channels in background
     {{Board$}} cat /dev/ttyRPMSG0 &
     {{Board$}} cat /dev/ttyRPMSG1 &
    * Send a message on one ttyRPMSG0 channel and check the echo log
     {{Board$}} echo "Hello Virtual UART0" > /dev/ttyRPMSG0
     Channel RPMSG0: Hello Virtual UART0
    * Send a message on one ttyRPMSG1 channel and check the echo log
     {{Board$}} echo "Hello Virtual UART1" > /dev/ttyRPMSG1
     Channel RPMSG1: Hello Virtual UART1<br>
    
    {{Info| When the firmware is running, you can output log from the firmware by using the following command:<br>
    <pre>cat /sys/kernel/debug/remoteproc/remoteproc0/trace0</pre> }}<br>
    * After playing a while you can stop the firmware
     {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
    
    * For SW4STM32,  just terminate the debug session
    
    * Terminate the STM32CubeIDE debug session.
    <noinclude>
    
    {{NoIndex}}
    __NOTOC__
    [[Category:Sub-articles]]</noinclude>
    (97 intermediate revisions by 8 users not shown)
    Line 1: Line 1:
    <noinclude>
    +
    <noinclude>{{ApplicableFor
    {{ArticleMainWriter | VincentA}}
    +
    |MPUs list=STM32MP15x
    [[Category:Sub-articles]]
    +
    |MPUs checklist=STM32MP13x, STM32MP15x
    __NOTOC__
    +
    }}</noinclude>
    </noinclude>
     
     
     
     
    ==Overview==
     
    ==Overview==
    This stage explains how to modify, rebuild and reload a STM32MP1 Arm® Cortex®-M4 coprocessor firmware.
    +
    This stage explains how to modify, rebuild and reload an STM32MP1 Arm® Cortex®-M4 coprocessor firmware.
       
    It proposes to customize the STM32MP1 Cube Package Application example OpenAMP_TTY_Echo using the MPU feature integrated in SW4STM32 IDE.
    +
    It proposes to customize the STM32MP1 Cube Package application example "OpenAMP_TTY_Echo" using STM32CubeIDE.
       
    ==Open SW4STM32 IDE==
    +
    ==Disconnect the "minicom" console==
    * Open System Workbench for STM32 IDE
    +
    * If "minicom" is already opened, please disconnect it to use the STM32CubeIDE built-in serial console.
    [[File: SW4STM32_workspace.png|thumb|upright=2|center|link=|SW4STM32 workspace]]
    +
    {{PC$}} Ctrl + A then Q
       
    ==Connect a console to the board ==
    +
    ==Open STM32CubeIDE ==
      +
    * Start STM32CubeIDE
      +
    [[File:STM32CubeIDE Starter.png|thumb|upright=2|center|link=|STM32CubeIDE Starter Screen]]
       
    * It's very convenient to use the serial console integrated in SW4STM32 
     
    [[File: SW4STM32_workspace_serial_disconnect_1.png|thumb|upright=2|center|link=|SW4STM32 Open the serial device by clicking this item]]
     
       
    * Connection is ok if you can see Linux log or prompt.
    +
    * Choose a workspace (default is fine)
    [[File: SW4STM32_workspace_serial_disconnect_2.png|thumb|upright=2|center|link=|SW4STM32 Serial Consol is ready ]]
     
       
    * If for personal reason you prefer using another terminal ( ssh, minicom), it's then recommended to stop the Target Status Widget using the Serial port in SW4STM32 by right click on the bottom right corner then stop
    +
    * Notice information provided in the "Information Center page" and close it. (you can open it later on)
       
    [[File:Stop Serial widget zoom.png|thumb|upright=2|center|link=Stop the Target Status Widget]]
    +
    [[File:STM32CubeIDE_info.png|800px|link=|center|STM32CubeIDE Information Center Page]]
      +
      +
      +
      +
    * Go into your workspace projet view
      +
      +
      +
      +
    [[File:STM32CubeIDE Default.png|800px|link=|center|STM32CubeIDE Project View]]
       
    * It will avoid the following repetitive pattern in your Linux console
    +
    ==Import an existing example in STM32CubeIDE==
    <pre>
     
    root@stm32mp1:~# ifconfig; echo __END__:$?
     
    eth0      Link encap:Ethernet  HWaddr 00:80:E1:42:45:69 
     
              inet addr:10.48.1.143  Bcast:10.48.3.255  Mask:255.255.252.0
     
              inet6 addr: fe80::280:e1ff:fe42:4569/64 Scope:Link
     
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
     
              RX packets:37 errors:0 dropped:1 overruns:0 frame:0
     
              TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
     
              collisions:0 txqueuelen:1000
     
              RX bytes:5776 (5.6 KiB)  TX bytes:3146 (3.0 KiB)
     
              Interrupt:63 Base address:0xc000
     
       
    lo        Link encap:Local Loopback  
    +
    * Open the import screen '''File > Import...''' and select '''Existing Project into Workspace'''
              inet addr:127.0.0.1  Mask:255.0.0.0
    +
    [[File:STM32CubeIDE Import.png|thumb|upright=2|center|link=|STM32CubeIDE import screen]]
              inet6 addr: ::1/128 Scope:Host
    +
    * Browse and select '''OpenAMP_TTY_echo''' application example in the folder matching your board :
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
     
              RX packets:344 errors:0 dropped:0 overruns:0 frame:0
     
              TX packets:344 errors:0 dropped:0 overruns:0 carrier:0
     
              collisions:0 txqueuelen:1000
     
              RX bytes:22880 (22.3 KiB)  TX bytes:22880 (22.3 KiB)
     
       
    usb0      Link encap:Ethernet  HWaddr 4A:06:6C:16:19:EC 
    +
    ''$HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v4.1.0/Developer-Package/{{EcosystemRelease/Package | revision=latest | package=STM32CubeMP1 | request=path}}/Projects/'''STM32MP157C-DK2'''/Applications/OpenAMP/OpenAMP_TTY_echo/STM32CubeIDE''
              inet addr:192.168.7.2  Bcast:192.168.7.255  Mask:255.255.255.0
     
              inet6 addr: fe80::4806:6cff:fe16:19ec/64 Scope:Link
     
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
     
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
     
              TX packets:396 errors:0 dropped:0 overruns:0 carrier:0
     
              collisions:0 txqueuelen:1000
     
              RX bytes:0 (0.0 B)  TX bytes:115397 (112.6 KiB)
     
       
    __END__:0
    +
    or
    </pre>
     
       
    ==Import an existing example in SW4STM32 IDE==
    +
    ''$HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v4.1.0/Developer-Package/{{EcosystemRelease/Package | revision=latest | package=STM32CubeMP1 | request=path}}/Projects/'''STM32MP157C-EV1'''/Applications/OpenAMP/OpenAMP_TTY_echo/STM32CubeIDE''  
    * Open the import screen  '''File > Import...''' and select '''Existing Project into Workspace'''
    +
     
    [[File: SW4STM32_import.png|thumb|upright=2|center|link=|SW4STM32 import screen]]
    +
     
    * Browse and select '''OpenAMP_TTY_echo''' application example
    +
    * STM32CubeIDE brings a specific project structure for dual core devices such as STM32MP1. A top level project contains sub-projects for each core.
    :* If you are using STM32MP157C-DK2 Discovery kit
    +
    * Here '''OpenAMP_TTY_echo''' top project contains '''OpenAMP_TTY_echo_CM4''' sub project. Keep the 2 projects selected and click on "Finish".
    ::'''$HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo'''
    +
     
    :* If you are using STM32MP157x-EV1 Evaluation board
    +
    [[File:STMCubeIDE import project.png|thumb|upright=2|center|link=|STM32CubeIDE project selection]]
    ::'''$HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo'''
    +
     
    * Click finish
    +
    * The '''OpenAMP_TTY_echo''' project is opened and you can browse inside using the left pan.
    * The '''OpenAMP_TTY_echo''' project is open and you can browse inside using the left pan
    +
     
    [[File: SW4STM32_workspace_project_open.png|thumb|upright=2|center|link=|SW4STM32 workspace with project open]]
    +
    [[File:STMCubeIde project structure.png|thumb|upright=2|center|link=|OpenAMP_TTY_echo project structure]]
       
     
    ==Build the firmware==
     
    ==Build the firmware==
    * Click the build button (the little hammer in the toolbar)
    +
    * Select project '''OpenAMP_TTY_Echo_CM4''' and click the '''Build''' button (the little hammer in the toolbar)
    [[File: SW4STM32_workspace_project_build.png|thumb|upright=2|center|link=|SW4STM32 build the project]]
    +
    [[File:STM32CubeIDE Build.png|800px|center|link=|STM32CubeIDE build the project]]
      +
     
      +
     
      +
    * "Build" is finished with no error
      +
     
      +
    [[File:STM32CubeIDE Build complete.png|800px|center|link=|STM32CubeIDE build finished with no error]]
      +
     
      +
    ==Check connection to the target ==
      +
     
      +
    STM32CubeIDE requires to be connected to Linux running on STM32MP1 device though serial connection.<br>
      +
    This connection is automatically detected and configured when you have put cable on ST-Link port and board has booted.
      +
     
      +
    You can check you can get Linux log and prompt by clicking on the "STM32 butterfly" button :
      +
     
      +
    [[File:STM32CubeIDE ConsoleButton.png|thumb|upright=2|center|link=|STM32CubeIDE Serial Console button]]
      +
     
      +
    Connection is correct if Linux log or prompt are displayed in the console windows.
      +
    {{ReviewsComments|-- [[User:Nathalie Sangouard|Nathalie Sangouard]] ([[User talk:Nathalie Sangouard|talk]]) 11:54, 21 February 2020 (CET)<br />Below, Image is fuzzy, to be reworked }}
      +
    [[File:STM32CubeIDE prompt.png|600px|center|link=|STM32CubeIDE Linux Prompt]]
      +
    Your board might be connected to the PC by Ethernet, either using RJ45  (point to point or VLAN) or USB0 EthernetOverUSB gadget (point to point connection with PC using TypeA-TypeC cable). Screenshot below uses the second solution.
      +
     
      +
    When serial connection is established, STM32CubeIDE automatically detects the board IP address and displays sit in the "Serial Target widget status" window in bottom right part of the screen.
      +
     
      +
    [[File:STM32CubeIDE Serial widget.png|thumb|upright=2|center|link=|STM32Cube Serial Target widget status]]
      +
     
      +
    In case different status such as "busy" or "console in use", check you have no other terminal connected and close the console.
       
    * Build is finished with no error
    +
    ==Start Debug Session ==
    [[File: SW4STM32_workspace_project_build_finished.png|thumb|upright=2|center|link=|SW4STM32 build finished with no error]]
     
       
    ==Upload the firmware through Linux console ==
    +
    *Select your '''OpenAMP_TTY_echo_CM4''' project
    * If you are using STM32MP157C-DK2 Discovery kit
     
    {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
     
    * If you are using STM32MP157x-EV1 Evaluation board
     
    {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
     
    * Upload your firmware example into the board
     
    {{PC$}} scp Debug/OpenAMP_TTY_echo.elf root@<board ip address>:/lib/firmware
     
       
    ==Start the firmware through Linux console ==
    +
    *Right click on '''Debug As > Debug configurations...''' to open the ''Debug Configurations'' panel
    * Verify that no firmware is currently runnig
     
    {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
     
    offline
     
    If offline is displayed, that means that no firmware is currently running. If running is displayed, a firmware is currently running. You shoul then stop it using the following command
     
    {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
     
    * Set the firmware name to be executed
     
    {{Board$}} echo -n OpenAMP_TTY_echo.elf > /sys/class/remoteproc/remoteproc0/firmware
     
    * Start the firmware
     
    {{Board$}} echo start > /sys/class/remoteproc/remoteproc0/state
     
    * Verify that the firmware is runnig
     
    {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
     
    running
     
       
    == Upload and start the firmware with SW4STM32 ==
    +
    *If not already created, create your debug configuration by double clicking on '''STM32 C/C++ Application''' and open "Debugger" pane.
       
    Thanks to the STM32-CoPro-MPU which complete SW4STM32 from version 2.8.0, SW4STM32 can manage to load and start a STM32MP1 Arm® Cortex®-M4 coprocessor firmware.  
    +
    [[File:STM32CubeIDE Debug conf numbered.png|800px|center|link=|Select Production mode in Startup pane of Debug Configuration]]
       
    For doing so open the Debug Configuration ot the OpenAMP_TTY_echo and select "Thru Linux core (Production mode)  
    +
    * Check IP address is correctly filled (1). Else, you can force detection using button on the right (2).
      +
    * Make sure the "Thru Linux core (production mode)" is selected (3)
      +
    * When configuration is correct, the "Debug" button (5) turns to active and you can launch the debug session. Else, error message appears in area (4).
       
    The inet Address of the board should be already filled. Else try to update it thanks to the button on the right
    +
    STM32CubeIDE needs to use serial connection to the board to manage firmware download. <br>
      +
    If the console is opened, it will request your approval to close it. Answer "yes".
       
    [[File:SW4STM32 Production Mode.png|thumb|upright=4|center|link=|Select Production mode in Startup pane of Debug Configuration]]
    +
    [[File:STM32CubeIDE prompt close active console.png|thumb|upright=2|center|link=|SSH password popup]]
       
    When configuration is ok the "Debug" button on the bottom right turn to active and you can launch the debug session.
     
       
    The Debug in Production Mode adds the cortex-M firmware transfer to the embedded Linux. This means also in case of network usage some specific pop-up appearing:  
    +
    The debug in "production mode" adds the cortex-M firmware transfer to the embedded Linux. In case of network usage, some specific pop-up appears:  
       
    * the SSH Password is to complete: the default one is root.
    +
    * the ''SSH Password'' must be completed: the default one is "root".
       
     
    [[File:DebugCfg-Launch-PM-EnterPwd.png|thumb|upright=2|center|link=|SSH password popup]]
     
    [[File:DebugCfg-Launch-PM-EnterPwd.png|thumb|upright=2|center|link=|SSH password popup]]
       
    * the RSA key is to be approved.  
    +
    * the ''RSA key'' must be approved.  
       
     
    [[File:DebugCfg-Launch-PM-RSA.png|thumb|upright=2|center|link=|RSA key popup]]
     
    [[File:DebugCfg-Launch-PM-RSA.png|thumb|upright=2|center|link=|RSA key popup]]
       
    After download of the firmware SW4STM32 will start it and switch into Debug Perspective. You can then use all features of the debugger.
     
       
    For further information and support on new MPU feature in SW4STM32, refer to Help menu of SW4STM32 "Micro Processor Unit (MPU) Family - MCU support "
    +
     
      +
    After, firmware download, STM32CubeIDE switches into ''Debug Perspective''. <br>
      +
     
      +
    In "production mode", the firmware is not break at main. GDB is simply attached to the running target.
      +
    You can then use all features of the debugger.
      +
     
      +
    {{Info| To benefit of the best GDB debug experience it's recommended to upgrade the onboard ST-Link version with the latest release. You can simply do it from STM32CubeIDE using menu "Help -> ST-Link Upgrade"}}
      +
     
      +
     
      +
    For further information, refer to STM32CubeIDE documentation avaialble in [https://my.st.com/content/my_st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-ides/stm32cubeide.html my.st.com]
       
     
    ==Test the firmware==
     
    ==Test the firmware==
    The OpenAMP_TTY_echo firmware do the following:
    +
    The '''OpenAMP_TTY_echo_CM''' firmware do the following:
    *CPU2(CM4) initialize OPenAMP MW which initializes/configures IPCC peripheral through HAL and setup openamp-rpmsg framework infrastructure
    +
    *CPU2(CM4) initializes OpenAMP MW which initializes/configures IPCC peripheral through HAL and setup openamp-rpmsg framework infrastructure,
    *CPU2(CM4) creates 2 rpmsg channels for 2 virtual UART instances UART0 and UART1
    +
    *CPU2(CM4) creates 2 rpmsg channels for 2 virtual UART instances (UART0 and UART1),
    *CPU2(CM4) is waiting for messages from CPU1(CA7) on these both channels
    +
    *CPU2(CM4) is waiting for messages from CPU1(CA7) on these both channels,
     
    *When CPU2(CM4) receives a message on 1 Virtual UART instance/rpmsg channel, it sends the message back to CPU1(CA7) on the same Virtual UART instance
     
    *When CPU2(CM4) receives a message on 1 Virtual UART instance/rpmsg channel, it sends the message back to CPU1(CA7) on the same Virtual UART instance
       
    If you have used SW4STM32 to load and start the firmware you should reopen the serial console.
    +
    Reopen the Serial console of STM32CubeIDE and enter following commands :
     
     
     
    * Initialize the ttyRPMSG0 configuration
     
    * Initialize the ttyRPMSG0 configuration
     
      {{Board$}} stty -onlcr -echo -F /dev/ttyRPMSG0
     
      {{Board$}} stty -onlcr -echo -F /dev/ttyRPMSG0
     
    * Read constantly the ttyRPMSG0 channel in background
     
    * Read constantly the ttyRPMSG0 channel in background
     
      {{Board$}} cat /dev/ttyRPMSG0 &
     
      {{Board$}} cat /dev/ttyRPMSG0 &
    * Send a message on one ttyRPMSG0 channel and recieve the echo on the same ttyRPMSG0 channel
    +
    * Send a message on one ttyRPMSG0 channel and receive the echo on the same ttyRPMSG0 channel
     
      {{Board$}} echo "Hello Virtual UART0" > /dev/ttyRPMSG0
     
      {{Board$}} echo "Hello Virtual UART0" > /dev/ttyRPMSG0
     
      Hello Virtual UART0
     
      Hello Virtual UART0
     
    * You can perform the same steps with the ttyRPMSG1 channel
     
    * You can perform the same steps with the ttyRPMSG1 channel
       
      +
    * Terminate the STM32CubeIDE debug session will stop the firmware.
       
    * After playing a while you can stop the firmware
    +
    ==Modify the firmware==
    {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
    +
    The original firmware example receives a message for the host on one channel and acknolegde by returning the same message to the host on the same channel.
       
    * If using SW4STM32 just terminate the debug session
    +
    As this is not so obvious on which channel the message is received, we propose you to modify the firmware in order to add an indication to know what is the channel that is receiving the message.
       
    ==Modify the firmware==
    +
    For that, please modify main.c original code as follow:
    The original firmware example receives a message for the host on one channel end sent back the same message to the host on the same channel.<br>
     
    As this is not so obvious on which channel the message is received, we propose to modify the firmware in order to add an indication to know what is the channel that is receiving the message.<br>
     
    Please modify main.c original code as follow:
     
    [[File: SW4STM32_workspace_project_modification.png|thumb|upright=2|center|link=|SW4STM32 main.c file modification]]
     
       
     
       /* Infinite loop */
     
       /* Infinite loop */
    Line 190: Line 183:
     
       /* USER CODE END 3 */
     
       /* USER CODE END 3 */
       
    * Save your modifications
    +
    * Save your modifications.
     
     
    ==Rebuild, reload and test the modified firmware==
     
    ===Rebuild===
     
    * Click the build button (the little hammer in the toolbar)
     
    * Wait the end of the build
     
     
     
    ===Reload though Linux console ===
     
    * If you are using STM32MP157C-DK2 Discovery kit
     
    {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
     
    * If you are using STM32MP157x-EV1 Evaluation board
     
    {{PC$}} cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.0.0/Developer-Package/STM32Cube_FW_MP1_V1.0.0/Projects/STM32MP157C-EV1/Applications/OpenAMP/OpenAMP_TTY_echo/SW4STM32/OpenAMP_TTY_echo/
     
    * Upload your firmware example into the board
     
    {{PC$}} scp Debug/OpenAMP_TTY_echo.elf root@<board ip address>:/lib/firmware
     
       
    ===Start through Linux console ===
    +
    ==Testing the modified firmware==
    * Verify that no firmware is currently running
    +
    ===Relaunch debug session ===
    {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
    +
    * By clicking on the "Debug" button, STM32CubeIDE relaunches the debug session after performing an incremental build to take into account your modification .
    offline
     
    If "offline" is displayed, that means that no firmware is currently running. If "running" is displayed, a firmware is currently running. You should then stop it using the following command:
     
    {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
     
    * Set the firmware name to be executed
     
    {{Board$}} echo -n OpenAMP_TTY_echo.elf > /sys/class/remoteproc/remoteproc0/firmware
     
    * Start the firmware
     
    {{Board$}} echo start > /sys/class/remoteproc/remoteproc0/state
     
    * Verify that the firmware is runnig
     
    {{Board$}} cat /sys/class/remoteproc/remoteproc0/state
     
    running
     
       
    ===Reload and start with SW4STM32 ===
    +
    * If everything is correct, you will be back switch to "Debug Perspective" windows after reload of the new firmware.
       
    Just relaunch the debug session but reply "No" to following popup in order to force load of the updated firmware.
    +
    ===Test ===
     
     
    [[File:Force Load of the updated binary.png|thumb|upright=2|center|link=|Force Load of the updated firmware]]
     
     
     
    ===Test===
     
     
    * Initialize the ttyRPMSG0 and ttyRPMSG1 configurations
     
    * Initialize the ttyRPMSG0 and ttyRPMSG1 configurations
     
      {{Board$}} stty -onlcr -echo -F /dev/ttyRPMSG0
     
      {{Board$}} stty -onlcr -echo -F /dev/ttyRPMSG0
    Line 242: Line 208:
     
    <pre>cat /sys/kernel/debug/remoteproc/remoteproc0/trace0</pre> }}
     
    <pre>cat /sys/kernel/debug/remoteproc/remoteproc0/trace0</pre> }}
     
    <br>
     
    <br>
    * After playing a while you can stop the firmware
     
    {{Board$}} echo stop > /sys/class/remoteproc/remoteproc0/state
     
       
    * For SW4STM32,  just terminate the debug session
    +
    * Terminate the STM32CubeIDE debug session.
      +
     
      +
    <noinclude>
      +
    {{NoIndex}}
      +
    __NOTOC__
      +
    [[Category:Sub-articles]]
      +
    </noinclude>