Skip to content

sys/arduino: add Serial over stdio support#17447

Merged
aabadie merged 5 commits intoRIOT-OS:masterfrom
gschorcht:sys/arduino_serial_stdio
Jan 7, 2022
Merged

sys/arduino: add Serial over stdio support#17447
aabadie merged 5 commits intoRIOT-OS:masterfrom
gschorcht:sys/arduino_serial_stdio

Conversation

@gschorcht
Copy link
Copy Markdown
Contributor

@gschorcht gschorcht commented Dec 25, 2021

Contribution description

This PR provides the support for using the Serial over stdio_*

On Arduino boards, the Serial object uses

  • either an UART interface connected to an USB interface via an additional ATmega chip (class HardwareSerial)
  • or directly the USB CDC interface (class _Serial).

However, the Serial object in RIOT always uses the UART interface defined by ARDUINO_UART_DEV, usually UART_DEV(0). Therefore Serial does not work for boards like feather-m0 and arduino-mkr which use the USB CDC interface directly. Since the STDIO already uses the USB CDC interface for such boards with the help of the module stdio_cdc_acm, it is possible to realize the Serial object for such boards on top of the STDIO.

For this purpose the module arduino_serial_stdio is introduced. If this module is enabled AND the ARDUINO_UART_DEV is defined as UART_UNDEF, the STDIO is used for Serial. This allows either the use of the STDIO or the use of a UART interface if defined by ARDUINO_UART_DEV.

The module arduino_serial_stdio is automatically enabled for boards using stdio_cdc_acm. However, to actually use Serial via STDIO, ARDUINO_UART_DEV have to be defined additionally UART_UNDEF. This is done by this PR for

  • feather-m0
  • arduino-mkr.

For sodaq boards the situation is unclear, since ARDUINO_UART_DEV is explicitly defined for these boards and it is not clear whether this is intentional.

The use of Serial over STDIO requires that the used stdio backend implements the stdio_available function that was introduced by PR #17446.

Testing procedure

  1. Use either a feather-m0 or an arduino-mkr board and use the following example to test:
    make BOARD=arduino-mkr1000 -C examples/arduino_hello-world flash term
    make BOARD=feather-m0 -C examples/arduino_hello-world flash term
    
    Enter a string should be echoed as expected.
  2. Use any other board that uses std_uart, for example esp32-wroom and do the same:
    CFLAGS='-DARDUINO_UART_DEV=UART_UNDEF' USEMODULE=arduino_serial_stdio \
    make BOARD=esp32-wroom-32 -C examples/arduino_hello-world flash term
    
    Enter a string should be echoed as expected.

Issues/PRs references

Depends on PR #17446.

@github-actions github-actions bot added Area: arduino API Area: Arduino wrapper API Area: boards Area: Board ports Area: build system Area: Build system Area: Kconfig Area: Kconfig integration Area: sys Area: System Area: tests Area: tests and testing framework Area: USB Area: Universal Serial Bus labels Dec 25, 2021
@gschorcht gschorcht added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Dec 25, 2021
@gschorcht gschorcht force-pushed the sys/arduino_serial_stdio branch from 24f890f to c5940ad Compare December 25, 2021 20:18
@gschorcht gschorcht removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 26, 2021
@gschorcht gschorcht force-pushed the sys/arduino_serial_stdio branch from c5940ad to 33c7423 Compare December 26, 2021 06:39
@github-actions github-actions bot removed Area: USB Area: Universal Serial Bus Area: build system Area: Build system labels Dec 26, 2021
@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Jan 6, 2022

I tried this PR on arduino-mkrfox1200 and it works like a charm. Very nice!
I also tried on sodaq-autonomo and, with the following change, it also works like a charm without having to plug an USB to UART converter:

diff --git a/boards/sodaq-autonomo/include/arduino_board.h b/boards/sodaq-autonomo/include/arduino_board.h
index dbf200ed43..2f95638c75 100644
--- a/boards/sodaq-autonomo/include/arduino_board.h
+++ b/boards/sodaq-autonomo/include/arduino_board.h
@@ -33,9 +33,11 @@ extern "C" {
 #define ARDUINO_LED         (13)
 
 /**
- * @brief   On-board serial port mapping
+ * @brief   On-board serial port mapping, stdio is used for Serial
  */
-#define ARDUINO_UART_DEV         UART_DEV(0)
+#ifndef ARDUINO_UART_DEV
+#define ARDUINO_UART_DEV    UART_UNDEF
+#endif
 
 /**
  * @brief   Look-up table for the Arduino's digital pins

So I'm +1 for adapting them as well (some arduino stuff could be shared there but that's another story). In a word, I'd ACK if you adapt them as well.

@gschorcht gschorcht force-pushed the sys/arduino_serial_stdio branch from 33c7423 to a7dc480 Compare January 6, 2022 16:37
@gschorcht
Copy link
Copy Markdown
Contributor Author

OK, I have rebased to have the changes of PR #17446. ARDUINO_UART_DEV is set to UART_UNDEF for all sodaq* boards. We could move this definition to a arduino_board_common.h file to define it at only one place.

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Jan 6, 2022

Thanks !

We could move this definition to a arduino_board_common.h file to define it at only one place.

Let's keep this for a follow-up.

Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK!

@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 6, 2022
@aabadie aabadie enabled auto-merge January 6, 2022 17:04
@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 7, 2022
@aabadie aabadie merged commit 3676b63 into RIOT-OS:master Jan 7, 2022
@gschorcht
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and merging

@gschorcht gschorcht deleted the sys/arduino_serial_stdio branch January 13, 2022 13:11
@fjmolinas fjmolinas added this to the Release 2022.01 milestone Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: arduino API Area: Arduino wrapper API Area: boards Area: Board ports Area: Kconfig Area: Kconfig integration Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants