You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: variants/STM32MP157_DK/README.md
+145-5
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,8 @@ In this example, the user **must** upload `<Arduino build output path>/run_ardui
43
43
After uploading the user can use `sh run_arduino_<sketch name>.sh start` in the console of host Linux via either SSH or Serial Console, to run the Arduino firmware.
44
44
45
45
#### Note
46
-
*`sh run_arduino_<sketch name>.sh start` is a one-shot command, the Arduino firmware only runs for the current boot. If you want to make it run after reboot, you need to use `sh run_arduino_<sketch name>.sh install` command.
46
+
47
+
*`sh run_arduino_<sketch name>.sh start` is a one-shot command, the Arduino firmware only runs for the current boot. If you want to make it run after reboot, you need to use `sh run_arduino_<sketch name>.sh install` command.
47
48
48
49
`run_arduino_<sketch name>.sh` help page summary:
49
50
@@ -63,6 +64,21 @@ After uploading the user can use `sh run_arduino_<sketch name>.sh start` in the
63
64
sh run_arduino_<sketch name>.sh uninstall
64
65
Uninstall the autostart service.
65
66
67
+
sh run_arduino_<sketch name>.sh monitor
68
+
Monitor data received from the coprocessor via the virtual serial.
69
+
70
+
sh run_arduino_<sketch name>.sh send-msg <message...>
71
+
Send a message to the coprocessor via the virtual serial.
72
+
73
+
sh run_arduino_<sketch name>.sh send-file <filename>
74
+
Send a file content to the coprocessor via the virtual serial.
75
+
76
+
sh run_arduino_<sketch name>.sh minicom
77
+
Launch minicom interactive serial communication program.
78
+
79
+
sh run_arduino_<sketch name>.sh log
80
+
Print debugging log in OpenAMP trace buffer.
81
+
66
82
sh run_arduino_<sketch name>.sh stop
67
83
Stop the coprocessor.
68
84
@@ -73,6 +89,122 @@ See the source code [run_arduino_gen.sh] for the full help page and the more det
73
89
74
90
[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.
75
91
92
+
## Virtual Serial
93
+
94
+
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 `SerialVirtIO` object and you can use it as a standard Arduino Serial object.
95
+
96
+
Enable `SerialVirtIO` in Arduino IDE->Tools->Virtual serial support. You can optionally alias generic `Serial` object with `SerialVirtIO` as well.
97
+
98
+
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.
99
+
100
+
See [OpenAMP] and [Linux RPMsg] to learn more.
101
+
102
+
### Configuration
103
+
104
+
To increase the performance of SerialVirtIO you can resize the related buffer configurations. There are three definitions you can use:
The recommended option is to resize `VRING_NUM_BUFFS`. Be very cautious when resizing `RPMSG_BUFFER_SIZE`, which must be matched with the Linux kernel definition. Also `VIRTIO_BUFFER_SIZE` has the minimum required size depending on the other two. See their links above for further descriptions.
111
+
112
+
To redefine these definitions, see how to create `build_opt.h` described in Debugging section below.
113
+
114
+
### Virtual Serial Example
115
+
116
+
Here is a basic echo example:
117
+
```cpp
118
+
int available;
119
+
char buffer[1024];
120
+
121
+
unsignedlong time = 0;
122
+
123
+
voidsetup() {
124
+
// You can SerialVirtIO.begin() and use SerialVirtIO later instead.
125
+
Serial.begin(); // You don't need to configure speed, it is ignored.
126
+
pinMode(LED_BUILTIN, OUTPUT);
127
+
}
128
+
129
+
voidloop() {
130
+
available = Serial.available();
131
+
while (available > 0) {
132
+
int size = min(available, Serial.availableForWrite());
133
+
Serial.readBytes(buffer, size);
134
+
Serial.write(buffer, size);
135
+
available -= size;
136
+
}
137
+
138
+
// Heartbeat. If Arduino stops the LED won't flash anymore.
Note the use of `Serial.availableForWrite()`. SerialVirtIO has [a hard restriction of the write size], so it is important to `Serial.write()` less than the value of `Serial.availableForWrite()`.
147
+
148
+
After loading Arduino, You can use SerialVirtIO in two ways in this example:
149
+
150
+
* Run `sh run_arduino_<sketch name>.sh minicom` and type anything in the minicom console. The console will print out what you type immediately.
151
+
152
+
* Open two Linux consoles (using SSH)
153
+
1. In the first console, run `sh run_arduino_<sketch name>.sh monitor`
154
+
2. In the second console, run `sh run_arduino_<sketch name>.sh send-msg <your message>` or `sh run_arduino_<sketch name>.sh send-file <your file>`, the first console will print the content of the message.
155
+
156
+
## Debugging
157
+
158
+
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.
159
+
160
+
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:
161
+
162
+
```
163
+
build_opt.h (in the same directory of your Sketch)
164
+
-----------------------------
165
+
166
+
-DCORE_DEBUG
167
+
-DVIRTIO_LOG_BUFFER_SIZE=4086
168
+
```
169
+
170
+
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. Don't forget to add `#include "core_debug.h"` in your code in order to use `core_debug()`.
171
+
172
+
Also, you must enable the Virtual Serial (described in the above section) and include `SerialVirtIO.begin();` in your Arduino sketch, because this logging feature is tightly coupled to OpenAMP virtio.
173
+
174
+
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.
175
+
176
+
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.
177
+
178
+
See [virtio_log.h] for more information.
179
+
180
+
### Debugging Example
181
+
182
+
Here is a basic blink example with `core_debug()`:
183
+
```cpp
184
+
#include"core_debug.h"
185
+
186
+
unsignedlong time = 0;
187
+
unsignedlong count = 1;
188
+
189
+
voidsetup() {
190
+
// You must enable SerialVirtIO to use core_debug(), even if you don't use SerialVirtIO.
Don't forget to add [build_opt.h] described above.
205
+
206
+
After loading Arduino, you can simply `sh run_arduino_<sketch name>.sh log` to print the current `core_debug()` logs.
207
+
76
208
## Pin mapping
77
209
78
210
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.
@@ -108,7 +240,7 @@ There are additional pins for LEDs and buttons.
108
240
| PA_13 | 17 / LED_RED | USER2_BTN | Active Low, LED LD6, also connected to B4 button |
109
241
| PH_7 | 18 / LED_ORANGE / LED_BUILTIN || Active High, LED LD7 |
110
242
111
-
[`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.
243
+
[`variant.h` of the board] has the complete information about the pinouts.
112
244
113
245
## Uploading
114
246
@@ -152,9 +284,8 @@ And then the Device Tree should enable TIM1 for the coprocessor, although this d
152
284
## Limitations
153
285
154
286
* Ethernet and USB are not supported. Use them in the Linux host.
155
-
* 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).
156
287
* 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.
157
-
*[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.
288
+
*[Early firmware loading from U-Boot stage] is not supported. Only firmware loading on Linux boot stage by systemd (aka. `sh run_arduino_<sketch name>.sh install`) 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.
158
289
* 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.
159
290
160
291
@@ -170,11 +301,20 @@ And then the Device Tree should enable TIM1 for the coprocessor, although this d
0 commit comments