fix for PSRAM with new hapOut

Force hapOut to use internal memory only.

Tested on ESP32-S2 with/without PSRAM.  However, crashes on ESP32-S3 when using PSRAM (?!)
This commit is contained in:
Gregg 2024-01-06 16:55:17 -06:00
parent 4269eca982
commit bd474778e5
5 changed files with 35 additions and 20 deletions

View File

@ -73,7 +73,7 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.setLogLevel(1); homeSpan.setLogLevel(2);
homeSpan.enableWebLog(500); homeSpan.enableWebLog(500);
homeSpan.begin(Category::Lighting,"HomeSpan Max"); homeSpan.begin(Category::Lighting,"HomeSpan Max");

View File

@ -1604,15 +1604,19 @@ void Nonce::inc(){
HapOut::HapStreamBuffer::HapStreamBuffer(){ HapOut::HapStreamBuffer::HapStreamBuffer(){
buffer=(char *)HS_MALLOC(bufSize+1); // add 1 for adding null terminator when printing text // note - must require all memory allocation to be pulled from INTERNAL heap only
encBuf=(uint8_t *)HS_MALLOC(bufSize+18); // 2-byte AAD + encrypted data + 16-byte authentication tag
hash=(uint8_t *)HS_MALLOC(48); // space for SHA-384 hash output const uint32_t caps=MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL;
ctx = (mbedtls_sha512_context *)HS_MALLOC(sizeof(mbedtls_sha512_context)); // space for hash context
mbedtls_sha512_init(ctx); // initialize context
mbedtls_sha512_starts_ret(ctx,1); // start SHA-384 hash (note second argument=1)
setp(buffer, buffer+bufSize-1); buffer=(char *)heap_caps_malloc(bufSize+1,caps); // add 1 for adding null terminator when printing text
encBuf=(uint8_t *)heap_caps_malloc(bufSize+18,caps); // 2-byte AAD + encrypted data + 16-byte authentication tag
hash=(uint8_t *)heap_caps_malloc(48,caps); // space for SHA-384 hash output
ctx = (mbedtls_sha512_context *)heap_caps_malloc(sizeof(mbedtls_sha512_context),caps); // space for hash context
mbedtls_sha512_init(ctx); // initialize context
mbedtls_sha512_starts_ret(ctx,1); // start SHA-384 hash (note second argument=1)
setp(buffer, buffer+bufSize-1); // assign buffer pointers
} }
////////////////////////////////////// //////////////////////////////////////

View File

@ -207,6 +207,7 @@ class HapOut : public std::ostream {
HapStreamBuffer(); HapStreamBuffer();
~HapStreamBuffer(); ~HapStreamBuffer();
}; };
HapStreamBuffer hapBuffer; HapStreamBuffer hapBuffer;

View File

@ -186,9 +186,9 @@ void Span::pollTask() {
HAPClient::init(); // read NVS and load HAP settings HAPClient::init(); // read NVS and load HAP settings
if(heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL)<DEFAULT_LOW_MEM_THRESHOLD) if(heap_caps_get_free_size(MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)<DEFAULT_LOW_MEM_THRESHOLD)
LOG0("\n**** WARNING! Low Internal RAM Watermark of %d bytes is less than Low Threshold of %d bytes. Device *may* run out of memory.\n\n", LOG0("\n**** WARNING! Internal Free Heap of %d bytes is less than Low-Memory Threshold of %d bytes. Device *may* run out of Internal memory.\n\n",
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),DEFAULT_LOW_MEM_THRESHOLD); heap_caps_get_free_size(MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL),DEFAULT_LOW_MEM_THRESHOLD);
if(!strlen(network.wifiData.ssid)){ if(!strlen(network.wifiData.ssid)){
LOG0("*** WIFI CREDENTIALS DATA NOT FOUND. "); LOG0("*** WIFI CREDENTIALS DATA NOT FOUND. ");
@ -823,14 +823,24 @@ void Span::processSerialCommand(const char *c){
break; break;
case 'm': { case 'm': {
LOG0("Free Heap Internal RAM : %7d bytes. Low: %7d\n",heap_caps_get_free_size(MALLOC_CAP_INTERNAL),heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL)); multi_heap_info_t heapAll;
#if defined(BOARD_HAS_PSRAM) multi_heap_info_t heapInternal;
LOG0("Free Heap SPI (PS) RAM : %7d bytes. Low: %7d\n",heap_caps_get_free_size(MALLOC_CAP_SPIRAM),heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM)); multi_heap_info_t heapPSRAM;
#endif
LOG0("Lowest stack level : %7d bytes\n",uxTaskGetStackHighWaterMark(NULL)); heap_caps_get_info(&heapAll,MALLOC_CAP_DEFAULT);
heap_caps_get_info(&heapInternal,MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
heap_caps_get_info(&heapPSRAM,MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
Serial.printf("\n Allocated Free Largest Low\n");
Serial.printf(" --------- --------- --------- ---------\n");
Serial.printf("Total Heap: %9d %9d %9d %9d\n",heapAll.total_allocated_bytes,heapAll.total_free_bytes,heapAll.largest_free_block,heapAll.minimum_free_bytes);
Serial.printf(" Internal: %9d %9d %9d %9d\n",heapInternal.total_allocated_bytes,heapInternal.total_free_bytes,heapInternal.largest_free_block,heapInternal.minimum_free_bytes);
Serial.printf(" PSRAM: %9d %9d %9d %9d\n\n",heapPSRAM.total_allocated_bytes,heapPSRAM.total_free_bytes,heapPSRAM.largest_free_block,heapPSRAM.minimum_free_bytes);
LOG0("Lowest stack level: %d bytes\n",uxTaskGetStackHighWaterMark(NULL));
nvs_stats_t nvs_stats; nvs_stats_t nvs_stats;
nvs_get_stats(NULL, &nvs_stats); nvs_get_stats(NULL, &nvs_stats);
LOG0("NVS Flash Partition : %7d of %d records used\n\n",nvs_stats.used_entries,nvs_stats.total_entries-126); LOG0("NVS Flash Partition: %d of %d records used\n\n",nvs_stats.used_entries,nvs_stats.total_entries-126);
} }
break; break;

View File

@ -34,7 +34,7 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.setLogLevel(2); homeSpan.setLogLevel(2);
homeSpan.enableWebLog(200); homeSpan.enableWebLog(500);
homeSpan.begin(Category::Lighting,"HomeSpan Max"); homeSpan.begin(Category::Lighting,"HomeSpan Max");