Skip to content

boards: add Wemos D1 R32 (aka ESPDuino-32) board definition #21479

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 2 commits into from
May 15, 2025

Conversation

gschorcht
Copy link
Contributor

@gschorcht gschorcht commented May 9, 2025

Contribution description

This PR adds the board definition for the Wemos D1 R32 also known as ESPDuino-32, the only only Arduino-sized ESP32 board with Arduino Uno compatible headers.

WeMos D1 R32

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 Area: Kconfig Area: Kconfig integration labels May 9, 2025
@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 May 9, 2025
@gschorcht gschorcht force-pushed the boards/esp32-wemos-d1-r32 branch from 121091e to 5cffb8a Compare May 9, 2025 16:25
@riot-ci
Copy link

riot-ci commented May 9, 2025

Murdock results

✔️ PASSED

bd55bd0 boards/esp32-wroom-32: small doc fix

Success Failures Total Runtime
555 0 555 04m:59s

Artifacts

@crasbe
Copy link
Contributor

crasbe commented May 12, 2025

I just bought the hardware and once it arrives, I'll give it a test.

In the meantime, you could change the headerguards to #pragma once as discussed in #21335 and the doc.txt files to doc.md as discussed in #21220.

@@ -96,8 +96,8 @@ Function | GPIOs | Remarks |Configuration
:---------------|:-------|:--------|:----------------------------------
BUTTON0 | GPIO0 | | |
ADC | GPIO0, GPIO2, GPIO4, GPIO12, GPIO13,\n GPIO14, GPIO15, GPIO25, GPIO26, GPIO27,\n GPIO32, GPIO33, GPIO34, GPIO35, GPIO36,\n GPIO39 | | see \ref esp32_adc_channels "ADC Channels"
DAC | GPIO25, GPIO26 | | \ref esp32_dac_channels "refer"
PWM_DEV(0) | GPIO0, GPIO2, GPIO4, GPIO16, GPIO17 | - | \ref esp32_pwm_channels "DAC Channels"
DAC | GPIO25, GPIO26 | | \ref esp32_dac_channels \ref esp32_pwm_channels "DAC Channels"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DAC | GPIO25, GPIO26 | | \ref esp32_dac_channels \ref esp32_pwm_channels "DAC Channels"
DAC | GPIO25, GPIO26 | | \ref esp32_dac_channels "DAC Channels"

@@ -0,0 +1,16 @@
# Copyright (c) 2020 HAW Hamburg
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe consider changing the copyright here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, at typical copy&paste problem. The Kconfig still had to be completely updated 😎

