-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Mbedtls using external memory failing #4770
Comments
I've got a simple example which tries to load an ini file from a server via HTTPS which works if using internal memory but fails when switched to use external. The sdkconfig we used to build with is also below as well This used to work until the lets encrypt cert was updated and at the same time it was switched from x3 to r3, maybe this causes the issue? #include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
const char* ssid = "ssid";
const char* password = "pass";
const char* rootCACertificate = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIFjTCCA3WgAwIBAgIRANOxciY0IzLc9AUoUSrsnGowDQYJKoZIhvcNAQELBQAw\n" \
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n" \
"cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTYxMDA2MTU0MzU1\n" \
"WhcNMjExMDA2MTU0MzU1WjBKMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg\n" \
"RW5jcnlwdDEjMCEGA1UEAxMaTGV0J3MgRW5jcnlwdCBBdXRob3JpdHkgWDMwggEi\n" \
"MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCc0wzwWuUuR7dyXTeDs2hjMOrX\n" \
"NSYZJeG9vjXxcJIvt7hLQQWrqZ41CFjssSrEaIcLo+N15Obzp2JxunmBYB/XkZqf\n" \
"89B4Z3HIaQ6Vkc/+5pnpYDxIzH7KTXcSJJ1HG1rrueweNwAcnKx7pwXqzkrrvUHl\n" \
"Npi5y/1tPJZo3yMqQpAMhnRnyH+lmrhSYRQTP2XpgofL2/oOVvaGifOFP5eGr7Dc\n" \
"Gu9rDZUWfcQroGWymQQ2dYBrrErzG5BJeC+ilk8qICUpBMZ0wNAx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AT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BImlJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1OyK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90IdshCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6ZvMldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqXnLRbwHOoq7hHwg==\n"\
"-----END CERTIFICATE-----\n";
void setup() {
// put your setup code here, to run once:
Serial.begin(500000);
log_i("Connecting to Wifi");
WiFi.begin(ssid, password);
}
void loop() {
// put your main code here, to run repeatedly:
/*log_i("Free memory: %d %d", ESP.getFreeHeap(), heap_caps_get_free_size(MALLOC_CAP_32BIT));
for (int i = 0; i < 20; ++i) {
uint8_t *buffer = (uint8_t*)malloc(10*1024);
if (buffer != NULL) {
memset(buffer, 0x00, 10*1024);
}
else {
log_d("Couldn't create buffer: %d", i);
}
}
for (int i = 0; i < 50; ++i) {
uint8_t *buffer = (uint8_t*)heap_caps_malloc(10*1024, MALLOC_CAP_32BIT | MALLOC_CAP_SPIRAM);
if (buffer != NULL) {
memset(buffer, 0x00, 10*1024);
}
else {
log_d("Couldn't allocate caps: %d", i);
}
}*/
log_i("Free memory: %d %d", ESP.getFreeHeap(), heap_caps_get_free_size(MALLOC_CAP_32BIT));
bool done_test = false;
if (!WiFi.isConnected()) {
log_i("WiFi disconnected. retrying WiFi connection...");
log_i("Free memory: %d %d", ESP.getFreeHeap(), heap_caps_get_free_size(MALLOC_CAP_32BIT));
int wait = 0;
while (1) {
sleep(1);
wait++;
if (WiFi.isConnected()) {
log_i("Connected!");
break;
}
if (wait > 10) {
log_i("retrying WiFi connection...");
WiFi.disconnect();
WiFi.begin(ssid, password);
wait = 0;
}
}
}
if (WiFi.isConnected() && !done_test) {
log_i("running test...");
WiFiClientSecure client;
client.setCACert(rootCACertificate);
log_i("cert set...");
if (!client.connect("wiphone.io", 443)) {
log_i("Unable to connect to server");
} else {
log_i("After connected to server");
/*
client.print((std::string("GET ") + "/static/releases/firmware/WiPhone-phone.ini" + " HTTP/1.1\r\n" +
"Host: " + "wiphone.io" + "\r\n" +
"Connection: close\r\n\r\n").c_str());
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 15000) {
log_i("Client Timeout !");
client.stop();
break;
}
}
while (client.available()) {
String l = client.readStringUntil('\r');
log_i("Read: %s", l.c_str());
}
*/
done_test = true;
}
}
sleep(1);
}```
Automatically generated file; DO NOT EDIT.Espressif IoT Development Framework ConfigurationCONFIG_IDF_TARGET="esp32" SDK tool configurationCONFIG_TOOLPREFIX="xtensa-esp32-elf-" Application managerCONFIG_APP_COMPILE_TIME_DATE=y Arduino ConfigurationCONFIG_ENABLE_ARDUINO_DEPENDS=y Debug Log ConfigurationCONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_NONE= Bootloader configCONFIG_LOG_BOOTLOADER_LEVEL_NONE= Security featuresCONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT= Serial flasher configCONFIG_ESPTOOLPY_PORT="/dev/cu.usbserial-DO00EAB0" Partition TableCONFIG_PARTITION_TABLE_SINGLE_APP=y Compiler optionsCONFIG_OPTIMIZATION_LEVEL_DEBUG=y Component configApplication Level TracingCONFIG_ESP32_APPTRACE_DEST_TRAX= BluetoothCONFIG_BT_ENABLED=y Bluetooth controllerCONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY= MODEM SLEEP OptionsCONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y Driver configurationsADC configurationCONFIG_ADC_FORCE_XPD_FSM= SPI configurationCONFIG_SPI_MASTER_IN_IRAM= eFuse Bit ManagerCONFIG_EFUSE_CUSTOM_TABLE= ESP-FACE ConfigurationCONFIG_MTMN_LITE_QUANT=y Object DetectionCONFIG_DETECT_WITH_LANDMARK= Pose EstimationCONFIG_HD_NANO1=y ESP32-specificCONFIG_IDF_TARGET_ESP32=y SPI RAM configCONFIG_SPIRAM_BOOT_INIT= PSRAM clock and cs IO for ESP32-DOWDCONFIG_D0WD_PSRAM_CLK_IO=17 PSRAM clock and cs IO for ESP32-D2WDCONFIG_D2WD_PSRAM_CLK_IO=9 PSRAM clock and cs IO for ESP32-PICOCONFIG_PICO_PSRAM_CS_IO=10 Wi-FiCONFIG_SW_COEXIST_ENABLE=y PHYCONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y Power ManagementCONFIG_PM_ENABLE= Camera configurationCONFIG_OV7670_SUPPORT=y ADC-CalibrationCONFIG_ADC_CAL_EFUSE_TP_ENABLE=y Event Loop LibraryCONFIG_EVENT_LOOP_PROFILING= ESP HTTP clientCONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y HTTP ServerCONFIG_HTTPD_MAX_REQ_HDR_LEN=512 ESP HTTPS OTACONFIG_OTA_ALLOW_HTTP= Core dumpCONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH= EthernetCONFIG_DMA_RX_BUF_NUM=10 FAT Filesystem supportCONFIG_FATFS_CODEPAGE_DYNAMIC= Modbus configurationCONFIG_MB_QUEUE_LENGTH=20 FreeRTOSCONFIG_FREERTOS_UNICORE= Heap memory debuggingCONFIG_HEAP_POISONING_DISABLED= libsodiumCONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y Log outputCONFIG_LOG_DEFAULT_LEVEL_NONE= LWIPCONFIG_L2_TO_L3_COPY= DHCP serverCONFIG_LWIP_DHCPS_LEASE_UNIT=60 TCPCONFIG_LWIP_TCP_ISN_HOOK=y UDPCONFIG_LWIP_MAX_UDP_PCBS=16 ICMPCONFIG_LWIP_MULTICAST_PING= LWIP RAW APICONFIG_LWIP_MAX_RAW_PCBS=16 SNTPCONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 mbedTLSCONFIG_MBEDTLS_INTERNAL_MEM_ALLOC= TLS Key Exchange MethodsCONFIG_MBEDTLS_PSK_MODES=y Symmetric CiphersCONFIG_MBEDTLS_AES_C=y CertificatesCONFIG_MBEDTLS_PEM_PARSE_C=y mDNSCONFIG_MDNS_MAX_SERVICES=10 ESP-MQTT ConfigurationsCONFIG_MQTT_PROTOCOL_311=y NVSOpenSSLCONFIG_OPENSSL_DEBUG= PThreadsCONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5 SPI Flash driverCONFIG_SPI_FLASH_VERIFY_WRITE= SPIFFS ConfigurationCONFIG_SPIFFS_MAX_PARTITIONS=3 SPIFFS Cache ConfigurationCONFIG_SPIFFS_CACHE=y Debug ConfigurationCONFIG_SPIFFS_DBG= TCP/IP AdapterCONFIG_IP_LOST_TIMER_INTERVAL=120 Unity unit testing libraryCONFIG_UNITY_ENABLE_FLOAT=y Virtual file systemCONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y Wear LevellingCONFIG_WL_SECTOR_SIZE_512= Wi-Fi Provisioning ManagerCONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16 SupplicantCONFIG_WPA_WPS_WARS=
|
We've also added a component to idf which loads the file via HTTPS and called it from Arduino and it has the same issue. Calling the component from an esp-idf built program and it works. Could you please advise on why the same code when built via esp-idf would work but when built via Arduino would fail? |
Are you saying that when using Arduino as IDF component it is failing, but when using only IDF it does not? Other than that, Arduino does not have the flag for external RAM set |
I'm using the esp32-arduino-lib-builder and have enabled the external memory option in the config file. When running the output that repo produces from the Disabling external memory and running |
hmm... since the lib builder is in reality "Using Arduino as IDF component", what happens if you change |
Replacing |
Are you sure that you copied the resulting release from |
I'm building on Linux but running Arduino on Mac so am using a different script to copy but am copying the newly build one over. If I wasn't copying it over disabling the external memory flag for mbedtls and copying again wouldn't make it work? |
if something is not copied over properly, your change will not apply. Are you sure that all is copied over? Are you using the same version of esp32-arduino on the Mac? (BTW I use/develop the lib builder on a Mac. Maybe you can try that?) |
Thanks, I'll try building on Mac and running the same script |
Yes we did everything. That you mentioned probably like 50 iterations. back and forth. At the last i have another code in which we just use the static mbedtls mbedtls_memory_buffer_alloc_init( memory_buf, sizeof(memory_buf) ); Using this. Interesting thing. When i use internal ram it works fine. But if i use psram malloc it crashes. |
I'll post that code here too. It's little messy up but it will do our job. For that i needed to uncomment #define tag from esp_config in mbedtls component esp-idf folder //#define MBEDTLS_MEMORY_BUFFER_ALLOC_C I thought if i just allocate psram memory in before everything it might solve the problem but still same issue. |
#include <WiFi.h>
#include <HTTPClient.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include "lwip/netdb.h"
#include "lwip/dns.h"
#include "mbedtls/platform.h"
#include "mbedtls/net_sockets.h"
#include "mbedtls/esp_debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/error.h"
#include "mbedtls/certs.h"
#include "mbedtls/memory_buffer_alloc.h"
const char* ssid = "Akshar";
const char* password = "sss3kk2aaaa4";
extern const uint8_t server_root_cert_pem_start[] asm("_binary_server_root_cert_pem_start");
extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_pem_end");
#define WEB_SERVER "www.wiphone.io"
#define WEB_PORT "443"
#define WEB_URL "https://www.wiphone.io/static/releases/firmware/WiPhone-phone.ini"
static const char *TAG = "example";
const char rootCert[] = "-----BEGIN CERTIFICATE-----\n"\
"MIIFazCCA1OgAwIB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1nYsvC9JSQ6ZvMldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqXnLRbwHOoq7hHwg==\n"\
"-----END CERTIFICATE-----\n";
static const char *REQUEST = "GET " WEB_URL " HTTP/1.0\r\n"
"Host: "WEB_SERVER"\r\n"
"User-Agent: esp-idf/1.0 esp32\r\n"
"\r\n";
// extern "C"
// {
// int printf(const char *format,...);
// }
// unsigned char alloc_buf[80000];
unsigned char *alloc_buf;
static void https_get_task(void *pvParameters)
{
char buf[512];
int ret, flags, len;
// unsigned char *alloc_buf = (unsigned char *)ps_calloc(80000,1);
if(alloc_buf == NULL)
{
ESP_LOGI(TAG,"alloc_buf is not initialised");
return;
}
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
mbedtls_x509_crt cacert;
mbedtls_ssl_config conf;
mbedtls_net_context server_fd;
mbedtls_memory_buffer_alloc_init(alloc_buf, 80000 );
mbedtls_ssl_init(&ssl);
mbedtls_x509_crt_init(&cacert);
mbedtls_ctr_drbg_init(&ctr_drbg);
ESP_LOGI(TAG, "Seeding the random number generator");
mbedtls_ssl_config_init(&conf);
mbedtls_entropy_init(&entropy);
if((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
NULL, 0)) != 0)
{
ESP_LOGE(TAG, "mbedtls_ctr_drbg_seed returned %d", ret);
abort();
}
ESP_LOGI(TAG, "Loading the CA root certificate...");
ret = mbedtls_x509_crt_parse(&cacert, (const unsigned char*)rootCert,sizeof(rootCert));
if(ret < 0)
{
ESP_LOGE(TAG, "mbedtls_x509_crt_parse returned -0x%x\n\n", -ret);
abort();
}
ESP_LOGI(TAG, "Setting hostname for TLS session...");
/* Hostname set here should match CN in server certificate */
if((ret = mbedtls_ssl_set_hostname(&ssl, WEB_SERVER)) != 0)
{
ESP_LOGE(TAG, "mbedtls_ssl_set_hostname returned -0x%x", -ret);
abort();
}
ESP_LOGI(TAG, "Setting up the SSL/TLS structure...");
if((ret = mbedtls_ssl_config_defaults(&conf,
MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT)) != 0)
{
ESP_LOGE(TAG, "mbedtls_ssl_config_defaults returned %d", ret);
// goto exit;
}
/* MBEDTLS_SSL_VERIFY_OPTIONAL is bad for security, in this example it will print
a warning if CA verification fails but it will continue to connect.
You should consider using MBEDTLS_SSL_VERIFY_REQUIRED in your own code.
*/
mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
mbedtls_ssl_conf_ca_chain(&conf, &cacert, NULL);
mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &ctr_drbg);
#ifdef CONFIG_MBEDTLS_DEBUG
mbedtls_esp_enable_debug_log(&conf, 4);
#endif
if ((ret = mbedtls_ssl_setup(&ssl, &conf)) != 0)
{
ESP_LOGE(TAG, "mbedtls_ssl_setup returned -0x%x\n\n", -ret);
// goto exit;
}
while(1) {
/* Wait for the callback to set the CONNECTED_BIT in the
event group.
*/
// xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
// false, true, portMAX_DELAY);
ESP_LOGI(TAG, "Connected to AP");
mbedtls_net_init(&server_fd);
ESP_LOGI(TAG, "Connecting to %s:%s...", WEB_SERVER, WEB_PORT);
if ((ret = mbedtls_net_connect(&server_fd, WEB_SERVER,
WEB_PORT, MBEDTLS_NET_PROTO_TCP)) != 0)
{
ESP_LOGE(TAG, "mbedtls_net_connect returned -%x", -ret);
// goto exit;
}
ESP_LOGI(TAG, "Connected.");
mbedtls_ssl_set_bio(&ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);
ESP_LOGI(TAG, "Performing the SSL/TLS handshake...");
while ((ret = mbedtls_ssl_handshake(&ssl)) != 0)
{
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)
{
ESP_LOGE(TAG, "mbedtls_ssl_handshake returned -0x%x", -ret);
// goto exit;
}
}
ESP_LOGI(TAG, "Verifying peer X.509 certificate...");
if ((flags = mbedtls_ssl_get_verify_result(&ssl)) != 0)
{
/* In real life, we probably want to close connection if ret != 0 */
ESP_LOGW(TAG, "Failed to verify peer certificate!");
bzero(buf, sizeof(buf));
mbedtls_x509_crt_verify_info(buf, sizeof(buf), " ! ", flags);
ESP_LOGW(TAG, "verification info: %s", buf);
}
else {
ESP_LOGI(TAG, "Certificate verified.");
}
ESP_LOGI(TAG, "Cipher suite is %s", mbedtls_ssl_get_ciphersuite(&ssl));
ESP_LOGI(TAG, "Writing HTTP request...");
size_t written_bytes = 0;
do {
ret = mbedtls_ssl_write(&ssl,
(const unsigned char *)REQUEST + written_bytes,
strlen(REQUEST) - written_bytes);
if (ret >= 0) {
ESP_LOGI(TAG, "%d bytes written", ret);
written_bytes += ret;
} else if (ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret != MBEDTLS_ERR_SSL_WANT_READ) {
ESP_LOGE(TAG, "mbedtls_ssl_write returned -0x%x", -ret);
// goto exit;
}
} while(written_bytes < strlen(REQUEST));
ESP_LOGI(TAG, "Reading HTTP response...");
do
{
len = sizeof(buf) - 1;
bzero(buf, sizeof(buf));
ret = mbedtls_ssl_read(&ssl, (unsigned char *)buf, len);
if(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE)
continue;
if(ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) {
ret = 0;
break;
}
if(ret < 0)
{
ESP_LOGE(TAG, "mbedtls_ssl_read returned -0x%x", -ret);
break;
}
if(ret == 0)
{
ESP_LOGI(TAG, "connection closed");
break;
}
len = ret;
ESP_LOGD(TAG, "%d bytes read", len);
/* Print response directly to stdout as it is read */
for(int i = 0; i < len; i++) {
putchar(buf[i]);
}
} while(1);
mbedtls_ssl_close_notify(&ssl);
// exit:
// mbedtls_ssl_session_reset(&ssl);
// mbedtls_net_free(&server_fd);
//
// if(ret != 0)
// {
// mbedtls_strerror(ret, buf, 100);
// ESP_LOGE(TAG, "Last error was: -0x%x - %s", -ret, buf);
// }
//
// putchar('\n'); // JSON output doesn't have a newline at end
//
// static int request_count;
// ESP_LOGI(TAG, "Completed %d requests", ++request_count);
//
// for(int countdown = 10; countdown >= 0; countdown--) {
// ESP_LOGI(TAG, "%d...", countdown);
// vTaskDelay(1000 / portTICK_PERIOD_MS);
// }
// ESP_LOGI(TAG, "Starting again!");
}
}
void setup() {
// alloc_buf = (unsigned char *)malloc(100);
alloc_buf = (unsigned char *)heap_caps_malloc(80000,MALLOC_CAP_SPIRAM);
Serial.begin(115200);
// if(alloc_buf == NULL)
// {
// Serial.println("alloc_buf is not initialised");
// }
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
xTaskCreate(&https_get_task, "https_get_task", 8192, NULL, 5, NULL);
}
void loop() {
delay(100);
Serial.println("getting");
// if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
//
// HTTPClient http;
//
// http.begin("https://wiphone.io/static/releases/firmware/WiPhone-phone.ini", rootCACertificate); //Specify the URL and certificate
// int httpCode = http.GET(); //Make the request
//
// if (httpCode > 0) { //Check for the returning code
//
// String payload = http.getString();
// Serial.println(httpCode);
// Serial.println(payload);
// }
//
// else {
// Serial.println("Error on HTTP request");
// }
//
// http.end(); //Free the resources
// }
//
// delay(10000);
} |
So if use this // unsigned char alloc_buf[80000]; it works fine. |
but when we use this alloc_buf = (unsigned char *)heap_caps_malloc(80000,MALLOC_CAP_SPIRAM); problem. |
@me-no-dev #4818 (comment) |
I've also just finished trying it on Mac and using the copy script linked and it doesn't work still |
i'm really confused why it would work in the lib-builder, but not when copied... it's the same files... except if some flag is missing in the build commands? They are taken from the build in the 4.2 branch (cmake) but not on master (make). Maybe check the output running a verbose build of the lib-builder and compare flags against what is in platform.txt? |
We've both been working on this independently to try and figure it out so chances are we've both not done something dumb with copying etc. Are you able to try enabling that external memory setting for mbedtls and try it? I'll have a look and see if I can see anything with the flags |
Same confusion here. What i have noticed is build settings, I am using mac @me-no-dev i have used this copy-to-arduino.sh one |
@me-no-dev can you try once doing this same on your side. it might take 10 minutes only. We have one thing to launch and we are just stuck at development because of this. |
Also we are running it on v1 hardware, not sure if that matters |
what do I need to test this? a board with WROVER module + the sketch above? |
I'm using a board with the following chip: ESP32D0WDQ6 (revision 1) with 8MB SPI RAM and Akshar is using: ESP32-D0WDQ6-ATUB00 |
Just to make sure that you know we only see the error when we enable the external memory and enable this option for mbedtls: |
@me-no-dev yes. nothing more. |
Looking at the flags I noticed this was missing: |
@shaun-mzj I have tried that as well same for me. |
@me-no-dev I have also tried using uni core but it didn't helped me either, |
The issue was that certain libraries that deal with PSRAM issues were not included in the linking process and were also not copied by the lib-builder. Lib-builder commit is here: espressif/esp32-arduino-lib-builder@3fa59d5 You can now create a proper update with mbedts in PSRAM :) |
Thank you! I've tried it and it working |
Hardware:
Board: esp32
Core Installation version: 1.0.5-rc6
IDE name: Arduino IDE
Flash Frequency: 40Mhz
PSRAM enabled: yes
Upload Speed: 921600
Computer OS: Mac OSX
Description:
I've built the latest release candidate of the code manually and have enabled the following flag:
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC
which causes the following error when accessing a web server:However if I switch mbedtls to use internal memory it can connect fine. Is there something else which needs to be done for the mbedtls library to use external memory?
The text was updated successfully, but these errors were encountered: