Skip to content

boards/esp32: Arduino I/O mapping completion #21484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 20, 2025

Conversation

gschorcht
Copy link
Contributor

@gschorcht gschorcht commented May 13, 2025

Contribution description

This PR completes the migration to the new Arduino I/O mapping for ESP32x boards, which was not fully covered in PR #19759 when the new Arduino I/O mapping was introduced and the feature handling was changed. That is arduino_io_map.h is updated and the features arduino_analog, arduino_dac, arduino_i2c, arduino_pwm, arduino_spi and arduino_uart are enabled if supported for the following boards:

esp32-heltec-lora32-v2
esp32-mh-et-live-minikit
esp32-olimex-evb
esp32-ttgo-t-beam
esp32-wemos-lolin-d32-pro
esp32-wroom-32
esp32-wrover-kit
esp32s2-devkit
esp32s2-lilygo-ttgo-t8
esp32s3-devkit
esp32s3-pros3
esp32c3-devkit
esp32c3-wemos-mini

During the migration process some small peripheral configuration fixes and changes had to be done:

  • esp32-heltec-lora32-v2: GPIO0 is connected to the BOOT button and pulled up by external resistor. Using it as PWM channel is probably not the best idea.
  • esp32-ttgo-t-beam: To handle different revisions of the board with same configuration, one ADC channel was added to the configuration and the last two ADC lines were reordered. It shouldn't affect existing applications.
  • esp32-wrover-kit: GPIO2 (LED1_PIN) is used as SPI signal, not only if sdcard_spi is enabled. herefore, it must not be defined as LED pin if periph_spi is used. GIO4 (LED2_PIN) is used by the SDMMC Host Controller as SD Card DAT1 signal and must not be defined as LED pin in that case.
  • esp32c3-devkit: The channel of PWM_DEV(0) that conflicts with the I2C SCA signal is replaced by another channel. PWM_DEV(1) is defined in addition if periph_spi is not used.
  • esp32c3-wemos-mini: Additional channel was added tot the configuration of PWM_DEV(0). Documentation fixed.

Testing procedure

Compilation in CI should succeed

Issues/PRs references

@github-actions github-actions bot added Area: doc Area: Documentation Area: boards Area: Board ports labels May 13, 2025
@gschorcht gschorcht added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: arduino API Area: Arduino wrapper API Platform: ESP Platform: This PR/issue effects ESP-based platforms and removed Area: doc Area: Documentation labels May 13, 2025
@gschorcht gschorcht requested a review from maribu May 13, 2025 05:07
@riot-ci
Copy link

riot-ci commented May 13, 2025

Murdock results

✔️ PASSED

85d65aa boards/common/esp32x: cleanup Arduino leftover

Success Failures Total Runtime
10348 0 10348 13m:36s

Artifacts

@github-actions github-actions bot added Area: doc Area: Documentation and removed Area: arduino API Area: Arduino wrapper API Platform: ESP Platform: This PR/issue effects ESP-based platforms labels May 13, 2025
Copy link
Contributor

@crasbe crasbe left a comment

Choose a reason for hiding this comment

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

Mostly very small nitpicks here and there.

What I don't understand, but my understanding of ESP32 is limited, is the change of pins. Were there so many errors in the pin definitions? Wrong GPIOs selected for the Arduino pins?

Or do these boards not have Arduino headers and the GPIOs are just chosen arbitrarily?

@gschorcht
Copy link
Contributor Author

gschorcht commented May 14, 2025

Or do these boards not have Arduino headers and the GPIOs are just chosen arbitrary?

None of the boards have Arduino headers so that the choice of the GPIOs is arbitrary. The only ESP32 board with Arduino headers is that one in PR #21479.

@maribu
Copy link
Member

maribu commented May 14, 2025

None of the boards have Arduino headers so that the choice of the GPIOs is arbitrarily.

That is in-line with what the I/O mapping documentation claims: https://doc.riot-os.org/iomaps.html#iomaps-shields

Only when a feature such as arduino_shield_nano/arduino_shield_uno/xiao_shield is provided, the board has electrical and mechanical compatibility with the Arduino Nano/Arduino UNO/XIAO form factor and must use the same numbering scheme. If no such feature is provided by the board, the I/O mapping can just be arbitrary.

(I wonder why we are not having a feature declaring consistent mapping for feather compatible boards yet. I guess someone(tm) should do that :D)

@gschorcht
Copy link
Contributor Author

Only when a feature such as arduino_shield_nano/arduino_shield_uno/xiao_shield is provided

That's why the only ESP32 board with Arduino headers in PR #21479 provides the feature arduino_shield_uno while all other ESP32x boards doesn't.

@gschorcht
Copy link
Contributor Author

What I don't understand, but my understanding of ESP32 is limited, is the change of pins. Were there so many errors in the pin definitions? Wrong GPIOs selected for the Arduino pins?

Many of the changes are either to document the pins more clearly or to complete missing mappings, e.g. for esp32s3-pros3 or esp32s3-devkit.

But when I went through the Arduino configuration board by board again, I noticed some misconfigurations on some boards that either hadn't been noticed before or didn't matter, e.g. for the esp32-olimex-evb board.

I also realized that some of the configurations don't make sense, even in the peripheral configuration, e.g. using a pull-up button input as a PWM channel on esp32-heltec-lora-v2.

I'm sorry that all these cleanups lead to 897 lines + and 300 lines - 🙈 If it helps, I could split this PR into seperate PRs, one for each board which would result in 12 separate PRs.

