#include <stdio.h>
#include <string.h>
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define CONFIG_LOG_MAXIMUM_LEVEL 5
const static char *TAG = "Memory";
void app_main()
{
esp_log_level_set(TAG, ESP_LOG_VERBOSE);
int total_ram = heap_caps_get_free_size(MALLOC_CAP_8BIT);
int IRam = heap_caps_get_free_size(MALLOC_CAP_32BIT) - heap_caps_get_free_size(MALLOC_CAP_8BIT);
int stack = uxTaskGetStackHighWaterMark(NULL);
int internal_memory = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
int external_memory = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
int free = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
ESP_LOGW(TAG, "Free heap size: %lu KiB", esp_get_free_heap_size() / 1024);
ESP_LOGW(TAG, "Free heap size (caps): %d KiB", total_ram / 1024);
ESP_LOGW(TAG, "iram: %d KiB", IRam / 1024);
ESP_LOGW(TAG, "stack: %d KiB", stack / 1024);
ESP_LOGW(TAG, "internal: %d KiB", internal_memory / 1024);
ESP_LOGW(TAG, "external: %d KiB", external_memory / 1024);
ESP_LOGW(TAG, "free: %d KiB", free / 1024);
int stackmem = uxTaskGetStackHighWaterMark(NULL);
ESP_LOGW(TAG, "stack space: %d", stackmem);
void *memoryPointer = malloc(free);
if (memoryPointer == NULL)
{
ESP_LOGW(TAG, "Failed to allocate memory");
}
else
{
ESP_LOGW(TAG, "Allocated memory");
}
}