Can't know the size of the off-chip SPI flash of ESP32

I have a 30-pin ESP32 Board of Espressif Systems. I am aware that the 32-bit LX6 Processor of the board does not have on-chip flash memory. The Espressif Systems has added an off-chip SPI-port based flash memory as per following connection diagram (Fig-1).

The type of the chip indicates its size as 4-MByte which I want to verify running the following sketch picked up from web; however, it does not get compiled due to missing of ESP.h and SPIFFS.h files.

I have searched the web for these files without luck. Would appreciate your help in getting these header files or a working sketch.
esp32offchipflash
Figure-1:

Non-functional Test Sketch (copy paste from web):

#include <ESP.h>
#include <SPIFFS.h>

void setup() {
  Serial.begin(9600);
  delay(1000);
  
  // Initialize the SPIFFS file system
  if (!SPIFFS.begin(true)) {
    Serial.println("Initialization failed!");
    return;
  }
  
  // size of the compiled program
  uint32_t program_size = ESP.getSketchSize();
  
  // size of the file system
  FSInfo fs_info;
  SPIFFS.info(fs_info);
  uint32_t file_system_size = fs_info.totalBytes;
  
  // used size of the file system
  uint32_t file_system_used = fs_info.usedBytes;
  
  // free size in the flash memory
  uint32_t free_size = ESP.getFlashChipSize() - program_size - file_system_size + file_system_used;
  
  Serial.print("Program size: ");
  Serial.print(program_size);
  Serial.println(" bytes");
  
  Serial.print("File system size: ");
  Serial.print(file_system_size);
  Serial.println(" bytes");
  
  Serial.print("File system used: ");
  Serial.print(file_system_used);
  Serial.println(" bytes");
  
  Serial.print("Free space: ");
  Serial.print(free_size);
  Serial.println(" bytes");
}

void loop() {
  // Do Nothing Here
}

Seems you don't have installed the ESP32 support.

I have already installed the ESP32 support, and I can see the following board (s) by clicking on the Tools of the Tools Bar:

ESP32 Arduino

There is an example in the IDE named SPIFFS_test which has included FS.h and SPIFFS.h files and the sketch gets uploaded (though at this moment I don't know what this sketch is doing!)

I use

I am trying to install esp32 using Library Manager of IDE 1.8.19; but, it is not appearing! Which version of IDE you are using?

You have to use the board manager, not the library manager.

The screenshot was from 1.8.13.

Did you even bother to look at the provided link?

You do not install board files using the Library Manager

If you have added the required URL to the "Additional boards" field in Preferences then use the Board Manager to install the board

I have just now followed the link. The esp26 board was already installed and yet I have updated it via Board Manager. The sketch of post #1 is still not compiled. The error message is posted below:

Arduino: 1.8.19 (Windows 10), Board: "ESP32 Dev Module, Disabled, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled"

D:\ArduinoESP32\FlashMemorySizeOffChipESP32\FlashMemorySizeOffChipESP32.ino: In function 'void setup()':

FlashMemorySizeOffChipESP32:18:3: error: 'FSInfo' was not declared in this scope

FSInfo fs_info;

^~~~~~

FlashMemorySizeOffChipESP32:19:10: error: 'class fs::SPIFFSFS' has no member named 'info'

SPIFFS.info(fs_info);

      ^~~~

FlashMemorySizeOffChipESP32:19:15: error: 'fs_info' was not declared in this scope

SPIFFS.info(fs_info);

           ^~~~~~~

D:\ArduinoESP32\FlashMemorySizeOffChipESP32\FlashMemorySizeOffChipESP32.ino:19:15: note: suggested alternative: 'isinff'

SPIFFS.info(fs_info);

           ^~~~~~~

           isinff

exit status 1

'FSInfo' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

What is the difference between Board File and Library File?

From where can I get ESP.h and SPIFFS.h Library files in order to get my sketch of post #1 compiled? Should I be able to include these two files in my IDE using Library Manager or these are automatically included when the esp32 Board is installed?

Board files contain the definitions for boards such as the mapping between the pins on the chip and the pins on the board and other board specific parameters

Library files contain code that can be called by your sketches

Note that some libraries may be specific to particular boards and a number of them will be installed when you install a board

Installation of a board using IDE 1.x is a 2 stage process

First put the required URL in the Additional Boards field of Preferences so that the IDE knows where to find the board file. Then use the Board Manager to actually install the board files and make the board definition available to the IDE

1 Like

There is only one Compiler package in the IDE and is dealing with different boards (UNO, ESP32 for example) which contain processors of differing instruction sets. However, the high level code like digitalWrite() is the same for both boards.

The Compiler chooses the right instruction set for the right processor; as a result, the high level codes are correctly transformed into corresponding executable binary codes.

My question is: where does this mapping table (high level code vs processor-specific binary codes) reside -- within the Compiler or the Board File?

What is an esp26? A mixture from esp8266 and esp32?

1 Like

Definitely not. Each board package usually has its own compiler. E.g. on windows the ESP32 compiler resides in C:\Users\username\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc. The board package contains much more than mappings and parameters. There is a lot of software in it - board specific versions of the standard libraries, core specific software and tools to get it running.

2 Likes

I have travelled across the above tree and have visited all the folders/files.

There are so much code lines and text lines -- have they all been created by human being or some kind of assistances are taken from machines?

When IDE is called upon, then all the executable files are loaded into memory or they remain in the secondary storage device and called upon when needed in response to the click on the Verify/Compile button?

Drawing kind attention of the veteran Forum members to my issue posted in this thread -- is there a way to make the following API-based code to work to know the off-chip flash size of ESP32? You may suggest any other possible ways.

uint32_t program_size = esp_flash_get_chip_size();

Hello!

I asked chatGPT for help and it has supplied me some trustworthy codes which I have tailored as follows to get the size of the off-chip flash memory of ESP32. The sketch has worked and reported the flash size as 4 MB.

Thanks to all who have participated with me in my journey of learning the architecture and programming of "32-bit LX6 Microcontroller using ESP32 Dev Kit".

#include "esp_system.h"
#include "esp_spi_flash.h"

void setup()
{
  Serial.begin(9600);
  while(!Serial)
  {
    ;
  }
  Serial.println();
  esp_chip_info_t chip_info;
  esp_chip_info(&chip_info);

  uint32_t flashSize = spi_flash_get_chip_size();

  Serial.print("Off-chip Flash Memory Size: ");
  Serial.print(flashSize/(1024*1024)); Serial.println(" MB");
}

void loop() {}

Output:

Off-chip Flash Memory Size: 4 MB

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.