-->
Page 2 of 6

Re: determine flash size

PostPosted: Wed Apr 15, 2015 3:59 pm
by draco
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.

Re: determine flash size

PostPosted: Fri Apr 17, 2015 9:50 am
by draco
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.

Re: determine flash size

PostPosted: Sat Jun 27, 2015 3:35 am
by dkdileep
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.

Re: determine flash size

PostPosted: Thu Sep 24, 2015 4:58 pm
by jjorsett
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