Skip to content
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

boards/esp32s2-mini: add definition for ESP32 S2 Mini #18863

Merged
merged 6 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions boards/common/makefiles/stdio_tinyusb_cdc_acm.dep.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ifeq (,$(filter stdio_% slipdev_stdio,$(USEMODULE)))
gschorcht marked this conversation as resolved.
Show resolved Hide resolved
# Use stdio_tinyusb_cdc_acm only if no other stdio is requested explicitly.
# and usbus is used for any other reason
ifneq (,$(filter usbus,$(USEMODULE)))
USEMODULE += stdio_cdc_acm
else
USEMODULE += stdio_tinyusb_cdc_acm
endif

FEATURES_REQUIRED += highlevel_stdio
endif
24 changes: 24 additions & 0 deletions boards/esp32s2-wemos-mini/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2022 Benjamin Valentin
#
# 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.

config BOARD
default "esp32s2-wemos-mini" if BOARD_ESP32S2_WEMOS_MINI

config BOARD_ESP32S2_WEMOS_MINI
bool
default y
select BOARD_COMMON_ESP32S2
select CPU_MODEL_ESP32S2_FN4R2
select HAS_PERIPH_ADC
select HAS_PERIPH_DAC
select HAS_PERIPH_I2C
select HAS_PERIPH_PWM
select HAS_PERIPH_SPI
select HAS_PERIPH_USBDEV
select HAS_TINYUSB_DEVICE
select HAS_HIGHLEVEL_STDIO

source "$(RIOTBOARD)/common/esp32s2/Kconfig"
5 changes: 5 additions & 0 deletions boards/esp32s2-wemos-mini/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = board

DIRS = $(RIOTBOARD)/common/esp32s2

include $(RIOTBASE)/Makefile.base
2 changes: 2 additions & 0 deletions boards/esp32s2-wemos-mini/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include $(RIOTBOARD)/common/makefiles/stdio_tinyusb_cdc_acm.dep.mk
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use stdio_cdc_acm instead of stdio_tinyusb_cdc_acm?

Suggested change
include $(RIOTBOARD)/common/makefiles/stdio_tinyusb_cdc_acm.dep.mk
include $(RIOTBOARD)/common/makefiles/stdio_cdc_acm.dep.mk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does not work unfortunately:

[67805.165596] usb 1-1.3: new full-speed USB device number 41 using ehci-pci
[67805.194752] usb 1-1.3: device descriptor read/8, error -32
[67805.322445] usb 1-1.3: device descriptor read/8, error -32
[67805.513597] usb 1-1.3: new full-speed USB device number 42 using ehci-pci
[67805.550441] usb 1-1.3: device descriptor read/8, error -32
[67805.678470] usb 1-1.3: device descriptor read/8, error -32
[67805.785725] usb 1-1-port3: unable to enumerate USB device

Copy link
Contributor

Choose a reason for hiding this comment

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

Strange, I don't have any problem with tests/usbus_stdio_cdc_acm on an ESP32-S2 DevKit:

[3575781.815894] usb 1-4.3.4: reset high-speed USB device number 12 using xhci_hcd
[3575789.473284] usb 1-2.3: USB disconnect, device number 104
[3575790.031381] usb 1-2.3: new full-speed USB device number 105 using xhci_hcd
[3575790.134714] usb 1-2.3: New USB device found, idVendor=1209, idProduct=7d00, bcdDevice= 1.00
[3575790.134718] usb 1-2.3: New USB device strings: Mfr=3, Product=2, SerialNumber=4
[3575790.134720] usb 1-2.3: Product: esp32s2-devkit
[3575790.134721] usb 1-2.3: Manufacturer: RIOT-os.org
[3575790.134723] usb 1-2.3: SerialNumber: A591F23634E0D055
[3575790.144876] cdc_acm 1-2.3:1.0: ttyACM0: USB ACM device

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, forgot that this problem isn't solved. Have you tried another cable or port?

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 don't think it's a connection issue, it works when I use the tinyUSB stack, but not with usbus - without touching the connection.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's a connection issue

In principle yes, I would have supposed that too. But maybe there are timing issues caused by the poor signal quality that lead to different behavior in different implementations. The implementation of the usbdev_synopsys_dwc2 driver is different from the one used by tinyUSB. I already had the case that both the USB Serial/JTAG interface and the tinyUSB DWC2 worked without problems, but periph_usbdev did not until I changed the cable and the port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh you are right!
After some fiddling around and a few resets the board is recognized with usbus

[  664.957863] usb 1-1-port3: unable to enumerate USB device
[  666.593778] usb 1-1.3: new full-speed USB device number 11 using ehci-pci
[  666.702686] usb 1-1.3: device descriptor read/all, error -32
[  666.793786] usb 1-1.3: new full-speed USB device number 12 using ehci-pci
[  666.906697] usb 1-1.3: device descriptor read/all, error -32
[  666.913784] usb 1-1-port3: attempt power cycle
[  667.521790] usb 1-1.3: new full-speed USB device number 13 using ehci-pci
[  667.553220] usb 1-1.3: New USB device found, idVendor=1209, idProduct=7d01, bcdDevice= 1.00
[  667.553230] usb 1-1.3: New USB device strings: Mfr=3, Product=2, SerialNumber=4
[  667.553234] usb 1-1.3: Product: esp32s2-wemos-mini
[  667.553236] usb 1-1.3: Manufacturer: RIOT-os.org
[  667.553239] usb 1-1.3: SerialNumber: A591F27212482C31
[  667.554279] cdc_acm 1-1.3:1.0: ttyACM0: USB ACM device

but tinyUSB appears more stable indeed

include $(RIOTBOARD)/common/esp32s2/Makefile.dep
15 changes: 15 additions & 0 deletions boards/esp32s2-wemos-mini/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CPU_MODEL = esp32s2_fn4r2

