2024-04-12 12:56 PM - edited 2024-04-12 12:57 PM
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".
But in flash memory showing as "yyyy6.Its not storing properly.If you see the picture below in memory browser its showing as "yyyy6".
I dont know why?. Any suggestions.
2024-04-12 01:18 PM
Suppose someone asks you this question. What would you say? Do you have enough information to help him?
2024-04-12 02:20 PM
>>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.
2024-04-12 11:46 PM - edited 2024-04-13 12:10 AM
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);
}
2024-04-12 11:53 PM
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
2024-04-14 04:24 AM
Thank you for the reply. For the next write I am doing erase before.
2024-04-14 06:16 AM
Aghh seems with you can only communicat ChatGPT. Show code
MY_FLASH_WriteN
or better complete relevant code.
2024-04-14 09:29 AM
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
2024-04-14 09:47 AM
Declarations ptr CStore ???
memset(CStore[Counter], '\0', 10);
is absurd if CStore is char array etc.
2024-04-14 10:28 AM
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.