Skip to content

Commit 33e4ed4

Browse files
committed
Add documentation about VirtIO
1 parent 75fd9ca commit 33e4ed4

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

variants/STM32MP157_DK/README.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ After uploading the user can use `sh run_arduino_<sketch name>.sh start` in the
7777
sh run_arduino_<sketch name>.sh minicom
7878
Launch minicom interactive serial communication program.
7979

80+
sh run_arduino_<sketch name>.sh log
81+
Print debugging log in OpenAMP trace buffer.
82+
8083
sh run_arduino_<sketch name>.sh stop
8184
Stop the coprocessor.
8285

@@ -87,6 +90,40 @@ See the source code [run_arduino_gen.sh] for the full help page and the more det
8790

8891
[run_arduino_gen.sh] is the shell script that produces a copy of the script called `run_arduino_<sketch name>.sh` but with the sketch binary self-contained.
8992

93+
## Virtual Serial
94+
95+
With Virtual Serial, you can easily implement inter-core communication between the Linux host and Arduino coprocessor. Virtual Serial uses OpenAMP rpmsg framework. This is available as `VirtIOSerial` object and you can use it as a standard Arduino Serial object.
96+
97+
Enable `VirtIOSerial` in Arduino IDE->Tools->Virtual serial support. You can optionally alias generic `Serial` object with `VirtIOSerial` as well.
98+
99+
When enabled, `/dev/ttyRPMSG0` is available to the Linux host. You can use it as a normal serial tty. `sh run_arduino_<sketch name>.sh` provides `monitor`, `minicom`, `send-msg`, `send-file` as a convenience. See above command descriptions.
100+
101+
See [OpenAMP] and [Linux RPMsg] to learn more.
102+
103+
## Debugging
104+
105+
For printf-style debugging, `core_debug()` is highly recommended instead of using Arduino Serial. In STM32MP1, `core_debug()` utilizes OpenAMP trace buffer and it has a minimal real-time impact (other than the overhead of printf) because it is not bound to the speed of a hardware IO peripheral while printing it.
106+
107+
Create [build_opt.h] in the sketch directory and simply put `-DCORE_DEBUG`. Additionally you can resize the buffer size of logging by redefining `VIRTIO_LOG_BUFFER_SIZE` (2kb by default). As an example you can create a file like the following:
108+
109+
```
110+
build_opt.h (in the same directory of your Sketch)
111+
-----------------------------
112+
113+
-DCORE_DEBUG
114+
-DVIRTIO_LOG_BUFFER_SIZE=4086
115+
```
116+
117+
Don't forget to change any of Arduino IDE option to reflect this as in the warning section in [build_opt.h description in wiki]. This is important because if `-DCORE_DEBUG` is not configured correctly `core_debug()` silently becomes an empty function without triggering any build error.
118+
119+
Also, need to add `#include "core_debug.h"` in your code in order to use `core_debug()`.
120+
121+
You can use `sh run_arduino_<sketch name>.sh log` command or `cat /sys/kernel/debug/remoteproc/remoteproc0/trace0` command to print out the debug log in the Linux host.
122+
123+
Note that when overflow occurs the trace buffer is re-written from the beginning, removing existing logs. Consider increasing `VIRTIO_LOG_BUFFER_SIZE` in this case, as mentioned above.
124+
125+
See [virtio_log.h] for more information.
126+
90127
## Pin mapping
91128

92129
The boards have two pin headers: Raspberry Pi HAT headers and Arduino shield headers. This project currently supports Arduino Shield headers only, leaving RPi HAT headers for the Linux applications.
@@ -122,7 +159,7 @@ There are additional pins for LEDs and buttons.
122159
| PA_13 | 17 / LED_RED | USER2_BTN | Active Low, LED LD6, also connected to B4 button |
123160
| PH_7 | 18 / LED_ORANGE / LED_BUILTIN | | Active High, LED LD7 |
124161

