Author Topic: EEPROM/Flash  (Read 11789 times)

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: EEPROM/Flash
« Reply #15 on: February 05, 2014, 04:02:53 PM »
I looked into this further, and the flash page erase takes about 21ms. The default advertising interval is 80ms. So every 80ms we have the ble active for a few ms and can't perform any flash writes.

you must use:

while(!RFduinoBLE.radioActive){} //wait until the radio is active, wastes time, but ensures we will get the most usage of non active cpu time
delay(6); // roughly the amount of time, from when the radio notification triggers to when we are inactive
flashPageErase(MY_FLASH_PAGE);

mtnscott

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #16 on: April 07, 2014, 10:07:33 AM »
I have a suggestion about how the FLASH read and write is implemented.

There are two functions for using flash

flashPageErase, and flashWriteBlock.  These both seem to erase and write a 1K block of flash.

If your data you want to write to flash is much less than 1K erasing the entire block everytime seems overkill. 

Would there be any way to impelment a 'flash manager' such that when you write changes to your flash space - say passing a pointer to memory and a size, that the 'flash manager' would just write the new data to the 1K block, incrementing your start location each time and once you have completely used up your 1K, then erase the block and start over?

This would reduce the frequency of flash page erase saving your cycles as well as shorten the time for 'non erase' writes.

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: EEPROM/Flash
« Reply #17 on: April 07, 2014, 05:18:38 PM »
With Flash you must erase the whole page/block, unless its NOR flash.

jfp

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #18 on: April 07, 2014, 11:56:05 PM »
But from the SDK documention:
https://devzone.nordicsemi.com/documentation/nrf51/5.2.0/html/a01022.html

Code: [Select]
void  nrf_nvmc_page_erase (uint32_t address)
  Erase a page in flash. This is required before writing to any address in the page. More...
 
 
void  nrf_nvmc_write_byte (uint32_t address, uint8_t value)
  Write a single byte to flash. More...
 
 
void  nrf_nvmc_write_word (uint32_t address, uint32_t value)
  Write a 32-bit word to flash. More...
 
 
void  nrf_nvmc_write_bytes (uint32_t address, const uint8_t *src, uint32_t num_bytes)
  Write consecutive bytes to flash. More...
 
 
void  nrf_nvmc_write_words (uint32_t address, const uint32_t *src, uint32_t num_words)
  Write consecutive words to flash. More...

So functions seem to exist for writing something smaller than a full 1K block.

JF

Benson

  • RFduino Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #19 on: April 09, 2014, 02:21:58 PM »
I have a noob question related to the Flash memory.
Can I send some strings via BLE and save to the flash memory? Is the stored data persistent when power is off?
Thanks

Benson

  • RFduino Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #20 on: April 09, 2014, 05:37:56 PM »
My question would be how to properly store/read strings in Flash.

struct data_t
{

  String data;

};

struct data_t *flash = (data_t*)ADDRESS_OF_PAGE(MY_FLASH_PAGE);

String stringData="sample data";


void flashSave(String dataValue)
{
  Serial.println("flashSave run");
 
  flashPageErase(MY_FLASH_PAGE);
   
  struct data_t value;
 
  value.data= dataValue;

flashWriteBlock(flash, &value, sizeof(value));
 
}


 flashSave(stringData);


When I output the fash:

  Serial.println("Current Flash Memory");
    Serial.println(flash->data);

I received some random chars..

Thanks


tozymandias

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #21 on: February 10, 2016, 09:38:12 PM »
Hello,

did anyone try this solution on simblee?  the solution below for rfduino does not seem to work on simblee. 


I looked into this further, and the flash page erase takes about 21ms. The default advertising interval is 80ms. So every 80ms we have the ble active for a few ms and can't perform any flash writes.

you must use:

while(!RFduinoBLE.radioActive){} //wait until the radio is active, wastes time, but ensures we will get the most usage of non active cpu time
delay(6); // roughly the amount of time, from when the radio notification triggers to when we are inactive
flashPageErase(MY_FLASH_PAGE);

reddai

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #22 on: April 29, 2016, 02:12:13 PM »
Hi!

This discussion really helped me so I decided to contribute further. The BLE stack seems to be in conflict with the write an erase functions to the flash, and adding the following doesn't seem to help.


  while (RFduinoBLE.radioActive)
  {}

So, what I did is, in my wrapper I added the following, and it works fine for now.

Code: [Select]
//Writes a value to a flash page.
void writeFlashAt(long value_, int flashPage) {
  while (RFduinoBLE.radioActive)
  {}
  RFduinoBLE.end();
  //Wait for the radio to finish its calls.
  Serial.print("Attempting to store ");
  Serial.print(value_);
  Serial.print(" at flash page ");
  Serial.println(flashPage);
  uint32_t *p = ADDRESS_OF_PAGE(flashPage);

  byte rc = flashWrite(p, value_);
  if (rc == 0) {
    Serial.println("Success");
  }
  else if (rc == 1) {
    Serial.println("Error - the flash page is reserved");
  }
  else if (rc == 2) {
    Serial.println("Error - the flash page is used by the sketch");
  }
  Serial.print("The value stored in flash page ");
  Serial.print(flashPage);
  Serial.print(" is ");
  Serial.println(*p, HEX);
  RFduinoBLE.begin();
}


