cancel
Showing results for 
Search instead for 
Did you mean: 

storing string's on flash

cjaya.2
Associate II

hi,

I initialized string array with strings and type cast to uint32_t to store in flash memory as uint32_t. And then read the array as uint32_t. I update one of the string of the  array and type cast uint32_t to store that array in Flash memory back. But whenever I update string value and store on the flash memory. The string has strange characters on it. If you see the string that I am trying to store in string array "21.76".
string.jpg

But in flash memory showing as "yyyy6.Its not storing properly.If you see the picture below in memory browser its showing as "yyyy6".

memory.jpg

 

 

I dont know why?. Any suggestions.

 

 

 

 

 

19 REPLIES 19

You have an amazing skill of not really showing enough of the code to understand the context properly, and don't review the code you're interfacing with.

Need to pass a count of words

MY_FLASH_ReadN(0, (uint32_t*)CStore, (sizeof(CStore) + sizeof(uint32_t) - 1)/sizeof(uint32_t),DATA_TYPE_32);

 

Is CStore an array of pointer?

You have CStore[Counter] did you mean &CStore[Counter] ??

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@cjaya.2 wrote:

char CStore array contain old string after read from MY_FLASH_ReadN, I just wanted to clear out that string with memset and write the new string to the CStore array. And then store in flash, thats my thinking. 


then must be & here because now your code read first char convert it to address and erase memory 10 bytes from it.

Right is

memset(&CStore[Counter], '\0', 10);

and many next mistakes in your code

Thank you for the reply. CStore is initialized as "static char CStore[4][10]={0}". I made the changes according to you have mentioned on the code. But still I am getting like this, if you check on the memory browser.Is there a possibility, if the string has "-32.445656556789" long ended decimal places when it is doing typecast of uint32_t is messing up storing on flash. 

memory2.jpg

 

 

A two dimensional array ?? None of your other code uses in that form, pretty hard to follow, and lacks comments.

Perhaps add some output, say hex dumping the memory prior to the MY_FLASH_WriteN() so you can be sure what you're attempting to write.

Check that's correct. Show that so we can see what's happening.

And then follow the code flow/execution into MY_FLASH_WriteN()

Debugging is about finding out the point at which desired behaviour stops, and incorrect behaviour starts, and why.

Not really sure why you need to layer in a bunch of third party code when you could use the HAL more directly

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

How can I do hex dumping the memory prior to the MY_Flash_WriteN(). Can you point me how to do that?

I put some breakpoints before the MY_FLASH_WriteN() and I can see according to the address of the CStore. It contains string before writing to the flash. If you see the memory window,CStore.jpg After the MY_FLASH_WriteN() characters are not written properly into the flash memory. If you see the memory window,

memory -3.jpg

I have DMA configured for UART to receive data. Is there possibility that processor gets interrupted while it try to write to Flash. And then it stops writing properly to the flash. But I wait it for flash writing to finish before I receive any data from UART. I wait for 3 seconds. Is 3 seconds enough for flash writing. Any suggestions will be very helpful.     

 

Maybe good is stop testing your code and first test lib. Run only this and check result.

char test[16];
void test(void) {
   MY_FLASH_SetSectorAddrs(6, 0x08040000);
  test[0]='A';
  test[1]='B';
  test[2]='C';
  test[3]='D';
  test[4]=0;
   MY_FLASH_WriteN(0, (void *)test, 1, DATA_TYPE_32);
}

 

I put some breakpoints on the library file (MY_FLASH.c) just before the HAL_FLASH_Lock() on the HAL_FLASH_WriteN. I can see that in sector 0x08040000 characters are not written properly into the flash memory. I dont know whats going on there. Is there possibility that sector is bad or processor gets interrupted during the write operation. Or the flashAddress is not sequencing?

MY_FLASH_WriteN.jpg 

Firstly check is sector erased on line 51?

I put a break point on line 51, I can see the sector is being erased.There is nothing contains after erased. There is another strange factor if I change on DATA_TYPE_8 on MY_FLASH_WriteN it seems to work. It is only byte of data.  On this string contains 5 bytes of data.I dont undestand whats going on there?