Skip to content

Commit 75c6956

Browse files
committed
Fixed spiram memory allocation
1 parent 10e0315 commit 75c6956

File tree

1 file changed

+10
-7
lines changed
  • firmware/components/micropython

1 file changed

+10
-7
lines changed

firmware/components/micropython/main.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
// MicroPython runs as a task under FreeRTOS
7070
#define MP_TASK_PRIORITY (CONFIG_MICROPY_TASK_PRIORITY)
7171
#define MP_TASK_STACK_SIZE (CONFIG_MICROPY_STACK_SIZE * 1024)
72-
72+
#define TAG "MP"
7373
int vprintf_null(const char *format, va_list ap) {
7474
// do nothing: this is used as a log target during raw repl mode
7575
return 0;
@@ -100,26 +100,29 @@ void mp_task(void *pvParameter) {
100100
machine_init();
101101

102102
// TODO: CONFIG_SPIRAM_SUPPORT is for 3.3 compatibility, remove after move to 4.0.
103-
#if CONFIG_ESP32_SPIRAM_SUPPORT || CONFIG_SPIRAM_SUPPORT
103+
#if CONFIG_ESP32_SPIRAM_SUPPORT
104104
// Try to use the entire external SPIRAM directly for the heap
105-
size_t mp_task_heap_size;
106-
void *mp_task_heap = (void *)0x3f800000;
105+
size_t mp_task_heap_size = 0x00;
106+
void *mp_task_heap = (void *)0x00;
107+
ESP_LOGI(TAG, "SPIRAM: %d\n", esp_spiram_get_chip_size());
108+
ESP_LOGI(TAG, "Max free: %d\n", heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM));
107109
switch (esp_spiram_get_chip_size()) {
108110
case ESP_SPIRAM_SIZE_16MBITS:
109111
mp_task_heap_size = 2 * 1024 * 1024;
112+
mp_task_heap = heap_caps_malloc(mp_task_heap_size, MALLOC_CAP_SPIRAM);
110113
break;
111114
case ESP_SPIRAM_SIZE_32MBITS:
112115
case ESP_SPIRAM_SIZE_64MBITS:
113-
mp_task_heap_size = 4 * 1024 * 1024;
116+
mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
114117
mp_task_heap = heap_caps_malloc(mp_task_heap_size, MALLOC_CAP_SPIRAM);
115118
break;
116119
default:
117120
// No SPIRAM, fallback to normal allocation
118121
mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
119122
mp_task_heap = malloc(mp_task_heap_size);
120-
break;
121123
}
122-
124+
ESP_LOGI(TAG, "Heap adress: %p\n", mp_task_heap);
125+
ESP_LOGI(TAG, "Heap size: %d\n", mp_task_heap_size);
123126
#endif
124127

125128
soft_reset:

0 commit comments

Comments
 (0)