//erases a value at a flash page.
void eraseFlashAt(int flashPage) {
  while (RFduinoBLE.radioActive)
  {}
  RFduinoBLE.end();
  //Wait for the radio to finish its calls.
  Serial.print("Attempting to erase flash page ");
  Serial.println(flashPage);
  byte rc = flashPageErase(flashPage);
  if (rc == 0) {
    Serial.println("Success");
  }
  else if (rc == 1) {
    Serial.println("Error - the flash page is reserved");
  }
  else if (rc == 2) {
    Serial.println("Error - the flash page is used by the sketch");
  }
  //To check if the value at the memory we have allocated has been erased.
  uint32_t *p = ADDRESS_OF_PAGE(flashPage);
  Serial.print("The value stored in flash page ");
  Serial.print(flashPage);
  Serial.print(" is ");
  Serial.println(*p, HEX);
  RFduinoBLE.begin();
}

I am hoping this doesn't effect the BLE functions, as I haven't tested communication yet but it seems to have corrected the flash erase and write functions for now.

Do, let me know if we can write to individual smaller blocks within the page. Even if we can't erase any smaller than 1K should be fine.

Thanks,
« Last Edit: May 16, 2016, 05:37:59 PM by tolson »

wookie1

  • RFduino Jr. Member
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #23 on: April 29, 2016, 06:51:32 PM »
Instead of while (RFduinoBLE.radioActive)  {}, you need while (!RFduinoBLE.radioActive)  {}

Basically I think this burns time until the radio is active, at which time the radio will interrupt your code, and then when the radio is done the next line of your code will start, which will give you the maximum amount of time between advertising events.

tolson

  • Global Moderator
  • *****
  • Posts: 827
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: EEPROM/Flash
« Reply #24 on: April 30, 2016, 11:20:42 PM »
Basically, you can't know how much time is left before the radio is going to take over. So, if it isn't running already, then you should keep testing until you know it is running; then test for it to stop running; then immediately start your critical operation.
Turning the radio off and then back on works too, but I think your smart device forgets it's connection then. A radio pause feature that doesn't loose connection would be nice. That would be ideal. Has anybody played with something like that?

As far as I know you should be able to write to any location you want within a page; once a page is erased. As long as you are writing to a location that you haven't already written too, it should work. I think.

rickpres22

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #25 on: May 16, 2016, 04:22:38 PM »
I can't seem to get the flash page to erase without hanging the Simblee (at the point I call flashPageErase()), unless I use the SimbleeBLE.end() method.  Un-commenting and using the SimbleeBLE.end() method allows me to erase the flash page but terminates my connection to my phone; not good.  Anything I can do to erase/write to the flash without loosing my connection?

Code: [Select]
int eraseFlash(){
  int rc;
  if (SimbleeBLE.radioActive){
    while (SimbleeBLE.radioActive)  {}
  }
  else{
    while (!SimbleeBLE.radioActive)  {}
    while (SimbleeBLE.radioActive)  {}
  }
  delay(6);
  //SimbleeBLE.end();
  rc = flashPageErase(MY_FLASH_PAGE);
  if (rc == 0)
    Serial.println("Success");
  else if (rc == 1)
    Serial.println("Error - the flash page is reserved");
  else if (rc == 2)
    Serial.println("Error - the flash page is used by the sketch");
  return rc;
}

tolson

  • Global Moderator
  • *****
  • Posts: 827
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: EEPROM/Flash
« Reply #26 on: May 16, 2016, 05:35:47 PM »
I wish the Simblee developer would jump in on this. As they are the only ones who knows what they are really doing to the memory map. The rest of us are making educated guesses from experimenting the thing to death in relation to what Nordic says they are doing in their API. The differences are unknown.

ssozonoff

  • RFduino Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #27 on: December 06, 2016, 04:49:57 AM »
So has their really been no word about how to do this properly ??

We too are trying to port code from RFDuino to Simblee and the code which was working fine on the RFDuino is no longer working fine with the Simblee and its clearly related to the Flash operations.

Thanks,
Serge

ssozonoff

  • RFduino Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #28 on: December 07, 2016, 10:31:03 AM »
Seems like flashWriteBlock() works fine on the Simblee without any special requirements.

wdfreemanjr

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: EEPROM/Flash
« Reply #29 on: April 09, 2017, 08:18:12 PM »
Arggggg...

Just picked up a few Simblees and need to store a few bytes in flash.  FlashWriteBlock works just fine, but when you disconnect and then reconnect, the iOS application crashes.  Apparently this has been an issue for quite some time.

 I love the fact the chip can render it's own GI and the tiny footprint, but if I have to add an SD card reader or EEPROM, that pretty much throws the tiny footprint out the window.

I could write my own iOS app and use other libraries besides the SimbleeForMobile, but at that point, I might as well just use any bluetooth module.  The GUI rendering was what sold me on this and I see very little progress in upgrades or fixes.

I have not been very impressed with the documentation or the developers responses or lack there of.

 

anything