B4R Code Snippet ESP8266 Check flash configuration - Memory comparison

SubName: ESP8266 Check flash configuration
Description: This code tests if the selected EEPROM settings in the IDE matches the actual device that is being used.

Newer ESP-01 and ESP-12E/12F devices come with 4Mb of flash, some older ESP-x devices come with 1Mb, ESP-07 devices come with 512K of flash etc. This code allows you to see if you have selected the correct memory size in the IDE for the ESP8266 device you are using.

I have tested the code below with the following ESP8266 devices.
  • ESP-01 (AI-Cloud Inside)
  • ESP-01 (None Branded)
  • ESP-100 (Cloud-Linked)
  • ESP-8266 (AI-Thinker)
  • WeMos D1 Mini (AI-Thinker)
  • NodeMcu (Hysiry)
********************* PROGRAM STARTING ****************
AppStart
Flash real id: 001640E0
Flash real size: 4194304
Flash ide size: 4194304
Flash ide speed: 40000000
Flash ide mode: DIO
Flash chip configuration is correct...
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial

    Private realsize, idesize, fidespeed, frealid  As Long 'ignore
    Private frealsize, fidesize, idemode As Int 'ignore
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Delay(1500)
    Log("AppStart")
   
    RunNative("checkflash", Null)

    Dim RAF As RandomAccessFile
    Dim BC As ByteConverter
    Dim Buffer(4) As Byte

    RAF.Initialize(Buffer, False)
    RAF.WriteULong32(frealid, 0)
   
    Log("Flash real id: ", BC.HexFromBytes(Buffer))
    Log("Flash real size: ", realsize)
    Log("Flash ide size: ", idesize)
    Log("Flash ide speed: ", fidespeed)

    Dim Pretext As String = "Flash ide mode: "
   
    Select Case idemode
        Case 0 : Log(Pretext, "QIO")
        Case 1 : Log(Pretext, "QOUT")
        Case 2 : Log(Pretext, "DIO")
        Case 3 : Log(Pretext, "DOUT")
        Case Else Log(Pretext, "UNKNOWN")
    End Select

    If idesize = realsize Then Log("Flash chip configuration is correct...") Else Log("Flash chip configuration is incorrect...")
End Sub

#if C
//This sketch tests if the EEPROM settings of the IDE match the actual ESP8266 device

void checkflash (B4R::Object* unused)
{
    b4r_main::_realsize = ESP.getFlashChipRealSize();
    b4r_main::_idesize = ESP.getFlashChipSize();
    b4r_main::_fidesize = b4r_main::_idesize;
    b4r_main::_idemode = ESP.getFlashChipMode();
    b4r_main::_frealid = ESP.getFlashChipId();
    b4r_main::_frealsize = b4r_main::_realsize;
    b4r_main::_fidespeed = ESP.getFlashChipSpeed();
}
#End If

Tags: ESP8266, IDE, Configuration, EEPROM, IDE, Compare, Check

Enjoy...
 
Last edited:
Top