Comment on lines 1 to 9
/*
* Copyright (C) 2025 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/*
* Copyright (C) 2025 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**

No copyright notices and block comments are required for Markdown files.
(Remember to remove the closing piece of the block comment below as well).

Comment on lines 10 to 13
* @defgroup boards_esp32_wemos_d1_r32 Wemos D1 R32 (ESPDuino-32)
* @ingroup boards_esp32
* @brief Support for the Wemos D1 R32 (ESPDuino-32) board
* @author Gunar Schorcht <gunar@schorcht.net>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @defgroup boards_esp32_wemos_d1_r32 Wemos D1 R32 (ESPDuino-32)
* @ingroup boards_esp32
* @brief Support for the Wemos D1 R32 (ESPDuino-32) board
* @author Gunar Schorcht <gunar@schorcht.net>
@defgroup boards_esp32_wemos_d1_r32 Wemos D1 R32 (ESPDuino-32)
@ingroup boards_esp32
@brief Support for the Wemos D1 R32 (ESPDuino-32) board
@author Gunar Schorcht <gunar@schorcht.net>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, now where it is a Markdown file, C comments are wrong now 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was already wondering why Doxygen is complaining about a wrong list item.

Comment on lines 19 to 24
1. [Overview](#esp32_wemos_d1_r32_overview)
2. [Hardware](#esp32_wemos_d1_r32_hardware)
1. [MCU](#esp32_wemos_d1_r32_mcu)
2. [Board Configuration](#esp32_wemos_d1_r32_board_configuration)
3. [Board Pinout](#esp32_wemos_d1_r32_pinout)
3. [Flashing the Device](#esp32_wemos_d1_r32_flashing)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
1. [Overview](#esp32_wemos_d1_r32_overview)
2. [Hardware](#esp32_wemos_d1_r32_hardware)
1. [MCU](#esp32_wemos_d1_r32_mcu)
2. [Board Configuration](#esp32_wemos_d1_r32_board_configuration)
3. [Board Pinout](#esp32_wemos_d1_r32_pinout)
3. [Flashing the Device](#esp32_wemos_d1_r32_flashing)
-# [Overview](#esp32_wemos_d1_r32_overview)
-# [Hardware](#esp32_wemos_d1_r32_hardware)
-# [MCU](#esp32_wemos_d1_r32_mcu)
-# [Board Configuration](#esp32_wemos_d1_r32_board_configuration)
-# [Board Pinout](#esp32_wemos_d1_r32_pinout)
-# [Flashing the Device](#esp32_wemos_d1_r32_flashing)

You can let Doxygen do the enumeration for you instead of doing it manually.

@crasbe crasbe changed the title boards: add Wemos D1 R2 (aka ESPDuino) board definition boards: add Wemos D1 R32 (aka ESPDuino) board definition May 12, 2025

### Board Configuration {#esp32_wemos_d1_r32_board_configuration}

The boad configuration guaranties that the board is compatible with Arduino
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The boad configuration guaranties that the board is compatible with Arduino
The board configuration guarantees that the board is compatible with Arduino

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I'm wondering why it wasn't catched by the spell checker in CI?

Copy link
Contributor

Choose a reason for hiding this comment

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

guaranties is the valid plural form of guaranty and boad is simply not in the library: https://github.com/codespell-project/codespell/blob/d59cf4fe68f1d606c23f21a19ecd3828dbe8725e/codespell_lib/data/dictionary.txt#L9789

* mode for the GPIO pin has to be GPIO_IN.
*/
#ifndef BTN0_INT_FLANK
#define BTN0_INT_FLANK GPIO_FALLING
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#define BTN0_INT_FLANK GPIO_FALLING
# define BTN0_INT_FLANK GPIO_FALLING

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I forgot to elaborate. Our official stylekeeper @maribu establishes the indentations after the # for #defines in #if statements to make them more readable, especially for multiple #if-layers.

Therefore the suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maribu I really like indentation for nested #ifdef ... #endif directives or a sequence of defines within a conditional compilation. But especially for a bunch simple #ifndefs directives used as macro guards with just a single define depending on whether it is already defined or not, indentation leads to more "choppy" code that makes reading harder rather than better.

#ifndef ABDCX
#define ABDCX  x
#endif

#ifndef ABDCY
#define ABDCX  y
#endif

#ifndef ABDCZ
#define ABDCZ  z
#endif

vs.

#ifndef ABDCX
#  define ABDCX  x
#endif

#ifndef ABDCX
#  define ABDCY  y
#endif

#ifndef ABDCZ
#  define ABDCZ  z
#endif

IMHO, copy & paste errors are also easier to catch with the first variant than with the second variant because of the alignment of the identifiers. Personally, I would prefer if the indentation for such conditionals were not mandatory for such a single definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't matter for BTN0_INT_FLANK since the board doesn't have a button 😉 This was just a leftover. I didn't take care about it because usually each ESP32x board has a BOOT-Button that can be used as button once the application is loaded from flash.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was just joking with the "official stylekeeper", but the indentation is indeed part of the Coding Convention https://github.com/RIOT-OS/RIOT/blob/master/CODING_CONVENTIONS.md#indentation-of-preprocessor-directives

But indeed maribu is a lot more experienced with code styling than I am, so maybe he can voice his opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just joking with the "official stylekeeper", but the indentation is indeed part of the Coding Convention https://github.com/RIOT-OS/RIOT/blob/master/CODING_CONVENTIONS.md#indentation-of-preprocessor-directives

I know, I have read it 😉 but sometimes it is worth to discuss some style rules 😎

Copy link
Member

Choose a reason for hiding this comment

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

I would favor to just unconditionally stick with two spaces of indent. Style is pretty subjective, e.g. to me the second example with the indent is actually easier to read than the one without.

