#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_log.h"
static const char *TAG = "MAIN";
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_LOGD(TAG,
"embedded=%"PRIx32, embedded);
if (embedded) {
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 {
uint32_t id;
ESP_ERROR_CHECK(esp_flash_read_id(NULL, &id));
ESP_LOGI(TAG, "chip ID=0x%"PRIx32, id);
int flash_capacity = id & 0xff;
ESP_LOGI(TAG, "flash_capacity=0x%d", 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_LOGI(TAG, "external %d Mbytes flash",
real_flash_size);
uint32_t flash_size;
ESP_ERROR_CHECK(esp_flash_get_size(NULL,
&flash_size));
ESP_LOGI(TAG, "esp_flash_get_size=%"PRIi32, flash_size);
}
}
|