Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menu to choose which part of flash gets erased #4380

Merged
merged 3 commits into from
Feb 20, 2018

Conversation

igrr
Copy link
Member

@igrr igrr commented Feb 17, 2018

While troubleshooting some WiFi connection issues it is often required to erase flash contents, specifically SDK configuration (last 4 sectors of flash).

This PR adds a menu which allows selecting between:

  • normal upload, when only the part of the flash required to upload the sketch is erased
  • above plus SDK settings (last 4 sectors) are also erased
  • the whole flash chip is erased

To support these changes, esptool-ck is updated to 0.4.13.

@igrr
Copy link
Member Author

igrr commented Feb 17, 2018

Currently the new menu item is called "Erase Settings" and the options are "Only Sketch", "SDK Settings", and "All Flash Contents". Suggestions about better naming are very welcome.

Another option to give users a way to erase flash would be to create a plugin, similar to the SPIFFS upload plugin, but that needs some (even if small) effort to install.

One more option is to make the IDE perform flash erase when "Burn Bootloader" menu item is chosen. I thought this way was guaranteed to cause confusion, and went for the option implemented in this PR.

@@ -1109,6 +1123,7 @@ def all_boards ():
print 'menu.DebugLevel=Debug Level'
print 'menu.LwIPVariant=lwIP Variant'
print 'menu.led=Builtin Led'
print 'menu.FlashErase=Erase Settings'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest "Erase Flash" here. "Erase Settings" is a bit confusing.

'flash_erase_menu': collections.OrderedDict([
( '.menu.FlashErase.none', 'Only Sketch' ),
( '.menu.FlashErase.none.upload.erase_cmd', '' ),
( '.menu.FlashErase.sdk', 'SDK Settings' ),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest "Sketch + SDK Settings" here, to reflect reality.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 (or 'Sketch + WiFi settings' ?)

- fix argument parsing for flash erase command (-ce)
- add region erase command (-cz)
@igrr igrr force-pushed the feature/erase_flash_menu branch from 65e5b47 to 788001b Compare February 19, 2018 09:54
@igrr igrr requested a review from devyte February 19, 2018 09:55
@igrr igrr force-pushed the feature/erase_flash_menu branch from 788001b to 2570a7d Compare February 19, 2018 11:08
@igrr
Copy link
Member Author

igrr commented Feb 19, 2018

CI check for boards.txt has successfully triggered here after I forgot to commit my boards.txt changes:
https://travis-ci.org/esp8266/Arduino/jobs/343289885

Also noticed that I was formatting flash_size_bytes as a hex number, but forgot to add leading 0x. Fixed that as well.

@d-a-v
Copy link
Collaborator

d-a-v commented Feb 20, 2018

Here is a sketch to try with OTA.
The check_sdk22() needs to be in the first sketch flashed with sdk-2.2.
It uses EEPROM to check whether the erase operation is needed.

#include <EEPROM.h>
#include <ESP8266WiFi.h>

#define SSID "open"
#define PSK ""

#define EEPROM_SIZE 32          // EEPROM size
#define EEPROM_SDK_OFF 24       // EEPROM offset for sdk checker (size 4)

void check_sdk22 ()
{
  // all Serial.print can be commented out
  
  Serial.print("ESP reporting sdk version: ");
  Serial.println(ESP.getSdkVersion());

  // sketch is 128bytes bigger with PROGMEM, _P, pgm_read_byte
  static const char sdk22 [] = "2.2"; // 4 bytes in ram
  if (strncmp(ESP.getSdkVersion(), sdk22, sizeof(sdk22) - 1) == 0)
  {
    Serial.println("We are in sdk-2.2");

    EEPROM.begin(EEPROM_SIZE);
    char sdkee [sizeof(sdk22)];
    for (size_t i = 0; i < sizeof(sdk22) - 1; i++)
      sdkee[i] = EEPROM[EEPROM_SDK_OFF + i];
    sdkee[sizeof(sdk22) - 1] = 0;

    Serial.print("sdk in user-eeprom: ");
    Serial.println(sdkee);

    if (strncmp(sdkee, sdk22, sizeof(sdk22) - 1) == 0)
    {
      Serial.println("nothing to do");
    }
    else
    {
      for (size_t i = 0; i < sizeof(sdk22); i++)
        EEPROM[EEPROM_SDK_OFF + i] = sdk22[i];
      EEPROM.commit();
      bool done = ESP.eraseConfig();
      Serial.print("WiFi config erased: ");
      Serial.println(done);
      ESP.reset();
    }
  }
}

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  check_sdk22();
  WiFi.mode(WIFI_STA);
  WiFi.begin(SSID, PSK);
}

bool connected = true;

void loop() {
  if (connected ^ (WiFi.status() == WL_CONNECTED))
  {
    connected = !connected;
    Serial.print("Connected: ");
    Serial.println(connected);
  }
}

@igrr igrr merged commit 00c8b63 into master Feb 20, 2018
@igrr igrr deleted the feature/erase_flash_menu branch February 20, 2018 18:51
earlephilhower added a commit to earlephilhower/Arduino that referenced this pull request Jul 1, 2018
Fix a compiler ambiguity introduced with a floating point frequency option
for tone().  Thanks to @Rob58329 for discovering this and proposing the
fix.

Match original analogWrite behavior by going from 0...1023 (PWMRANGE) and
not 0...1024, and also explicitly set the analogWrite pin to an OUTPUT.
Thanks to @JAndrassy for finding this.

Fixes esp8266#4380 discovered by @cranphin where interrupts were disabled on a
stopWaveform().  Remove that completely and bracket the update of non-atomic
fields in the structure with disable/enable IRQs for safety.
devyte pushed a commit that referenced this pull request Jul 2, 2018
* Compatibility and IRQ fixed for waveform/tone/pwm

Fix a compiler ambiguity introduced with a floating point frequency option
for tone().  Thanks to @Rob58329 for discovering this and proposing the
fix.

Match original analogWrite behavior by going from 0...1023 (PWMRANGE) and
not 0...1024, and also explicitly set the analogWrite pin to an OUTPUT.
Thanks to @JAndrassy for finding this.

Fixes #4380 discovered by @cranphin where interrupts were disabled on a
stopWaveform().  Remove that completely and bracket the update of non-atomic
fields in the structure with disable/enable IRQs for safety.

* Fix tone(int,int,int) infinite loop

Explicitly cast the frequency, when passed in as an int, to an
unsigned int.  Verified with snippet:
  tone(D1, (int)1000, 500);
  tone(D1, (unsigned int)1000, 500);
  tone(D1, 1000.0, 500);
  tone(D1, (int)1000);
  tone(D1, (unsigned int)1000);
  tone(D1, 1000.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants