- Last edited 4 months ago ago
Modify, rebuild and reload a firmware
1 Overview[edit]
This stage explains how to modify, rebuild and reload a 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.
2 Open SW4STM32 IDE[edit]
- Open System Workbench for STM32 IDE
3 Connect a console to the board[edit]
- It's very convenient to use the serial console integrated in SW4STM32
- Connection is ok if you can see Linux log or prompt.
- 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[edit]
- Open the import screen File > Import... and select Existing Project into Workspace
- 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-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/Applications/OpenAMP/OpenAMP_TTY_echo
- Click finish
- The OpenAMP_TTY_echo project is open and you can browse inside using the left pan
5 Build the firmware[edit]
- Click the build button (the little hammer in the toolbar)
- Build is 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
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 SSH Password is to complete: the default one is root.
- the RSA key is to be approved.
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 "
9 Test the firmware[edit]
The OpenAMP_TTY_echo firmware do the following:
- CPU2(CM4) initialize 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.
- 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 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 stop the firmware
echo stop > /sys/class/remoteproc/remoteproc0/state
- If using SW4STM32 just terminate the debug session
10 Modify the firmware[edit]
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.
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.
Please modify main.c original code as follow:
/* 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 the modified firmware[edit]
11.1 Rebuild[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.
11.5 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
- After playing a while you can stop the firmware
echo stop > /sys/class/remoteproc/remoteproc0/state
- For SW4STM32, just terminate the debug session