Skip to content

Commit 1904833

Browse files
UnexpectedMakerdpgeorge
authored andcommitted
esp32: Add SDCard support for S3, and a GENERIC_S3_SPIRAM board.
Also add support for GPIO 47 and 48 on S3 boards.
1 parent f72b497 commit 1904833

File tree

10 files changed

+100
-6
lines changed

10 files changed

+100
-6
lines changed

ports/esp32/boards/GENERIC_S3/mpconfigboard.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
#define MICROPY_HW_MCU_NAME "ESP32S3"
33

44
#define MICROPY_PY_BLUETOOTH (0)
5-
#define MICROPY_HW_ENABLE_SDCARD (0)
65
#define MICROPY_PY_MACHINE_DAC (0)
76

87
#define MICROPY_HW_I2C0_SCL (9)
98
#define MICROPY_HW_I2C0_SDA (8)
109

11-
#define MICROPY_HW_SPI1_MOSI (35) // SDO
12-
#define MICROPY_HW_SPI1_MISO (37) // SDI
13-
#define MICROPY_HW_SPI1_SCK (36)
10+
#define MICROPY_HW_SPI1_MOSI (35)
11+
#define MICROPY_HW_SPI1_MISO (36)
12+
#define MICROPY_HW_SPI1_SCK (37)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"deploy": [
3+
"../deploy.md"
4+
],
5+
"docs": "",
6+
"features": [
7+
"BLE",
8+
"WiFi"
9+
],
10+
"images": [],
11+
"mcu": "esp32s3",
12+
"product": "Generic ESP32-S3 (SPIRAM)",
13+
"thumbnail": "",
14+
"url": "https://www.espressif.com/en/products/modules",
15+
"vendor": "Espressif"
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(IDF_TARGET esp32s3)
2+
3+
set(SDKCONFIG_DEFAULTS
4+
boards/sdkconfig.base
5+
boards/sdkconfig.usb
6+
boards/sdkconfig.spiram_sx
7+
boards/GENERIC_S3_SPIRAM/sdkconfig.board
8+
)
9+
10+
if(NOT MICROPY_FROZEN_MANIFEST)
11+
set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py)
12+
endif()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#define MICROPY_HW_BOARD_NAME "ESP32S3 module (spiram)"
2+
#define MICROPY_HW_MCU_NAME "ESP32S3"
3+
4+
#define MICROPY_PY_BLUETOOTH (0)
5+
#define MICROPY_PY_MACHINE_DAC (0)
6+
7+
#define MICROPY_HW_I2C0_SCL (9)
8+
#define MICROPY_HW_I2C0_SDA (8)
9+
10+
#define MICROPY_HW_SPI1_MOSI (35)
11+
#define MICROPY_HW_SPI1_MISO (36)
12+
#define MICROPY_HW_SPI1_SCK (37)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CONFIG_FLASHMODE_QIO=y
2+
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
3+
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
4+
CONFIG_ESPTOOLPY_AFTER_NORESET=y
5+
6+
CONFIG_SPIRAM_MEMTEST=
7+
8+
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
9+
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
10+
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=
11+
CONFIG_PARTITION_TABLE_CUSTOM=y
12+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-8MiB.csv"

ports/esp32/boards/sdkconfig.spiram_sx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# MicroPython on ESP32-S2 and ESP32-PAD1_subscript_3, ESP IDF configuration with SPIRAM support
22
CONFIG_ESP32S2_SPIRAM_SUPPORT=y
3+
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
4+
CONFIG_SPIRAM_MODE_QUAD=y
35
CONFIG_SPIRAM_TYPE_AUTO=y
46
CONFIG_DEFAULT_PSRAM_CLK_IO=30
57
CONFIG_DEFAULT_PSRAM_CS_IO=26
@@ -9,3 +11,5 @@ CONFIG_SPIRAM_BOOT_INIT=y
911
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
1012
CONFIG_SPIRAM_USE_MEMMAP=y
1113
CONFIG_SPIRAM_MEMTEST=y
14+
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
15+
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768

ports/esp32/machine_pin.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ STATIC const machine_pin_obj_t machine_pin_obj[] = {
200200
{{&machine_pin_type}, GPIO_NUM_46},
201201

202202
#endif
203+
204+
#if CONFIG_IDF_TARGET_ESP32S3 && MICROPY_HW_ESP32S3_EXTENDED_IO
205+
206+
{{&machine_pin_type}, GPIO_NUM_47},
207+
{{&machine_pin_type}, GPIO_NUM_48},
208+
209+
#endif
203210
};
204211

