Skip to content

Commit

Permalink
boards/esp32-wrover-kit: add SDMMC support
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Sep 13, 2023
1 parent a967a4e commit c2017a8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 20 deletions.
1 change: 1 addition & 0 deletions boards/esp32-wrover-kit/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config BOARD_ESP32_WROVER_KIT
select HAS_PERIPH_ADC
select HAS_PERIPH_I2C
select HAS_PERIPH_PWM
select HAS_PERIPH_SDMMC
select HAS_PERIPH_SPI
select HAS_SDCARD_SPI

Expand Down
14 changes: 10 additions & 4 deletions boards/esp32-wrover-kit/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ endif
# Sets up configuration for openocd
USEMODULE += esp_jtag

ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_sdcard_default
endif

# default to using fatfs on SD card
ifneq (,$(filter vfs_default,$(USEMODULE)))
USEMODULE += fatfs_vfs
USEMODULE += mtd
endif

ifneq (,$(filter mtd,$(USEMODULE)))
ifneq (,$(filter sdcard_spi,$(USEMODULE)))
# use mtd_sdcard_default if sdcard_spi is explicitly used
USEMODULE += mtd_sdcard_default
else
# use mtd_sdmmc_default otherwise
USEMODULE += mtd_sdmmc_default
endif
endif

include $(RIOTBOARD)/common/esp32/Makefile.dep
1 change: 1 addition & 0 deletions boards/esp32-wrover-kit/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include $(RIOTBOARD)/common/esp32/Makefile.features
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_sdmmc
FEATURES_PROVIDED += periph_spi

# unique features provided by the board
Expand Down
29 changes: 18 additions & 11 deletions boards/esp32-wrover-kit/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ configuration can be overridden by

These abbreviations are used in subsequent tables:

*SDC* = SD-Card interface is used (module **sdcard_spi** is enabled)\n
*SDC* = SD-Card interface is used (module **periph_sdmmc** is enabled)\n
*CAM* = Camera is plugged in/used

<center>
Expand All @@ -95,12 +95,18 @@ These abbreviations are used in subsequent tables:
| `ADC_LINE(2)` | `GPIO36` | `GPIO36` | - | - | `CAMERA_D4` | \ref esp32_adc_channels |
| `ADC_LINE(3)` | `GPIO39` | `GPIO39` | - | - | `CAMERA_D5` | \ref esp32_adc_channels |
| `PWM_DEV(0):0 / LED0` | `GPIO0` | `GPIO0` | - | - | `LED_RED` / `CAMERA_RESET` | \ref esp32_pwm_channels |
| `PWM_DEV(0):2 / LED2` | `GPIO4` | `GPIO4` | - | - | `LED_BLUE` / `CAMERA_D0` | \ref esp32_pwm_channels |
| `PWM_DEV(0):1 / LED2` | `GPIO4` | `GPIO4` | - | - | `LED_BLUE` / `CAMERA_D0` | \ref esp32_pwm_channels |
| `LED1` | `GPIO2` | `GPIO2` | `GPIO2` | `GPIO2` | `LED_GREEN` | |
| `I2C_DEV(0):SCL` | `GPIO27` | `GPIO27` | `GPIO27` | `GPIO27` | `CAMERA_SIO_C` | \ref esp32_i2c_interfaces |
| `I2C_DEV(0):SDA` | `GPIO26` | `GPIO26` | `GPIO26` | `GPIO27` | `CAMERA_SIO_D` | \ref esp32_i2c_interfaces |
| `I2C_DEV(0):SDA` | `GPIO26` | `GPIO26` | `GPIO26` | `GPIO26` | `CAMERA_SIO_D` | \ref esp32_i2c_interfaces |
| `UART_DEV(0):TX` | `GPIO1` | `GPIO1` | `GPIO1` | `GPIO1` | | \ref esp32_uart_interfaces |
| `UART_DEV(0):RX` | `GPIO3` | `GPIO3` | `GPIO3` | `GPIO3` | | \ref esp32_uart_interfaces |
| `SDMMC_DEV(0):CLK` | `GPIO14` | `GPIO14` | - | - | SD-Card | \ref esp32_sdmmc_interfaces |
| `SDMMC_DEV(0):CMD` | `GPIO15` | `GPIO` | - | - | SD-Card | \ref esp32_sdmmc_interfaces |
| `SDMMC_DEV(0):DAT0` | `GPIO2` | `GPIO2` | - | - | SD-Card | \ref esp32_sdmmc_interfaces |
| `SDMMC_DEV(0):DAT1` | `GPIO4` | `GPIO4` | - | - | SD-Card | \ref esp32_sdmmc_interfaces |
| `SDMMC_DEV(0):DAT2` | `GPIO12` | `GPIO` | - | - | SD-Card | \ref esp32_sdmmc_interfaces |
| `SDMMC_DEV(0):DAT3` | `GPIO13` | `GPIO` | - | - | SD-Card | \ref esp32_sdmmc_interfaces |
| `SPI_DEV(0):SCK` | `GPIO14` | `GPIO14` | `GPIO14` | `GPIO14` | HSPI: SD-Card / Peripherals | \ref esp32_spi_interfaces |
| `SPI_DEV(0):MOSI` | `GPIO15` | `GPIO15` | `GPIO15` | `GPIO15` | HSPI: SD-Card / Peripherals | \ref esp32_spi_interfaces |
| `SPI_DEV(0):CS0` | `GPIO13` | `GPIO13` | `GPIO13` | `GPIO13` | HSPI: SD-Card CS | \ref esp32_spi_interfaces |
Expand Down Expand Up @@ -133,28 +139,29 @@ These abbreviations are used in subsequent tables:

</center>

Following table shows the default board configuration sorted by GPIOs.
Following table shows the default board configuration sorted by GPIOs depending
on used hardware.

<center>

| Pin | None | SDC | CAM | SDC+CAM | Remarks |
| Pin | None | SDC 4-bit | CAM | SDC 1-bit + CAM | Remarks |
|:-------|:-----------------------|:--------------------|:--------------------|:---------------------------|:-----|
| GPIO0 | PWM_DEV(0):0 / LED0 | PWM_DEV(0):0 / LED0 | CAMERA_RESET | CAMERA_RESET | |
| GPIO1 | UART_DEV(0):TX | UART_DEV(0):TX | UART_DEV(0):TX | UART_DEV(0):TX | |
| GPIO2 | SPI_DEV(0):MISO / LED1 | SPI_DEV(0):MISO | SPI_DEV(0):MISO | SPI_DEV(0):MISO | HSPI |
| GPIO2 | SPI_DEV(0):MISO / LED1 | SDMMC_DEV(0):DAT0 | SPI_DEV(0):MISO | SDMMC_DEV(0):DAT0 | HSPI |
| GPIO3 | UART_DEV(0):RX | UART_DEV(0):RX | UART_DEV(0):RX | UART_DEV(0):RX | |
| GPIO4 | PWM_DEV(0):1 / LED2 | PWM_DEV(0):1 / LED2 | CAMERA_D0 | CAMERA_D0 | |
| GPIO4 | PWM_DEV(0):1 / LED2 | SDMMC_DEV(0):DAT1 | CAMERA_D0 | CAMERA_D0 | |
| GPIO5 | LCD LED | LCD_LED | CAMERA_D1 | CAMERA_D1 | |
| GPIO6 | Flash CLK | Flash CLK | Flash CLK | Flash CLK | |
| GPIO7 | Flash SD0 | Flash SD0 | Flash SD0 | Flash SD0 | |
| GPIO8 | Flash SD1 | Flash SD1 | Flash SD1 | Flash SD1 | |
| GPIO9 | | | | | |
| GPIO10 | | | | | |
| GPIO11 | Flash CMD | Flash CMD | Flash CMD | Flash CMD | |
| GPIO12 | | | | | |
| GPIO13 | SPI_DEV(0):CS0 | SPI_DEV(0):CS0 | SPI_DEV(0):CS0 | SPI_DEV(0):CS0 | HSPI / SD-Card CS |
| GPIO14 | SPI_DEV(0):SCK | SPI_DEV(0):SCK | SPI_DEV(0):SCK | SPI_DEV(0):SCK | HSPI |
| GPIO15 | SPI_DEV(0):MOSI | SPI_DEV(0):MOSI | SPI_DEV(0):MOSI | SPI_DEV(0):MOSI | HSPI |
| GPIO12 | | SDMMC_DEV(0):DAT2 | | | |
| GPIO13 | SPI_DEV(0):CS0 | SDMMC_DEV(0):DAT3 | SPI_DEV(0):CS0 | | HSPI / SPI SD-Card CS |
| GPIO14 | SPI_DEV(0):SCK | SDMMC_DEV(0):CLK | SPI_DEV(0):SCK | | HSPI |
| GPIO15 | SPI_DEV(0):MOSI | SDMMC_DEV(0):CMD | SPI_DEV(0):MOSI | | HSPI |
| GPIO16 | N/A | N/A | N/A | N/A | see below |
| GPIO17 | N/A | N/A | N/A | N/A | see below |
| GPIO18 | LCD_RESET | LCD_RESET | LCD_RESET | CAMERA_D2 | |
Expand Down
42 changes: 37 additions & 5 deletions boards/esp32-wrover-kit/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define PERIPH_CONF_H

