#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#if CONFIG_SPIRAM
#include "esp_psram.h"
#endif
static const char *TAG = "MAIN";
int spi_flash_size() {
uint32_t
chip_id;
ESP_ERROR_CHECK(esp_flash_read_id(NULL, &chip_id));
ESP_LOGI(TAG,
"chip ID=0x%"PRIx32, chip_id);
int
flash_capacity = chip_id & 0xff;
ESP_LOGI(TAG,
"flash_capacity=0x%x", flash_capacity);
int
real_flash_size = 0;
if
(flash_capacity == 0x15) {
real_flash_size = 2;
} else if
(flash_capacity == 0x16) {
real_flash_size = 4;
} else if
(flash_capacity == 0x17) {
real_flash_size = 8;
} else if
(flash_capacity == 0x18) {
real_flash_size = 16;
}
ESP_LOGD(TAG,
"real_flash_siz=%d", real_flash_size);
return
real_flash_size;
}
void app_main()
{
esp_chip_info_t
chip_info;
esp_chip_info(&chip_info);
// Print out
embedded or external
uint32_t
embedded = chip_info.features &
CHIP_FEATURE_EMB_FLASH;
ESP_LOGI(TAG,
"embedded=%"PRIx32, embedded);
if (embedded) {
ESP_LOGI(TAG, "embedded flash");
uint32_t flash_size;
ESP_ERROR_CHECK(esp_flash_get_size(NULL,
&flash_size));
size_t flash_size_k = flash_size / 1024;
size_t flash_size_m = flash_size_k / 1024;
ESP_LOGI(TAG, "embedded %d MBytes flash", flash_size_m);
} else {
ESP_LOGI(TAG, "external flash");
int flash_size = spi_flash_size();
ESP_LOGI(TAG, "external %d Mbytes flash", flash_size);
}
#if CONFIG_SPIRAM
size_t
psram_size = esp_psram_get_size();
size_t
psram_size_k = psram_size/1024;
size_t
psram_size_m = psram_size_k/1024;
ESP_LOGI(TAG,
"PSRAM size: %d bytes %d Mbytes", psram_size,
psram_size_m);
#endif
ESP_LOGI(TAG,
"MALLOC_CAP_INTERNAL: %d bytes",
heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
ESP_LOGI(TAG,
"MALLOC_CAP_SPIRAM: %d bytes",
heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
ESP_LOGI(TAG,
"Free heap size: %"PRIu32" bytes",
esp_get_free_heap_size());
ESP_LOGI(TAG,
"Free heap size: %"PRIu32" K bytes",
esp_get_free_heap_size()/1024);
//ESP_LOGI(TAG,
"Free heap size (caps): %u",
heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
|