# Writing in flash memory is successful, but after reboot there is nothing

**URL:** <https://forums.digi.com/t/writing-in-flash-memory-is-successful-but-after-reboot-there-is-nothing/3902>\
**Category:** NET+OS\
**Tags:** flash-write\
**Created:** [July 12, 2006, 8:39am UTC](https://forums.digi.com/t/writing-in-flash-memory-is-successful-but-after-reboot-there-is-nothing/3902 "2006-07-12T08:39:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)\
**Post date:** [July 12, 2006, 8:39am UTC](https://forums.digi.com/t/writing-in-flash-memory-is-successful-but-after-reboot-there-is-nothing/3902/1 "2006-07-12T08:39:53Z")

</div>

Hi  
I’m developping with a Digi Connect ME DevKit (Connect ME JTAG).  
I’m trying to write a simple char array into the last sector of flash (NVRAM), after the DevBoardParams. NAFlashWrite(…) returns me 0 (successful) and when I’m reading with NAFlashRead(…) the data is available. But when I reboot the device, the data is no longer there.  
First I thought that the JTAG programmer erases the memory every download but then I flashed it (via FTP) and nothing changed.  
What do I wrong?

In my application I poll for my switches on the GPIOs and depending on them I can read or write…

My simple testapplication:

int success;  
unsigned long sectorNumber, sectorOffset;  
char buffer[20];

…

//Write  
sectorNumber = (NAFlashSectors() - 1); //last sector (34)  
sectorOffset = sizeof (devBoardParamsType); //0x1038  
memset ( (void\*)buffer, 0, sizeof (buffer) );  
strcpy (buffer, “Hello Flash-Test”);  
success = NAFlashWrite (sectorNumber, sectorOffset, (sizeof (buffer) - 1), buffer, ALWAYS\_ERASE);  
printf ("Writing flash-data on sector %d, offset 0x%X : %d (0 = successful, -1 = unknown flash, -3 = write failed, -4 = verify failed)  
", sectorNumber, sectorOffset, success);  
printf ("Data: %s  
", buffer);

…

//Read  
sectorNumber = (NAFlashSectors() - 1); //last sector (34)  
sectorOffset = sizeof (devBoardParamsType); //0x1038  
memset ( (void\*)buffer, 0, sizeof (buffer) );  
success = NAFlashRead (sectorNumber, sectorOffset, (sizeof (buffer) - 1), buffer);  
printf ("Reading flash-data from sector %d, offset 0x%X : %d (0 = successful, -1 = unknown flash, -5 = sectornr invalid, -6 = mem out of bound, -7 = sectoroffset invalid)  
", sectorNumber, sectorOffset, success);  
printf ("Data: %s  
", buffer);

…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)\
**Post date:** [July 12, 2006, 10:23am UTC](https://forums.digi.com/t/writing-in-flash-memory-is-successful-but-after-reboot-there-is-nothing/3902/2 "2006-07-12T10:23:26Z")

</div>

I solved the problem!

int NAFlashWrite(WORD32 sectorNumber, WORD32 sectorOffset, WORD32 bytesToWrite, char \* buffer, char options);

I didn’t read the meaning of the options exactly enough… Every time I wrote in the flash I erased the DevBoardParams! So they were restored on reboot by erasing the hole sector…

Now with the option ERASE\_AS\_NEEDED or DO\_NOT\_ERASE it works!

==\> success = NAFlashWrite (sectorNumber, sectorOffset, (sizeof (buffer) - 1), buffer, ERASE\_AS\_NEEDED);

---

<div class="post-metadata">

**Author:** ![pevandenburie](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@pevandenburie](https://forums.digi.com/u/pevandenburie)\
**Post date:** [September 18, 2006, 10:03am UTC](https://forums.digi.com/t/writing-in-flash-memory-is-successful-but-after-reboot-there-is-nothing/3902/3 "2006-09-18T10:03:16Z")

</div>

Hi,  
I have a similar unsolved problem: I write some data in flash sector #30 or #31 and sometimes (often) the program go to exception handler. More annoying, after reboot the whole NVRAM is erased (including the MAC), even though the NVRAM is stored in sector #34. I used the ALWAYS\_ERASE and ERASE\_AS\_NEEDED, same result:

NAFlashWrite( FLASH\_SECTOR30, 0, sizeof(my\_structure), (char\*)&my\_structure, ERASE\_AS\_NEEDED );

As I have several threads, I tried NAFlashCreateSemaphores() at startup, but it returns me a 0xfffffff6 (NAFLASH\_MEMORY\_OUTOFBOUND).

Thanks for any idea…

Paul

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)\
**Post date:** [September 22, 2006, 12:58pm UTC](https://forums.digi.com/t/writing-in-flash-memory-is-successful-but-after-reboot-there-is-nothing/3902/4 "2006-09-22T12:58:10Z")

</div>

Hi Paul,  
sorry, I have no idea to solve your problem.

I never used other sectors than sector 34. I always write my data in sector 34 after the DevBoardParams.  
First I had the problem I explained above but after setting the correct option I never had problems anymore.

As I remember, NAFlashCreateSemaphores() is called by default while starting the application. When I had the problem I tried this function too but as I remember it returned NAFLASH\_DUPLICATE\_CALL (Flash driver semaphores have already been created.)

Michael
