Announcement

Collapse
No announcement yet.

Write variables to flash

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • oamariei
    replied
    Hey,
    I need help with a little problem:
    I have a string variable like "data1[8]" with values data1[i]=12,23,13,44,0,0,0,9.
    Execution of flash_WriteBlock(data1,5,0) return me true(1) but when i read from flash with "flash_Copy(5,0,sysdata2,8)" the sistem tell me i copyed 8bytes but return me only first 4 values -> sysdata2[i]=12,23,13,44.
    sysdata2[7]=0 instead 9.

    I check flash location with flash_GetByte(5,7) and tell me its 0.

    regards
    Amariei Octavian

    I found. Data are word aligned: variable data[1]=12->[0x0c,0x00] in flash. data[8] take 16bytes in flash.Last value are stored at offset 14 in flash
    Last edited by oamariei; 27th February 2019, 06:54 PM. Reason: Resolved. Ty

    Leave a comment:


  • pauleilio
    replied
    Hello,

    It would only be possible if the code knew that a reset was going to happen eg if the reset was a software generated reset or there was a signal recieved to let the code know a hardware reset was about to happen. It wouldn't be possible to write to flash when there is a hardware reset.

    Best regards

    Paul

    Leave a comment:


  • rafa
    replied
    Hello,

    Thanks for the help pauleilio. Another question related with writing into flash. Is there any way to write to flash just before a reset?
    Best regards

    Leave a comment:


  • pauleilio
    replied
    Hello,

    The write flash limit is many tens of thousands of flash write cycles so you are very unlikely to hit this even with a display power cycled daily. It is good self contained efficient solution.

    I hope this helps

    Best regards

    Paul

    Leave a comment:


  • rafa
    replied
    Hi everyone,

    I am programming an application were the user can preset some values from screen and have them after a power-off. I am using the method you described in this post, i.e. writing in a block to flash when the user want to change the present value and reading them from flash just after start.
    Which are the drawbacks of using flash memory? I guess one must be totally sure to not overwrite the program code itself. What but the number of cycles writing/reading in flash? Is there any limit?
    I need to "stored" just 20 bytes, is there another most efficient way to do it?
    The method is working, I am just curious about if it is the correct one for my application.

    Best regards

    Leave a comment:


  • moormob
    replied
    Hi,
    I'm interested in the example code, but I can only see a blank page.

    Leave a comment:


  • koganei
    replied
    Haha, thanks for correcting the information after so long, Mark! Great support!

    Leave a comment:


  • ESPsupport
    replied
    Correction!

    block and ndt should not be declared the way they are in the original sample, they should indeed be

    Code:
    var block[1024], *hndl, ndt[6] ;
    as these are arrays, not pointers to arrays

    Leave a comment:


  • ESPsupport
    replied
    1. This isn't C, in 4DGL all the * does is to prevent a notice if the variable is indexed. Those two variables aren't indexed so the * is not needed, and is probably misleading (you, for example)
    2. 155, but, of course since the blocks are 2k aligned, it's higher than that
    3. I think you can write to flash that fast, try setting up a timer beforehand and reading it out afterwards to see how fast it is. But even so, it's not a good idea, Flash doesn't have an infinite life expectancy (10,000 cycles according to the datasheet), so try writing to it as infrequently as possible.

    Leave a comment:


  • koganei
    replied
    Thanks Mark!
    I have gotten this to work but have a few questions:
    1. Why are *block[1024] and *ndt[6] declared as pointers? Does it have something to do with the "dest" argument of flash_Copy? From the internal functions PDF: "dest Pointer to the destination. The destination pointer is byte aligned, so a str_Ptr must be raised to get correct address."
    2. The comments say "Must give a flashbyte > 'code size' + 17". Obviously this is only if using bank 0. And I realise you have to write a whole page at once. But just as an example, let's say my code size is 137 bytes, what is the first byte I can freely use in flash? Byte 154 or 155?
    3. What is the average time required for flash_WriteBlock to execute? I ask this because I'm writing to flash inside a pin counter OVFfunction that overflows every falling edge (counter is set to 0xFFFF every time it fires) and the pulses are up to 25Hz. If flash_WriteBlock takes a significant time to execute, I will have to consider writing to flash less often.

    Leave a comment:


  • ESPsupport
    replied
    I've attached a program that uses flash storage in bank 0 as variable storage.

    Note that for a larger program the location in the bank will need to be moved.

    Of course you could also change it to use another bank.
    Attached Files

    Leave a comment:


  • koganei
    started a topic Write variables to flash

    Write variables to flash

    Hi,
    I would like to have some variables that maintain their values through power cycles, I believe to do this I need to write the variables to flash.
    I have had a look at the app notes, but it only gives an example of writing a file from the micro SD to flash.

    How can I achieve this?
Working...
X