cancel
Showing results for 
Search instead for 
Did you mean: 

strlen flash writing question.

Study Yahoo
Associate III
Posted on November 20, 2017 at 03:04

In the flash memory as shown in the following code, the str1 and str2 values are divided into 4 bytes

I want to write down. I have an error like the image I captured .;

When I have an event, I write it to Flash and try to read it.

Help me ioi ;;

#define Address ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */

char str1[] = '' 2017-11-09 09:32'';

uint32_t *p1 = (uint32_t *)str1;

char str2[] = ''Errorcode1'';

uint32_t *p2 = (uint32_t *)str2;

uint32_t WordCount1 = (strlen(str1) + 3) / 4; // 32-bit words in string

uint32_t WordCount2 = (strlen(str2) + 3) / 4; // 32-bit words in string

while (WordCount1--)

{

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, *p1++) == HAL_OK)

{

Address = Address + 4;

}

}

while (WordCount2--)

{

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, *p2++) == HAL_OK)

{

Address = Address + 4;

}

}

0690X0000060PFSQA2.png

3 REPLIES 3
Posted on November 20, 2017 at 03:43

Then use sizeof() or compute rather than assign.

ie

uint32_t WordCount1, WordCount2;

WordCount1 = (strlen(str1) + 3) / 4; // 32-bit words in string

WordCount2 = (strlen(str2) + 3) / 4; // 32-bit words in string

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
175900CGIL2
Posted on November 20, 2017 at 06:51

Put it within the same compound statement you have the while() loops sitting in

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