Copy link
Contributor

@crasbe crasbe left a comment

Choose a reason for hiding this comment

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

LGTM, please squash!

@crasbe
Copy link
Contributor

crasbe commented May 14, 2025

I'm sorry that all these cleanups lead to 897 lines + and 300 lines - 🙈 If it helps, I could split this PR into seperate PRs, one for each board which would result in 12 separate PRs.

I went through everything yesterday reasonably thoroughly and the changes all look reasonable. Of course one could do more cleaning and whatever, but that is beyond the scope of this PR.

The channel of PWM_DEV(0) that conflicts with the I2C SCA signal is replaced by another channel. PWM_DEV(1) is defined in addition if `periph_spi` is not used.
@gschorcht gschorcht force-pushed the boards/esp32_arduino_cleanup branch from 006c577 to 17d9200 Compare May 14, 2025 18:24
@gschorcht
Copy link
Contributor Author

gschorcht commented May 14, 2025

@maribu One thing is not really clear to me from the documentation. Have the following macros to be declared only for boards with Arduino headers or for any board with some mapping, even if it doesn't have Arduino headers and is not mechanically compatible?

#define ARDUINO_UART_D0D1       UART_DEV(0) /**< Arduino UART interface */
#define ARDUINO_SPI_D11D12D13   SPI_DEV(0)  /**< Arduino SPI bus */
#define ARDUINO_I2C_UNO         I2C_DEV(0)  /**< Arduino I2C bus */

@maribu
Copy link
Member

maribu commented May 15, 2025

For the macros

#define ARDUINO_UART_D0D1       UART_DEV(0) /**< Arduino UART interface */
#define ARDUINO_SPI_D11D12D13   SPI_DEV(0)  /**< Arduino SPI bus */

I think it would be fair to use them also for non-Arduino compatible I/O mappings, as long as the named pins (or rather their I/O mapping names) are actually used. But we should update the doc to indicate that.

#define ARDUINO_I2C_UNO         I2C_DEV(0)  /**< Arduino I2C bus */

For this one, I think it is confusing to use that for non-Arudino-UNO compatible boards.

@gschorcht
Copy link
Contributor Author

#define ARDUINO_I2C_UNO         I2C_DEV(0)  /**< Arduino I2C bus */

For this one, I think it is confusing to use that for non-Arudino-UNO compatible boards.

Ok, that means you would define ARDUINO_UART_D0D1 and ARDUINO_SPI_D11D12D13 in arduino_iomap.h also for such boards that don't have Arduino headers, but not ARDUINO_I2C_UNO. Would you then define ARDUINO_I2C_DEV instead or nothing? ARDUINO_I2C_DEV is defined by the Arduino driver anyway, if it is not already defined.

@gschorcht
Copy link
Contributor Author

#define ARDUINO_I2C_UNO         I2C_DEV(0)  /**< Arduino I2C bus */

For this one, I think it is confusing to use that for non-Arudino-UNO compatible boards.

Ok, that means you would define ARDUINO_UART_D0D1 and ARDUINO_SPI_D11D12D13 in arduino_iomap.h also for such boards that don't have Arduino headers, but not ARDUINO_I2C_UNO. Would you then define ARDUINO_I2C_DEV instead or nothing? ARDUINO_I2C_DEV is defined by the Arduino driver anyway, if it is not already defined.

@maribu ?

@maribu
Copy link
Member

maribu commented May 19, 2025

I think either is fine

@gschorcht
Copy link
Contributor Author

I think either is fine

Ok, then I prefer the removal and leave the default definition.

@crasbe Is your approval still valid with the last fixups?

@crasbe
Copy link
Contributor

crasbe commented May 19, 2025

@crasbe Is your approval still valid with the last fixups?

Sure :)

gschorcht added 18 commits May 19, 2025 17:04
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
- GPIO2 (LED1_PIN) is used as SPI signal, not only if `sdcard_spi` is enabled. herefore, it must not be defined as LED pin if `periph_spi` is used.
- GIO4 (LED2_PIN) is used by the SDMMC Host Controller as SD Card DAT1 signal and must not be defined as LED pin in that case.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
GPIO0 is connected to the BOOT button and pulled up by external resistor. Using it as PWM channel is probably not the best idea.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
To handle different revisions of the board with same configuration, one ADC channel was added to the configuration and the last two ADC lines were reordered. It shouldn't affect existing applications.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
Migration to the new Arduino I/O mapping, which was not fully covered in PR RIOT-OS#19759 when the new Arduino I/O mapping was introduced and the feature handling was changed.
`arduino_pinmap` and `arduino__analog_map` are not defined any longer by the board but as a common approach in `sys/arduino/include/arduino_board*.h`. Their definition in `boards/common/esp32x` were just a leftover and forgotten in PR RIOT-OS#19759.
@gschorcht gschorcht force-pushed the boards/esp32_arduino_cleanup branch from fa630d3 to 85d65aa Compare May 19, 2025 15:04
@gschorcht gschorcht added this pull request to the merge queue May 20, 2025
Merged via the queue into RIOT-OS:master with commit f6e8c79 May 20, 2025
25 checks passed
@gschorcht
Copy link
Contributor Author

@crasbe @maribu Thanks for reviewing and your support.

@gschorcht gschorcht deleted the boards/esp32_arduino_cleanup branch May 20, 2025 08:00
@Teufelchen1 Teufelchen1 added this to the Release 2025.07 milestone Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: doc Area: Documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants