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

Bug Report: Writing struct after Flash erase sector not working. #112

Closed
koulombus opened this issue Feb 18, 2018 · 2 comments
Closed

Bug Report: Writing struct after Flash erase sector not working. #112

koulombus opened this issue Feb 18, 2018 · 2 comments
Assignees
Labels
bug Identifies a bug in the current version of the code
Milestone

Comments

@koulombus
Copy link

Hi,

SPIFlash Version: 3.0.1
Arduino IDE: 1.8.5
OS: Mac 10.13.3
Arduino Board: mega2560
Flash: Winbond: W25Q80BV 1MB

Before I write the struct to flash I do a flash.eraseSector() on page 0.
After check page 0 the values are not stored.
When I do the same with chip erase, all is fine. But I do not always want to delete the whole chip.

The struct:

struct CONFIGURATION {
    struct MISC {
        byte tempHigh = 30;            
        byte tempLow = 20;             
        bool parkingMode = false;      
        bool allowDataToBeSent = false;
    } misc;
    struct NETWORK {
        char ssid[50] = "§";           
        char pwd[50] = "§";            
        char userid[50] = "§";         
    } network;
    struct CHARGING_INFO {
        byte interval = 5;             
        byte highChargingDefault = 80; 
    } charging;
} configuration;

Save and read :

void readConfiguration() {
    flash.readAnything(0, configuration);
}

void saveConfiguration() {
    flash.eraseChip();
    // flash.eraseSector(0);
    flash.writeAnything(0, configuration);
}
@thedub2001
Copy link

Hello !
I have the same problem

SPIFlash Version: 3.0.0
Arduino IDE: 1.8.4
OS: Win7
Arduino Board: Atmega328P
Flash: Winbond: W25Q256

The eraseChip function is working while the eraseSector function is not erasing at all
Here is the serial output of the Test flash sketch when I ask to erase the sector at address 0 :

----------------------------------------------------------------------------------------------------------------------------------
                                                       Function 11 : Erase 4KB sector                                               
                                                        SPIFlash library test                                                     
----------------------------------------------------------------------------------------------------------------------------------
This function will erase a 4KB sector.
Please enter the address you wish to erase: 0
A 4KB sector containing address 0 has been erased
Type 1 to read the page you have just modified. Type 0 to continue: 1
Would you like your output in decimal or hexadecimal? Please indicate with '1' for HEX or '2' for DEC: 2
Reading address (0000)
049,075,050,083,110,055,122,119,049,075,050,083,078,075,122,118,
049,075,050,083,068,049,122,118,049,075,050,083,112,056,122,118,
049,075,050,083,056,049,122,118,049,075,050,083,082,105,122,118,
049,075,050,083,103,049,122,118,049,075,050,083,048,108,122,118,
049,075,050,083,071,080,122,118,049,075,050,083,080,065,122,118,
049,075,053,107,074,097,122,255,049,075,055,121,077,079,122,255,
049,075,066,113,057,090,122,255,049,075,069,107,080,099,122,255,
049,075,073,105,116,056,122,255,049,075,075,113,083,049,122,255,
049,075,077,085,100,116,122,255,049,075,077,121,083,048,122,255,
049,075,079,099,108,066,122,255,049,075,082,056,054,119,122,255,
049,075,083,097,108,055,122,255,049,075,085,056,083,120,122,255,
049,075,087,107,090,109,122,255,049,075,089,048,122,055,122,255,
049,075,089,103,072,056,122,255,049,075,098,079,048,048,122,255,
049,075,100,069,113,110,122,255,049,075,101,073,122,089,122,255,
049,075,101,109,077,069,122,255,049,075,103,099,102,108,122,255,
049,075,105,071,113,048,122,255,049,075,107,109,084,120,122,255,

We should only see unwritten bytes with a value of 255 (in decimal output mode)

@Marzogh Marzogh self-assigned this Feb 24, 2018
@Marzogh Marzogh added the bug Identifies a bug in the current version of the code label Feb 24, 2018
@Marzogh Marzogh added this to the v3.1.0 milestone Feb 24, 2018
Marzogh added a commit that referenced this issue Feb 24, 2018
…memory boundary - when rolling over from address '_chip.capacity' to address '0x00' - has been fixed. In previous versions this caused issues with writing complex data structures across the memory boundary and led to many _writeErrorCheck() failures. Fixes issue #112

--> A new function - 'flash.eraseSection(address, size)' - has been intrduced in this version. When a user requires a large and variable (between writes) amount of data to be written to the flash memory on the fly and to have the correct amount of space erased to fit the data, this function will automatically calculate and erase the right amount of space to fit the data. Please note that if the the amount of data being written is consistently the same size, the pre-existing 'flash.eraseSector()', 'flash.eraseBlock32K()' and 'flash.eraseBlock64K()' functions will operate a lot faster.
@Marzogh
Copy link
Owner

Marzogh commented Feb 24, 2018

Hi guys, Thanks for pointing this out. I've fixed it (I think) in the latest code in the development branch. I've tested it using the new version of Struct_writer.ino in the Examples folder. 🙂

My apologies for the delay in getting back to you. I came back from a long bushwalking holiday to the start of semester at the University I work at - having 1200 first years to deal with after a month of the wilderness took a bit of getting back into!

@Marzogh Marzogh closed this as completed Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies a bug in the current version of the code
Projects
None yet
Development

No branches or pull requests

3 participants