205212
// forward declaration
@@ -631,6 +638,14 @@ STATIC const machine_pin_irq_obj_t machine_pin_irq_object[] = {
631638
{{&machine_pin_irq_type}, GPIO_NUM_43},
632639
{{&machine_pin_irq_type}, GPIO_NUM_44},
633640
{{&machine_pin_irq_type}, GPIO_NUM_45},
641+
{{&machine_pin_irq_type}, GPIO_NUM_46},
642+
643+
#endif
644+
645+
#if CONFIG_IDF_TARGET_ESP32S3 && MICROPY_HW_ESP32S3_EXTENDED_IO
646+
647+
{{&machine_pin_irq_type}, GPIO_NUM_47},
648+
{{&machine_pin_irq_type}, GPIO_NUM_48},
634649

635650
#endif
636651
};

ports/esp32/machine_sdcard.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
188188
}
189189

190190
if (is_spi) {
191+
#if CONFIG_IDF_TARGET_ESP32S3
192+
self->host.slot = slot_num ? SPI3_HOST : SPI2_HOST;
193+
#else
191194
self->host.slot = slot_num ? HSPI_HOST : VSPI_HOST;
195+
#endif
192196
}
193197

194198
DEBUG_printf(" Calling host.init()");
@@ -198,6 +202,20 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
198202

199203
if (is_spi) {
200204
// SPI interface
205+
#if CONFIG_IDF_TARGET_ESP32S3
206+
STATIC const sdspi_slot_config_t slot_defaults[2] = {
207+
{
208+
.gpio_miso = GPIO_NUM_36,
209+
.gpio_mosi = GPIO_NUM_35,
210+
.gpio_sck = GPIO_NUM_37,
211+
.gpio_cs = GPIO_NUM_34,
212+
.gpio_cd = SDSPI_SLOT_NO_CD,
213+
.gpio_wp = SDSPI_SLOT_NO_WP,
214+
.dma_channel = 2
215+
},
216+
SDSPI_SLOT_CONFIG_DEFAULT()
217+
};
218+
#else
201219
STATIC const sdspi_slot_config_t slot_defaults[2] = {
202220
{
203221
.gpio_miso = GPIO_NUM_19,
@@ -210,6 +228,7 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
210228
},
211229
SDSPI_SLOT_CONFIG_DEFAULT()
212230
};
231+
#endif
213232

214233
DEBUG_printf(" Setting up SPI slot configuration");
215234
sdspi_slot_config_t slot_config = slot_defaults[slot_num];

ports/esp32/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void mp_task(void *pvParameter) {
101101
#if CONFIG_ESP32_SPIRAM_SUPPORT || CONFIG_SPIRAM_SUPPORT
102102
// Try to use the entire external SPIRAM directly for the heap
103103
size_t mp_task_heap_size;
104-
void *mp_task_heap = (void *)0x3f800000;
104+
void *mp_task_heap = (void *)SOC_EXTRAM_DATA_LOW;
105105
switch (esp_spiram_get_chip_size()) {
106106
case ESP_SPIRAM_SIZE_16MBITS:
107107
mp_task_heap_size = 2 * 1024 * 1024;
@@ -120,7 +120,7 @@ void mp_task(void *pvParameter) {
120120
// Try to use the entire external SPIRAM directly for the heap
121121
size_t mp_task_heap_size;
122122
size_t esp_spiram_size = esp_spiram_get_size();
123-
void *mp_task_heap = (void *)0x3ff80000 - esp_spiram_size;
123+
void *mp_task_heap = (void *)SOC_EXTRAM_DATA_HIGH - esp_spiram_size;
124124
if (esp_spiram_size > 0) {
125125
mp_task_heap_size = esp_spiram_size;
126126
} else {

ports/esp32/mpconfigport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ typedef long mp_off_t;
315315
// board specifics
316316
#define MICROPY_PY_SYS_PLATFORM "esp32"
317317

318+
// ESP32-S3 extended IO for 47 & 48
319+
#ifndef MICROPY_HW_ESP32S3_EXTENDED_IO
320+
#define MICROPY_HW_ESP32S3_EXTENDED_IO (1)
321+
#endif
322+
318323
#ifndef MICROPY_HW_ENABLE_MDNS_QUERIES
319324
#define MICROPY_HW_ENABLE_MDNS_QUERIES (1)
320325
#endif

0 commit comments

Comments
 (0)