Skip to content

Commit

Permalink
Fix io16 io17 and PSRAM support (espressif#1564)
Browse files Browse the repository at this point in the history
* Add PSRAM init and malloc funtions

* Rebuild IDF libs
  • Loading branch information
me-no-dev authored Jun 30, 2018
1 parent b855eb2 commit 184bb06
Show file tree
Hide file tree
Showing 48 changed files with 132 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CORE_SRCS
cores/esp32/esp32-hal-ledc.c
cores/esp32/esp32-hal-matrix.c
cores/esp32/esp32-hal-misc.c
cores/esp32/esp32-hal-psram.c
cores/esp32/esp32-hal-sigmadelta.c
cores/esp32/esp32-hal-spi.c
cores/esp32/esp32-hal-time.c
Expand Down
3 changes: 3 additions & 0 deletions cores/esp32/esp32-hal-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ bool btInUse(){ return false; }

void initArduino()
{
#if CONFIG_SPIRAM_SUPPORT
psramInit();
#endif
esp_log_level_set("*", CONFIG_LOG_DEFAULT_LEVEL);
esp_err_t err = nvs_flash_init();
if(err == ESP_ERR_NVS_NO_FREE_PAGES){
Expand Down
99 changes: 99 additions & 0 deletions cores/esp32/esp32-hal-psram.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

#include "esp32-hal.h"
#include "sdkconfig.h"

#if CONFIG_SPIRAM_SUPPORT
#include "esp_spiram.h"
#include "soc/efuse_reg.h"
#include "esp_heap_caps.h"

static volatile bool spiramDetected = false;
static volatile bool spiramFailed = false;

bool psramInit(){
if (spiramDetected) {
return true;
}
#ifndef CONFIG_SPIRAM_BOOT_INIT
if (spiramFailed) {
return false;
}
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
uint32_t pkg_ver = chip_ver & 0x7;
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) {
spiramFailed = true;
log_w("PSRAM not supported!");
return false;
}
esp_spiram_init_cache();
if (esp_spiram_init() != ESP_OK) {
spiramFailed = true;
log_w("PSRAM init failed!");
pinMatrixOutDetach(16, false, false);
pinMatrixOutDetach(17, false, false);
return false;
}
if (!esp_spiram_test()) {
spiramFailed = true;
log_e("PSRAM test failed!");
return false;
}
if (esp_spiram_add_to_heapalloc() != ESP_OK) {
spiramFailed = true;
log_e("PSRAM could not be added to the heap!");
return false;
}
#endif
spiramDetected = true;
log_d("PSRAM enabled");
return true;
}

bool IRAM_ATTR psramFound(){
return spiramDetected;
}

void IRAM_ATTR *ps_malloc(size_t size){
if(!spiramDetected){
return NULL;
}
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
}

void IRAM_ATTR *ps_calloc(size_t n, size_t size){
if(!spiramDetected){
return NULL;
}
return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
}

void IRAM_ATTR *ps_realloc(void *ptr, size_t size){
if(!spiramDetected){
return NULL;
}
return heap_caps_realloc(ptr, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
}

#else

bool psramInit(){
return false;
}

bool IRAM_ATTR psramFound(){
return false;
}

void IRAM_ATTR *ps_malloc(size_t size){
return NULL;
}

void IRAM_ATTR *ps_calloc(size_t n, size_t size){
return NULL;
}

void IRAM_ATTR *ps_realloc(void *ptr, size_t size){
return NULL;
}

#endif
25 changes: 25 additions & 0 deletions cores/esp32/esp32-hal-psram.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef _ESP32_HAL_PSRAM_H_
#define _ESP32_HAL_PSRAM_H_

bool psramInit();
bool psramFound();

void *ps_malloc(size_t size);
void *ps_calloc(size_t n, size_t size);
void *ps_realloc(void *ptr, size_t size);

#endif /* _ESP32_HAL_PSRAM_H_ */
1 change: 1 addition & 0 deletions cores/esp32/esp32-hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void yield(void);
#include "esp32-hal-sigmadelta.h"
#include "esp32-hal-timer.h"
#include "esp32-hal-bt.h"
#include "esp32-hal-psram.h"
#include "esp_system.h"

//returns chip temperature in Celsius
Expand Down
Binary file modified tools/sdk/bin/bootloader_dio_40m.bin
Binary file not shown.
Binary file modified tools/sdk/bin/bootloader_dout_40m.bin
Binary file not shown.
Binary file modified tools/sdk/bin/bootloader_qout_40m.bin
Binary file not shown.
Binary file modified tools/sdk/bin/bootloader_qout_80m.bin
Binary file not shown.
4 changes: 1 addition & 3 deletions tools/sdk/include/config/sdkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
#define CONFIG_LOG_BOOTLOADER_LEVEL 0
#define CONFIG_MBEDTLS_TLS_ENABLED 1
#define CONFIG_LWIP_MAX_RAW_PCBS 16
#define CONFIG_SPIRAM_IGNORE_NOTFOUND 1
#define CONFIG_SMP_ENABLE 1
#define CONFIG_SPIRAM_SIZE 4194304
#define CONFIG_MBEDTLS_SSL_SESSION_TICKETS 1
Expand Down Expand Up @@ -228,6 +227,7 @@
#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1
#define CONFIG_MONITOR_BAUD 115200
#define CONFIG_ESP32_DEBUG_STUBS_ENABLE 1
#define CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST 1
#define CONFIG_FREERTOS_CORETIMER_0 1
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv"
#define CONFIG_MBEDTLS_HAVE_TIME 1
Expand All @@ -238,12 +238,10 @@
#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1
#define CONFIG_MBEDTLS_TLS_SERVER 1
#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1
#define CONFIG_SPIRAM_BOOT_INIT 1
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
#define CONFIG_CLASSIC_BT_ENABLED 1
#define CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK 1
#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1
#define CONFIG_SPIRAM_MEMTEST 1
#define CONFIG_WL_SECTOR_SIZE_4096 1
#define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1
#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1
Expand Down
Binary file modified tools/sdk/lib/libapp_trace.a
Binary file not shown.
Binary file modified tools/sdk/lib/libapp_update.a
Binary file not shown.
Binary file modified tools/sdk/lib/libbootloader_support.a
Binary file not shown.
Binary file modified tools/sdk/lib/libbt.a
Binary file not shown.
Binary file modified tools/sdk/lib/libcoap.a
Binary file not shown.
Binary file modified tools/sdk/lib/libconsole.a
Binary file not shown.
Binary file modified tools/sdk/lib/libcxx.a
Binary file not shown.
Binary file modified tools/sdk/lib/libdriver.a
Binary file not shown.
Binary file modified tools/sdk/lib/libesp-tls.a
Binary file not shown.
Binary file modified tools/sdk/lib/libesp32.a
Binary file not shown.
Binary file modified tools/sdk/lib/libesp_adc_cal.a
Binary file not shown.
Binary file modified tools/sdk/lib/libesp_http_client.a
Binary file not shown.
Binary file modified tools/sdk/lib/libethernet.a
Binary file not shown.
Binary file modified tools/sdk/lib/libexpat.a
Binary file not shown.
Binary file modified tools/sdk/lib/libfatfs.a
Binary file not shown.
Binary file modified tools/sdk/lib/libfreertos.a
Binary file not shown.
Binary file modified tools/sdk/lib/libheap.a
Binary file not shown.
Binary file modified tools/sdk/lib/liblog.a
Binary file not shown.
Binary file modified tools/sdk/lib/liblwip.a
Binary file not shown.
Binary file modified tools/sdk/lib/libmbedtls.a
Binary file not shown.
Binary file modified tools/sdk/lib/libmdns.a
Binary file not shown.
Binary file modified tools/sdk/lib/libnewlib.a
Binary file not shown.
Binary file modified tools/sdk/lib/libnghttp.a
Binary file not shown.
Binary file modified tools/sdk/lib/libnvs_flash.a
Binary file not shown.
Binary file modified tools/sdk/lib/libopenssl.a
Binary file not shown.
Binary file modified tools/sdk/lib/libpthread.a
Binary file not shown.
Binary file modified tools/sdk/lib/libsdmmc.a
Binary file not shown.
Binary file modified tools/sdk/lib/libsmartconfig_ack.a
Binary file not shown.
Binary file modified tools/sdk/lib/libsoc.a
Binary file not shown.
Binary file modified tools/sdk/lib/libspi_flash.a
Binary file not shown.
Binary file modified tools/sdk/lib/libspiffs.a
Binary file not shown.
Binary file modified tools/sdk/lib/libtcpip_adapter.a
Binary file not shown.
Binary file modified tools/sdk/lib/libulp.a
Binary file not shown.
Binary file modified tools/sdk/lib/libvfs.a
Binary file not shown.
Binary file modified tools/sdk/lib/libwear_levelling.a
Binary file not shown.
Binary file modified tools/sdk/lib/libwpa_supplicant.a
Binary file not shown.
Binary file modified tools/sdk/lib/libxtensa-debug-module.a
Binary file not shown.
6 changes: 2 additions & 4 deletions tools/sdk/sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,15 @@ CONFIG_SPIRAM_SUPPORT=y
#
# SPI RAM config
#
CONFIG_SPIRAM_BOOT_INIT=y
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
CONFIG_SPIRAM_BOOT_INIT=
CONFIG_SPIRAM_USE_MEMMAP=
CONFIG_SPIRAM_USE_CAPS_ALLOC=y
CONFIG_SPIRAM_USE_MALLOC=
CONFIG_SPIRAM_TYPE_ESPPSRAM32=y
CONFIG_SPIRAM_SIZE=4194304
CONFIG_SPIRAM_SPEED_40M=y
CONFIG_SPIRAM_MEMTEST=y
CONFIG_SPIRAM_CACHE_WORKAROUND=y
CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST=
CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST=y
CONFIG_MEMMAP_TRACEMEM=
CONFIG_MEMMAP_TRACEMEM_TWOBANKS=
CONFIG_ESP32_TRAX=
Expand Down

0 comments on commit 184bb06

Please sign in to comment.