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
Pavel A.
Evangelist III

Suppose someone asks you this question. What would you say? Do you have enough information to help him? 

>>Any suggestions.

Doing it wrong, show code, use the </> code pasting tools if you in-line in post, or link to github project illustrating.

Show enough to be coherent, not selective snippets.

Looks like you're not writing the first word.

 

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

Here is the code.

 

if(strncmp((char*)ptr, "tempc", 5) == 0)
   {
   MY_FLASH_SetSectorAddrs(6, 0x08040000);
   if (strncmp((char*)ptr, "tempc1", 6) == 0)
       {
        Counter = 0;
       }

    MY_FLASH_ReadN(0, (uint32_t*)CStore, sizeof(Ctore),DATA_TYPE_32);
    HAL_Delay(100);
    memset(CStore[Counter], '\0', 10);

     for(char *str =strtok((char*)ptr, " "); str; str = strtok(NULL, " "))
	 {
	 if(strncmp((char*)str, "tempc", 5) == 0)
	   continue;

	 strncpy(CStore[Counter], str, strlen(str));  
	 Counter++;
	 }

     MY_FLASH_WriteN(0, (uint32_t*)CStore, sizeof(CStore), DATA_TYPE_32);
     HAL_Delay(100);
   }

 

Flash possition can be writed only once. For next write require erase before. And your code is chaos of pointers.

Read and apply EEPROM emulation code for STM. an4894-how-to-use-eeprom-emulation-on-stm32-mcus-stmicroelectronics.pdf

Thank you for the reply. For the next write I am doing erase before.

Aghh seems with you can only communicat ChatGPT. Show code 

MY_FLASH_WriteN

or better complete relevant code. 

Sure no problem. MY_FLASH_WriteN comes from this. I am using header files on my code.

https://github.com/MYaqoobEmbedded/STM32-Tutorials/blob/master/Tutorial%2030%20-%20FLASH%20Memory/MY_FLASH.c 

Declarations ptr CStore ???

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

is absurd if CStore is char array etc.

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.