Skip to content

Commit 3b88ae2

Browse files
committed
[MP1] README.md: Fix typo and add some examples
1 parent dd26d98 commit 3b88ae2

File tree

1 file changed

+79
-7
lines changed

1 file changed

+79
-7
lines changed

variants/STM32MP157_DK/README.md

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ In this example, the user **must** upload `<Arduino build output path>/run_ardui
4343
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.
4444

4545
#### 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.
4748

4849
`run_arduino_<sketch name>.sh` help page summary:
4950

@@ -90,17 +91,17 @@ See the source code [run_arduino_gen.sh] for the full help page and the more det
9091

9192
## Virtual Serial
9293

93-
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.
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.
9495

95-
Enable `VirtIOSerial` in Arduino IDE->Tools->Virtual serial support. You can optionally alias generic `Serial` object with `VirtIOSerial` as well.
96+
Enable `SerialVirtIO` in Arduino IDE->Tools->Virtual serial support. You can optionally alias generic `Serial` object with `SerialVirtIO` as well.
9697

9798
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.
9899

99100
See [OpenAMP] and [Linux RPMsg] to learn more.
100101

101102
### Configuration
102103

103-
To increase the performance of VirtIOSerial you can resize the related buffer configurations. There are three definitions you can use:
104+
To increase the performance of SerialVirtIO you can resize the related buffer configurations. There are three definitions you can use:
104105

105106
* [`VRING_NUM_BUFFS`](/cores/arduino/stm32/OpenAMP/virtio_config.h)
106107
* [`RPMSG_BUFFER_SIZE`](/cores/arduino/stm32/OpenAMP/virtio_config.h)
@@ -110,6 +111,48 @@ The recommended option is to resize `VRING_NUM_BUFFS`. Be very cautious when res
110111

111112
To redefine these definitions, see how to create `build_opt.h` described in Debugging section below.
112113

114+
### Virtual Serial Example
115+
116+
Here is a basic echo example:
117+
```cpp
118+
int available;
119+
char buffer[1024];
120+
121+
unsigned long time = 0;
122+
123+
void setup() {
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+
void loop() {
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.
139+
if ((millis() - time) > 1000) {
140+
time = millis();
141+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
142+
}
143+
}
144+
```
145+
146+
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+
113156
## Debugging
114157

115158
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.
@@ -124,16 +167,44 @@ build_opt.h (in the same directory of your Sketch)
124167
-DVIRTIO_LOG_BUFFER_SIZE=4086
125168
```
126169

127-
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.
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()`.
128171

129-
Also, need to add `#include "core_debug.h"` in your code in order to use `core_debug()`.
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.
130173

131174
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.
132175

133176
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.
134177

135178
See [virtio_log.h] for more information.
136179

180+
### Debugging Example
181+
182+
Here is a basic blink example with `core_debug()`:
183+
```cpp
184+
#include "core_debug.h"
185+
186+
unsigned long time = 0;
187+
unsigned long count = 1;
188+
189+
void setup() {
190+
// You must enable SerialVirtIO to use core_debug(), even if you don't use SerialVirtIO.
191+
SerialVirtIO.begin();
192+
pinMode(LED_BUILTIN, OUTPUT);
193+
}
194+
195+
void loop() {
196+
if ((millis() - time) > 1000) {
197+
time = millis();
198+
core_debug("%u seconds\n", count++);
199+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
200+
}
201+
}
202+
```
203+
204+
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+
137208
## Pin mapping
138209

139210
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.
@@ -214,7 +285,7 @@ And then the Device Tree should enable TIM1 for the coprocessor, although this d
214285

215286
* Ethernet and USB are not supported. Use them in the Linux host.
216287
* 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.
217-
* [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.
218289
* 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.
219290

220291

@@ -232,6 +303,7 @@ And then the Device Tree should enable TIM1 for the coprocessor, although this d
232303

233304
[OpenAMP]: https://github.com/OpenAMP/open-amp/wiki/OpenAMP-Overview
234305
[Linux RPMsg]: https://wiki.st.com/stm32mpu/wiki/Linux_RPMsg_framework_overview
306+
[a hard restriction of the write size]: /cores/arduino/VirtIOSerial.cpp#L148
235307

236308
[build_opt.h]: https://github.com/stm32duino/wiki/wiki/Customize-build-options-using-build_opt.h
237309
[build_opt.h description in wiki]: https://github.com/stm32duino/wiki/wiki/Customize-build-options-using-build_opt.h

0 commit comments

Comments
 (0)