125-
[`variant.h` of the board](https://github.com/stm32duino/Arduino_Core_STM32/tree/master/variants/STM32MP157_DK/variant.h) has the complete information about the pinouts.
162+
[`variant.h` of the board] has the complete information about the pinouts.
126163

127164
## Uploading
128165

@@ -166,7 +203,6 @@ And then the Device Tree should enable TIM1 for the coprocessor, although this d
166203
## Limitations
167204

168205
* Ethernet and USB are not supported. Use them in the Linux host.
169-
* Currently there is no easy way for communication between the Linux host and Arduino coprocessor. There is ongoing work for virtual serial communications using OpenAMP rpmsg framework. Currently one possible way is to wire between UART7 (Arduino SCL/SDA pins) and USART3 (Linux RPi HAT GPIO14/GPIO15 pins), however, users should manually modify [Linux Device tree to enable `usart3` and recompile it](usart3).
170206
* I2C pins on Raspberry Pi HAT header (GPIO2 and GPIO3) are not available in Linux host. This is because the Discovery board shares I2C pins on Arduino header and those on the HAT header.
171207
* [Early firmware loading from U-Boot stage] is not supported. Only firmware loading on Linux boot stage by systemd supported. The binary itself may be loaded by U-Boot without any problems, but there is no out-of-box tool to configure U-Boot to load the firmware using Arduino IDE yet.
172208
* EEPROM library: Those devices do not have non-volatile memory. The emulation is done using RETRAM. Therefore data will be preserved *only* when VBAT is supplied (e.g. A coin battery is connected to CN3 on STM32MP157A_DK1) and the coprocessor is waken up from sleep. This implies that cold boot the board may cause data loss, even if VBAT is supplied. See [discussions on RETRAM] for more detail.
@@ -184,11 +220,19 @@ And then the Device Tree should enable TIM1 for the coprocessor, although this d
184220

185221
[run_arduino_gen.sh]: https://github.com/stm32duino/Arduino_Tools/blob/master/run_arduino_gen.sh
186222

223+
[OpenAMP]: https://github.com/OpenAMP/open-amp/wiki/OpenAMP-Overview
224+
[Linux RPMsg]: https://wiki.st.com/stm32mpu/wiki/Linux_RPMsg_framework_overview
225+
226+
[build_opt.h]: https://github.com/stm32duino/wiki/wiki/Customize-build-options-using-build_opt.h
227+
[build_opt.h description in wiki]: https://github.com/stm32duino/wiki/wiki/Customize-build-options-using-build_opt.h
228+
[virtio_log.h]: /cores/arduino/stm32/OpenAMP/virtio_log.h
229+
230+
[`variant.h` of the board]: /variants/STM32MP157_DK/variant.h
231+
187232
[The ST Wiki page on C-Kermit]: https://wiki.st.com/stm32mpu/wiki/How_to_transfer_a_file_over_serial_console
188233
[a bug in OpenSTLinux]: https://community.st.com/s/question/0D50X0000B9vHa4/cannot-get-download-a-file-using-kermit
189234

190235
[stm32mp157c-dk2-m4-examples.dts]: https://github.com/STMicroelectronics/meta-st-stm32mp/blob/d8cbac759e1275b1a27d4ba38b64a0d83d0e8c9f/recipes-kernel/linux/linux-stm32mp/4.19/4.19.49/0029-ARM-stm32mp1-r2-DEVICETREE.patch#L4334
191236

192-
[usart3]: https://github.com/STMicroelectronics/meta-st-stm32mp/blob/d8cbac759e1275b1a27d4ba38b64a0d83d0e8c9f/recipes-kernel/linux/linux-stm32mp/4.19/4.19.49/0029-ARM-stm32mp1-r2-DEVICETREE.patch#L4274
193237
[Early firmware loading from U-Boot stage]: https://wiki.st.com/stm32mpu/wiki/How_to_start_the_coprocessor_from_the_bootloader
194238
[discussions on RETRAM]: https://community.st.com/s/question/0D50X0000B44pHUSQY/doesnt-the-mcu-coprocessor-have-nonvolatile-memory

0 commit comments

Comments
 (0)