# common board and CPU features
include $(RIOTBOARD)/common/esp32s2/Makefile.features

# additional features provided by the board
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_dac
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_usbdev

benpicco marked this conversation as resolved.
Show resolved Hide resolved
FEATURES_PROVIDED += highlevel_stdio
FEATURES_PROVIDED += tinyusb_device
9 changes: 9 additions & 0 deletions boards/esp32s2-wemos-mini/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT_LINUX ?= /dev/ttyACM0

USB_VID ?= $(USB_VID_TESTING)
USB_PID ?= $(USB_PID_TESTING)

CFLAGS += -DCONFIG_CONSOLE_UART_TX=39
CFLAGS += -DCONFIG_CONSOLE_UART_RX=37

include $(RIOTBOARD)/common/esp32s2/Makefile.include
benpicco marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 44 additions & 0 deletions boards/esp32s2-wemos-mini/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 Benjamin Valentin
*
* 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.
*/

/**
* @defgroup boards_esp32s2-wemos-mini Wemos S2 mini Board
* @ingroup boards_esp32s2
* @brief Support for Wemos S2 mini Board
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>

\section esp32s2-wemos-mini Wemos S2 mini

## Overview {#esp32s2-wemos-mini_overview}

\image html "https://www.wemos.cc/en/latest/_images/s2_mini_v1.0.0_4_16x9.jpg" "Wemos S2 mini" width=600px

Documentation for the board can be found on the vendor page:

- [Wemos S2 mini](https://www.wemos.cc/en/latest/s2/s2_mini.html)
- [Schematic](https://www.wemos.cc/en/latest/_static/files/sch_s2_mini_v1.0.0.pdf)

## Flashing the Device {#esp32s2-wemos-mini_flashing}

Flashing RIOT is quite easy. The board has a Micro-USB connector with
reset/boot/flash logic. Just connect the board to your host computer
gschorcht marked this conversation as resolved.
Show resolved Hide resolved
and type using the programming port:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOARD=esp32s2-wemos-mini make flash
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If RIOT is already on the device, it should automatically enter bootloader mode.
If this does not work or the device is stuck in some other mode, you can force
it into bootloader mode by pressing the Reset (RST) button while holding the BOOT (0)
button.

For detailed information about ESP32-S2 as well as configuring and compiling
RIOT for ESP32-S2 boards, see \ref esp32_riot.

[Back to table of contents](#esp32s2-wemos-mini_toc)
*/
2 changes: 2 additions & 0 deletions boards/esp32s2-wemos-mini/esp32s2-wemos-mini.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_PACKAGE_TINYUSB=y
Copy link
Contributor

Choose a reason for hiding this comment

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

This is again exactly the problem I tried to solve in PR #19038 for the boards with only one USB interface. Using such an application configurations in the board definition prevents switching between the stacks. PR #19086 provides an approach that could solve the problem, by selecting the stack implementation that should be used first and the modules of the according stack afterwards.

But let's continue as is for now.

CONFIG_MODULE_STDIO_TINYUSB_CDC_ACM=y
80 changes: 80 additions & 0 deletions boards/esp32s2-wemos-mini/include/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2022 Benjamin Valentin
*
* 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.
*/

/**
* @ingroup boards_esp32s2-wemos-mini
* @brief Board definitions for Wemos S2 mini board
* @{
*
* The board definitions in this file is valid for the Wemos S2 mini board.
*
* @file
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
*/

#ifndef BOARD_H
#define BOARD_H

#include <stdint.h>

/**
* @name Button pin definitions
* @{
*/

/**
* @brief Default button GPIO pin definition
*
* Wemos S2 mini boards have a BOOT button connected to GPIO0, which can be
* used as button during normal operation. Since the GPIO0 pin is pulled up,
* the button signal is inverted, i.e., pressing the button will give a
* low signal.
*/
#define BTN0_PIN GPIO0

/**
* @brief Default button GPIO mode definition
*/
#define BTN0_MODE GPIO_IN_PU

/**
* @brief Default interrupt flank definition for the button GPIO
*/
#ifndef BTN0_INT_FLANK
#define BTN0_INT_FLANK GPIO_FALLING
#endif

/**
* @brief Definition for compatibility with previous versions
*/
#define BUTTON0_PIN BTN0_PIN

/** @} */

/**
* @name LED (on-board) configuration
*
* @{
*/
#define LED0_PIN GPIO15 /**< LED is connected to GPIO15 */
#define LED0_ACTIVE 1 /**< LED is high active */
/** @} */
benpicco marked this conversation as resolved.
Show resolved Hide resolved

/* include common board definitions as last step */
#include "board_common.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
} /* end extern "C" */
#endif

#endif /* BOARD_H */
/** @} */
50 changes: 50 additions & 0 deletions boards/esp32s2-wemos-mini/include/gpio_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2022 Benjamin Valentin
*
* 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.
*/

#ifndef GPIO_PARAMS_H
#define GPIO_PARAMS_H

/**
* @ingroup boards_esp32s2-wemos-mini
* @brief Board specific configuration of direct mapped GPIOs
* @file
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
* @{
*/

#include "board.h"
#include "saul/periph.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief LED and Button configuration
*/
static const saul_gpio_params_t saul_gpio_params[] =
{
{
benpicco marked this conversation as resolved.
Show resolved Hide resolved
.name = "LED",
.pin = LED0_PIN,
.mode = GPIO_OUT,
},
{
.name = "BOOT",
.pin = BTN0_PIN,
.mode = BTN0_MODE,
.flags = SAUL_GPIO_INVERTED
},
};

#ifdef __cplusplus
}
#endif

#endif /* GPIO_PARAMS_H */
/** @} */
Loading