Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By draco
#14650 That's the same module I have. :) Well, I have an ESP-03 with 512kB and an ESP-12 with 4MB. The ESP-03's chips are exposed, so I was able to just read the chip ID (W25Q40BV) and verify it, but the ESP-12 has the metal RF shield on top, which is what prompted me to look for a software way to determine the size. I want to figure out a suitable way to utilize that extra 3.5MB of flash.
User avatar
By draco
#14825
Code: Select all// we need to include these to be able to use the spi_flash_get_id() function
extern "C" {
#include "c_types.h"
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "spi_flash.h"
}

size_t fs_size() { // returns the flash chip's size, in BYTES
  uint32_t id = spi_flash_get_id(); 
  uint8_t mfgr_id = id & 0xff;
  uint8_t type_id = (id >> 8) & 0xff; // not relevant for size calculation
  uint8_t size_id = (id >> 16) & 0xff; // lucky for us, WinBond ID's their chips as a form that lets us calculate the size
  if(mfgr_id != 0xEF) // 0xEF is WinBond; that's all we care about (for now)
    return 0;
  return 1 << size_id;
}


On my ESP-12, this returns 4194304 bytes, which is 4 megabytes.
User avatar
By dkdileep
#21852 EspressIf flash download tool v1.2 shows the installed flash size. I guess it uses the same logic as yours. Connect the board to USB, set to flash mode and the program detects the chip, flash size and clock speed.
User avatar
By jjorsett
#29815 In a NodeMCU unit, if you have a terminal session running you can manually get the flash size with the following:

> majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();
> print(flashsize)
4096 -- This is what my Adafruit Huzzah running NodeMCU 0.9.5 returned