File tree Expand file tree Collapse file tree
ports/espressif/supervisor Expand file tree Collapse file tree Original file line number Diff line number Diff line change 107107#include "esp_log.h"
108108#define TAG "port"
109109
110- uint32_t * heap ;
111- uint32_t heap_size ;
112-
113110STATIC esp_timer_handle_t _tick_timer ;
114111STATIC esp_timer_handle_t _sleep_timer ;
115112
@@ -255,9 +252,6 @@ safe_mode_t port_init(void) {
255252 esp_rom_install_uart_printf ();
256253 #endif
257254
258- heap = NULL ;
259- heap_size = 0 ;
260-
261255 #define pin_GPIOn (n ) pin_GPIO##n
262256 #define pin_GPIOn_EXPAND (x ) pin_GPIOn(x)
263257
@@ -329,7 +323,16 @@ void *port_malloc(size_t size, bool dma_capable) {
329323 if (dma_capable ) {
330324 caps |= MALLOC_CAP_DMA ;
331325 }
332- return heap_caps_malloc (size , caps );
326+
327+ void * ptr = NULL ;
328+ // Try SPIRAM first when available.
329+ #ifdef CONFIG_SPIRAM
330+ ptr = heap_caps_malloc (size , caps | MALLOC_CAP_SPIRAM );
331+ #endif
332+ if (ptr == NULL ) {
333+ ptr = heap_caps_malloc (size , caps );
334+ }
335+ return ptr ;
333336}
334337
335338void port_free (void * ptr ) {
@@ -341,7 +344,7 @@ void *port_realloc(void *ptr, size_t size) {
341344}
342345
343346size_t port_heap_get_largest_free_size (void ) {
344- size_t free_size = heap_caps_get_largest_free_block (0 );
347+ size_t free_size = heap_caps_get_largest_free_block (MALLOC_CAP_8BIT );
345348 return free_size ;
346349}
347350
You can’t perform that action at this time.
0 commit comments