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

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);

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);

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

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