Skip to content

Commit 8b44f93

Browse files
me-no-devCurclamas
authored andcommitted
Fix io16 io17 and PSRAM support (espressif#1564)
* Add PSRAM init and malloc funtions * Rebuild IDF libs
1 parent 626e08e commit 8b44f93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+132
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(CORE_SRCS
99
cores/esp32/esp32-hal-ledc.c
1010
cores/esp32/esp32-hal-matrix.c
1111
cores/esp32/esp32-hal-misc.c
12+
cores/esp32/esp32-hal-psram.c
1213
cores/esp32/esp32-hal-sigmadelta.c
1314
cores/esp32/esp32-hal-spi.c
1415
cores/esp32/esp32-hal-time.c

cores/esp32/esp32-hal-misc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ bool btInUse(){ return false; }
8484

8585
void initArduino()
8686
{
87+
#if CONFIG_SPIRAM_SUPPORT
88+
psramInit();
89+
#endif
8790
esp_log_level_set("*", CONFIG_LOG_DEFAULT_LEVEL);
8891
esp_err_t err = nvs_flash_init();
8992
if(err == ESP_ERR_NVS_NO_FREE_PAGES){

cores/esp32/esp32-hal-psram.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
#include "esp32-hal.h"
3+
#include "sdkconfig.h"
4+
5+
#if CONFIG_SPIRAM_SUPPORT
6+
#include "esp_spiram.h"
7+
#include "soc/efuse_reg.h"
8+
#include "esp_heap_caps.h"
9+
10+
static volatile bool spiramDetected = false;
11+
static volatile bool spiramFailed = false;
12+
13+
bool psramInit(){
14+
if (spiramDetected) {
15+
return true;
16+
}
17+
#ifndef CONFIG_SPIRAM_BOOT_INIT
18+
if (spiramFailed) {
19+
return false;
20+
}
21+
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
22+
uint32_t pkg_ver = chip_ver & 0x7;
23+
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) {
24+
spiramFailed = true;
25+
log_w("PSRAM not supported!");
26+
return false;
27+
}
28+
esp_spiram_init_cache();
29+
if (esp_spiram_init() != ESP_OK) {
30+
spiramFailed = true;
31+
log_w("PSRAM init failed!");
32+
pinMatrixOutDetach(16, false, false);
33+
pinMatrixOutDetach(17, false, false);
34+
return false;
35+
}
36+
if (!esp_spiram_test()) {
37+
spiramFailed = true;
38+
log_e("PSRAM test failed!");
39+
return false;
40+
}
41+
if (esp_spiram_add_to_heapalloc() != ESP_OK) {
42+
spiramFailed = true;
43+
log_e("PSRAM could not be added to the heap!");
44+
return false;
45+
}
46+
#endif
47+
spiramDetected = true;
48+
log_d("PSRAM enabled");
49+
return true;
50+
}
51+
52+
bool IRAM_ATTR psramFound(){
53+
return spiramDetected;
54+
}
55+
56+
void IRAM_ATTR *ps_malloc(size_t size){
57+
if(!spiramDetected){
58+
return NULL;
59+
}
60+
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
61+
}
62+
63+
void IRAM_ATTR *ps_calloc(size_t n, size_t size){
64+
if(!spiramDetected){
65+
return NULL;
66+
}
67+
return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
68+
}
69+
70+
void IRAM_ATTR *ps_realloc(void *ptr, size_t size){
71+
if(!spiramDetected){
72+
return NULL;
73+
}
74+
return heap_caps_realloc(ptr, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
75+
}
76+
77+
#else
78+
79+
bool psramInit(){
80+
return false;
81+
}
82+
83+
bool IRAM_ATTR psramFound(){
84+
return false;
85+
}
86+
87+
void IRAM_ATTR *ps_malloc(size_t size){
88+
return NULL;
89+
}
90+
91+
void IRAM_ATTR *ps_calloc(size_t n, size_t size){
92+
return NULL;
93+
}
94+
95+
void IRAM_ATTR *ps_realloc(void *ptr, size_t size){
96+
return NULL;
97+
}
98+
99+
#endif

cores/esp32/esp32-hal-psram.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef _ESP32_HAL_PSRAM_H_
16+
#define _ESP32_HAL_PSRAM_H_
17+
18+
bool psramInit();
19+
bool psramFound();
20+
21+
void *ps_malloc(size_t size);
22+
void *ps_calloc(size_t n, size_t size);
23+
void *ps_realloc(void *ptr, size_t size);
24+
25+
#endif /* _ESP32_HAL_PSRAM_H_ */

cores/esp32/esp32-hal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void yield(void);
5959
#include "esp32-hal-sigmadelta.h"
6060
#include "esp32-hal-timer.h"
6161
#include "esp32-hal-bt.h"
62+
#include "esp32-hal-psram.h"
6263
#include "esp_system.h"
6364

6465
//returns chip temperature in Celsius

tools/sdk/bin/bootloader_dio_40m.bin

1.36 KB
Binary file not shown.

tools/sdk/bin/bootloader_dout_40m.bin

0 Bytes
Binary file not shown.

tools/sdk/bin/bootloader_qout_40m.bin

0 Bytes
Binary file not shown.

tools/sdk/bin/bootloader_qout_80m.bin

0 Bytes
Binary file not shown.

tools/sdk/include/config/sdkconfig.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@
190190
#define CONFIG_LOG_BOOTLOADER_LEVEL 0
191191
#define CONFIG_MBEDTLS_TLS_ENABLED 1
192192
#define CONFIG_LWIP_MAX_RAW_PCBS 16
193-
#define CONFIG_SPIRAM_IGNORE_NOTFOUND 1
194193
#define CONFIG_SMP_ENABLE 1
195194
#define CONFIG_SPIRAM_SIZE 4194304
196195
#define CONFIG_MBEDTLS_SSL_SESSION_TICKETS 1
@@ -228,6 +227,7 @@
228227
#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1
229228
#define CONFIG_MONITOR_BAUD 115200
230229
#define CONFIG_ESP32_DEBUG_STUBS_ENABLE 1
230+
#define CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST 1
231231
#define CONFIG_FREERTOS_CORETIMER_0 1
232232
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv"
233233
#define CONFIG_MBEDTLS_HAVE_TIME 1
@@ -238,12 +238,10 @@
238238
#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1
239239
#define CONFIG_MBEDTLS_TLS_SERVER 1
240240
#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1
241-
#define CONFIG_SPIRAM_BOOT_INIT 1
242241
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
243242
#define CONFIG_CLASSIC_BT_ENABLED 1
244243
#define CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK 1
245244
#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1
246-
#define CONFIG_SPIRAM_MEMTEST 1
247245
#define CONFIG_WL_SECTOR_SIZE_4096 1
248246
#define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1
249247
#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1

tools/sdk/lib/libapp_trace.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libapp_update.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libbootloader_support.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libbt.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libcoap.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libconsole.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libcxx.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libdriver.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libesp-tls.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libesp32.a

-2.35 KB
Binary file not shown.

tools/sdk/lib/libesp_adc_cal.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libesp_http_client.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libethernet.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libexpat.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libfatfs.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libfreertos.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libheap.a

0 Bytes
Binary file not shown.

tools/sdk/lib/liblog.a

0 Bytes
Binary file not shown.

tools/sdk/lib/liblwip.a

5.2 KB
Binary file not shown.

tools/sdk/lib/libmbedtls.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libmdns.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libnewlib.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libnghttp.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libnvs_flash.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libopenssl.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libpthread.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libsdmmc.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libsmartconfig_ack.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libsoc.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libspi_flash.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libspiffs.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libtcpip_adapter.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libulp.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libvfs.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libwear_levelling.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libwpa_supplicant.a

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

tools/sdk/sdkconfig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,15 @@ CONFIG_SPIRAM_SUPPORT=y
217217
#
218218
# SPI RAM config
219219
#
220-
CONFIG_SPIRAM_BOOT_INIT=y
221-
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
220+
CONFIG_SPIRAM_BOOT_INIT=
222221
CONFIG_SPIRAM_USE_MEMMAP=
223222
CONFIG_SPIRAM_USE_CAPS_ALLOC=y
224223
CONFIG_SPIRAM_USE_MALLOC=
225224
CONFIG_SPIRAM_TYPE_ESPPSRAM32=y
226225
CONFIG_SPIRAM_SIZE=4194304
227226
CONFIG_SPIRAM_SPEED_40M=y
228-
CONFIG_SPIRAM_MEMTEST=y
229227
CONFIG_SPIRAM_CACHE_WORKAROUND=y
230-
CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST=
228+
CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST=y
231229
CONFIG_MEMMAP_TRACEMEM=
232230
CONFIG_MEMMAP_TRACEMEM_TWOBANKS=
233231
CONFIG_ESP32_TRAX=

0 commit comments

Comments
 (0)