m-mcgowan / spark-flashee-eeprom

Eeprom emulation using external flash on Particle devices. Includes unit tests cross compiled to regular gcc, and on-device integration tests.
GNU Affero General Public License v3.0
34 stars 8 forks source link

Flash write duration #20

Closed aaraujo11 closed 8 years ago

aaraujo11 commented 8 years ago

Hi @m-mcgowan ,

I'm experiencing some unstable timings while writing to the flash circular buffer. A writing usually lasts 732us, however from time to time it takes 15390us. Any clue on what the problem may be?

To emulate my issue, i had tested with this simple code below and the result is the same.

Thanks in advance!

void loop() {

       buff_test = Flashee::Devices::createCircularBuffer(4096*1, 4096*384);

        while(1){
            delay(512);
            byte tab[76];
            for(int i=0; i<76;i++){
                tab[i]=(byte)i;
            }
            int cnt=micros();
            buff_test->write(tab, 76);
            int cntF=micros()-cnt;
            Serial.print(cntF);
        }
}
aaraujo11 commented 8 years ago

After some debug, the main reason for this time consumption (15390us), it occurs in write_impl() function when the offset reaches zero and run the flash.erasePage(). The erasePage routine is the reason for those timings. Is possible to decrease the time of the erasepage?

m-mcgowan commented 8 years ago

Not to my knowledge - that's how long the hardware takes to erase the page.

There's no way to make the timing even on each write since different writes have different affects on the underlying hardware. If you need to isolate your code form timing variances then you can use multithreading, using a background thread to write to the circular buffer, which itself is fed from an in-memory buffer.

aaraujo11 commented 8 years ago

Hi @m-mcgowan, i deal with it by fed the memory buffer, when my routine had a free open time window, instead do it during my "real time" routine. Thanks