I would argue that adding exceptions to the coding conventions for short code makes the coding convention more complex and makes it more difficult to the use of tools such as clang-format and uncrustify, as special exceptions are not easily configured with such tools. Exceptions also tends to cause a lot of discussion (Would two #defines within the #ifndef ... #endif still be considered as short? How about three?).

In core @kaspar030 has enforced an "run uncrustify, don't discuss style" policy, even for the few cases the output of uncrustify not super ideal. I think we ended up spending more time to discuss the content of the code and almost no time on discussing style, which I believe is a good thing.

But anyway, so far we have not strictly enforced the coding convention outside of core yet, so I would not start insisting here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Style is pretty subjective, e.g. to me the second example with the indent is actually easier to read than the one without.

Totally agree. Maybe I should look for an editor with better syntax highlighting, where macro names in defines and guards are somehow colored 😉 gnome-textedit only uses one color for complete preprocessor directives, so that in header files that only contain preprocessor directives, there is in fact no highlighting 😟

Comment on lines 26 to 28
#ifndef PERIPH_CONF_H
#define PERIPH_CONF_H

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#ifndef PERIPH_CONF_H
#define PERIPH_CONF_H

Looks like you found a cornercase in the headerguards check 😅
I'll add a PR to cover that.

Copy link
Contributor

Choose a reason for hiding this comment

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

This commit is for another ESP32 board 4e3bb01 ?

The boards/esp32-wemos-d1-r32/include/periph_conf.h is still unchanged.

Did you cd into the wrong directory? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just mixed some work when I was switching between differen branches 🙈

@gschorcht gschorcht force-pushed the boards/esp32-wemos-d1-r32 branch 2 times, most recently from 5dcda95 to 59525bd Compare May 12, 2025 22:55
@gschorcht gschorcht changed the title boards: add Wemos D1 R32 (aka ESPDuino) board definition boards: add Wemos D1 R32 (aka ESPDuino-32) board definition May 12, 2025
Comment on lines 29 to 37
static const saul_gpio_params_t saul_gpio_params[] =
{
{
.name = "BOOT",
.pin = BTN0_PIN,
.mode = BTN0_MODE,
.flags = SAUL_GPIO_INVERTED
},
};

/**
* @brief LED configuration
*/
static const saul_gpio_params_t saul_gpio_params[] =
{
{
.name = "LED",
.pin = LED0_PIN,
.mode = GPIO_OUT,
.flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR)
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be one struct?

The compiler throws the following errors when building examples/basic/default:

In file included from /home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/drivers/saul/init_devs/auto_init_saul_gpio.c:25:
/home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/boards/esp32-wemos-d1-r32/include/gpio_params.h:33:16: error: 'BTN0_PIN' undeclared here (not in a function)
   33 |         .pin = BTN0_PIN,
      |                ^~~~~~~~
/home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/boards/esp32-wemos-d1-r32/include/gpio_params.h:34:17: error: 'BTN0_MODE' undeclared here (not in a function)
   34 |         .mode = BTN0_MODE,
      |                 ^~~~~~~~~
/home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/boards/esp32-wemos-d1-r32/include/gpio_params.h:42:33: error: redefinition of 'saul_gpio_params'
   42 | static const saul_gpio_params_t saul_gpio_params[] =
      |                                 ^~~~~~~~~~~~~~~~
/home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/boards/esp32-wemos-d1-r32/include/gpio_params.h:29:33: note: previous definition of saul_gpio_params' with type 'const saul_gpio_params_t[1]'
   29 | static const saul_gpio_params_t saul_gpio_params[] =
      |                                 ^~~~~~~~~~~~~~~~
make[3]: *** [/home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/Makefile.base:157: /home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/examples/basic/default/bin/esp32-wemos-d1-r32/saul_init_devs/auto_init_saul_gpio.o] Error 1
make[2]: *** [/home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/Makefile.base:31: ALL--/home/cbuec/RIOTstuff/riot-gettingstarted/RIOT/drivers/saul/init_devs] Error 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should probably be one struct?

Yeah, of course. But how could the compilation in Murdock succeed with this error, I'm a bit confused.

Anyway, since the board has no button, I will just drop the first structure. The problem was probably caused by copying and pasting these structures from different boards, sorry.

Copy link
Contributor

Choose a reason for hiding this comment

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

The CI only compiles for certain boards and this board is not one of them. Therefore the error would've shown only in the full build when the tests and examples are compiled for all boards, including this one.

.name = "LED",
.pin = LED0_PIN,
.mode = GPIO_OUT,
.flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR)
.flags = (SAUL_GPIO_INIT_CLEAR)

With the inverted flag, the LED is off when writing 1 and on when writing 0.
Furthermore, the LED is on on startup.

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.

You can squash the fixups. Please also address the suggestion from @mguetschow.

I tested the board locally with examples/basic/default, tests/periph/adc and tests/periph/pwm and everything seems to work as it should.

One thing that is still on my mind is the removal of the arduino_board_common.h in this PR. Maybe #21484 would be a better home for that, since it's already an "ESP32 Arduino Cleanup" PR?

@gschorcht
Copy link
Contributor Author

You can squash the fixups. Please also address the suggestion from @mguetschow.

These suggestions were already addressed.

One thing that is still on my mind is the removal of the arduino_board_common.h in this PR. Maybe #21484 would be a better home for that, since it's already an "ESP32 Arduino Cleanup" PR?

I moved the commit to #21484 and squashed.

Thanks for reviewing and testing.

@gschorcht
Copy link
Contributor Author

Hm, compilation failed in Murdock because tests/drivers/sps30/Makefile defines the macro I2C0_SPEED

CFLAGS+=-DI2C0_SPEED=I2C_SPEED_NORMAL

It is not yet clear for what purpose the macro was defined. It seems that it is not used in the driver code. Maybe it's just a leftover from the time when i2c_init took the I2C clock frequency as a parameter and the application could define which I2C clock frequency to use. On the other hand, the I2C API was changed in 2018, while the application was added with PR #13256 in 2020 🤔

In the description of PR #13256, it is pointed out that the SPS30 only works at normal speed. Maybe the definition of I2C0_SPEED in the Makefile was an attempt to define the speed at least for ESP32x boards, where this macro is actually used, but Fast Speed is the default.

I now conditionally define I2C0_SPEED in the board configuration.

@gschorcht
Copy link
Contributor Author

I had to modify the comments and mapping for Arduino DAC pins with commit 1e274e1.

@gschorcht
Copy link
Contributor Author

@crasbe With commit 1e274e1 I tried to changed the order of the Arduino DAC pins so that Arduino pins DAC0 and DAC1 are mapped consistently to DAC_LINE(0) and DAC_LINE(1), respectively.

#define DAC_GPIOS { GPIO25, GPIO26 }

#define ARDUINO_DAC0 DAC_LINE(0) /**< DAC line for Arduino DAC0 pin */
#define ARDUINO_DAC1 DAC_LINE(1) /**< DAC line for Arduino DAC1 pin */

However, this results in the Arduino pin D2 being the DAC1 and D3 the DAC0. That is, while the digital Arduino pins D2 and D3 are labelled in ascending order, the DAC pins are labelled in descending order. With other words you have D2=DAC1 and D3=DAC0 which might be a little bit confusing.
#define ARDUINO_PIN_2 GPIO26 /**< Arduino pin 2 (DAC1) */
#define ARDUINO_PIN_3 GPIO25 /**< Arduino pin 3 (PWM / DAC0) */

Now I'm wondering whether it wouldn't be better to change the order in periph_conf.h to

#define DAC_GPIOS   { GPIO26, GPIO25 } 

so that we could map D2=DAC0 to DAC_LINE(0) and D3=DAC1 to DAC_LINE(1).

On the other hand, DAC pins are something that is not known in the Arduino world and it probably doesn't matter how you map them to the DAC lines. What do you think?

@crasbe
Copy link
Contributor

crasbe commented May 15, 2025

What do you think?

You are probably overthinking it :D
I don't have an opinion on it and I agree that it probably doesn't matter.

@gschorcht
Copy link
Contributor Author

Ok, since we live in the RIOT bubble where Arduino sketches are just a nice but very special gadget, I would say that it is more important to map the ESP32 GPIOs to the DAC_LINE in ascending order, also because the headers of the board are not labelled D0 ... D13, but with GPIOx.

So I would have to squash the fixups.

@gschorcht gschorcht force-pushed the boards/esp32-wemos-d1-r32 branch from 694e4a4 to bd55bd0 Compare May 15, 2025 15:40
@gschorcht
Copy link
Contributor Author

May I enable Auto-merge?

@crasbe
Copy link
Contributor

crasbe commented May 15, 2025

Any time :)

@gschorcht gschorcht added this pull request to the merge queue May 15, 2025
Merged via the queue into RIOT-OS:master with commit 7abe650 May 15, 2025
25 checks passed
@gschorcht
Copy link
Contributor Author

@crasbe Many thanks for reviewing 😉

@Teufelchen1 Teufelchen1 added this to the Release 2025.07 milestone Jul 14, 2025
@gschorcht gschorcht deleted the boards/esp32-wemos-d1-r32 branch July 30, 2025 13:23
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 Area: Kconfig Area: Kconfig integration 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.

6 participants