#include <stdint.h>
#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -109,26 +110,51 @@
*
* LEDs are used as PWM channels for device PWM_DEV(0).
*
* @note As long as the according PWM device is not initialized with function
* pwm_init, the GPIOs declared for this device can be used for other
* purposes.
*
* @note As long as the according PWM device is not initialized with
* the `pwm_init`, the GPIOs declared for this device can be used
* for other purposes.
*
* @{
*/
#ifndef PWM0_GPIOS
#if !MODULE_ESP32_WROVER_KIT_CAMERA || DOXYGEN
#if (!MODULE_ESP32_WROVER_KIT_CAMERA && !MODULE_PERIPH_SDMMC) || DOXYGEN
#define PWM0_GPIOS { GPIO0, GPIO4 } /**< only available when camera is not connected */
#elif !MODULE_ESP32_WROVER_KIT_CAMERA
#define PWM0_GPIOS { GPIO0 }
#else
#define PWM0_GPIOS { }
#endif
#endif

/** @} */

/**
* @name SD/MMC host controller configuration
*
* @warning If the camera is plugged in, the SD Card has to be used in
* 1-bit mode.
* @{
*/

/** SDMMC devices */
static const sdmmc_conf_t sdmmc_config[] = {
{
.slot = SDMMC_SLOT_1,
.cd = GPIO21,
.wp = GPIO_UNDEF,
#if MODULE_ESP32_WROVER_KIT_CAMERA
/* if camera used, only DAT0 is available */
.bus_width = 1,
#else
.bus_width = 4,
#endif
},
};

/** Number of configured SDMMC devices */
#define SDMMC_CONFIG_NUMOF 1
/** @} */

/**
* @name SPI configuration
*
Expand All @@ -137,6 +163,12 @@
* HSPI is always available and therefore used as SPI_DEV(0)
* VSPI is only available when the camera is not plugged.
*
* @warning In order not to change the index of the SPI devices depending on
* the different hardware configuration options including the camera,
* SPI_DEV(0) is also defined in case of using the SD/MMC host
* controller, by default but cannot be used once an SD card is
* inserted. Use SPI_DEV(1) instead in this case.
*
* @{
*/

Expand Down

0 comments on commit c2017a8

Please sign in to comment.