Home > other >  STM32H743 using 1.3.0 version HAL library function continuous writing flash, write not complete, onl
STM32H743 using 1.3.0 version HAL library function continuous writing flash, write not complete, onl

Time:04-09

HAL STM32H743 using 1.3.0 version library function continuous writing flash, write not complete, only be written three times (every written 32 bytes),
My code is as follows:

/* FLASH unlock * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Status=HAL_FLASH_Unlock ();
If (the status!=HAL_OK)
return -1;

FirstSector=GetSector (FLASH_USER_START_ADDR);
NbOfSectors=GetSector (FLASH_USER_END_ADDR) - FirstSector + 1;
/* erasure of the sector to use * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* build EraseInit structure */
EraseInitStruct. TypeErase=FLASH_TYPEERASE_SECTORS;
EraseInitStruct. VoltageRange=FLASH_VOLTAGE_RANGE_3;
EraseInitStruct. Banks=FLASH_BANK_1;
EraseInitStruct. Sector=FirstSector;
EraseInitStruct. NbSectors=NbOfSectors;
/* start erasing operation */
If (HAL_FLASHEx_Erase (& amp; EraseInitStruct, & amp; SECTORError)!=HAL_OK)
{
/* erasing errors, return */
The return - 2;
}
/* "falsh words (256 bits - 32 bytes)" the size of the write data for the unit * * * * * * * * * * * * */
Address=FLASH_USER_START_ADDR;
While (Address & lt; (FLASH_USER_START_ADDR + 0 x80))
{
If (HAL_FLASH_Program (FLASH_TYPEPROGRAM_FLASHWORD, Address, (uint64_t) (uint32_t) my_DATA)==HAL_OK)
{
Address=Address + 32;
}
The else
{
Address wrong/* to write, print and return */
Printf (" flash write wrong Address 0 X X % \ r \ n ", Address).
The return - 3;
}
}
/* to FLASH locked to prevent content is tampered with */
Status=HAL_FLASH_Lock ();
If (the status!=HAL_OK)
{
The return - 4;
}
/* read out data from FLASH to check * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* MemoryProgramStatus=0: write data right
MemoryProgramStatus!=0: error writing data, its value is the number of errors */
Address=FLASH_USER_START_ADDR;
MemoryProgramStatus=0;
While (Address & lt; (FLASH_USER_START_ADDR + 0 x80))
{
Data32=* (__IO uint32_t *) Address;

If (Data32!=DATA_32)
{
MemoryProgramStatus++;
}
Printf (" Address 0 x x % of the data content is 0 x x % \ r \ n ", the Address, Data32);
Address=Address + 4;
}
Printf (" check error for (/4 bytes) : 0 X % X \ r \ n ", MemoryProgramStatus);
/* data validation is not correct */
If (MemoryProgramStatus)
{
Return to 5;
}
The else active-low data/* right */
{
return 0;
}
Download run printing result is like this:
Stm32h743 internal flash, speaking, reading and writing test
Address 0 x80a0000 data content is 0 x87654321
Address 0 x80a0004 data content is 0 x87654321
Address 0 x80a0008 data content is 0 x87654321
Address 0 x80a000c data content is 0 x87654321
Address 0 x80a0010 data content is 0 x87654321
Address 0 x80a0014 data content is 0 x87654321
Address 0 x80a0018 data content is 0 x87654321
Address 0 x80a001c data content is 0 x87654321
Address 0 x80a0020 data content is 0 x87654321
Address 0 x80a0024 data content is 0 x87654321
Address 0 x80a0028 data content is 0 x87654321
Address 0 x80a002c data content is 0 x87654321
Address 0 x80a0030 data content is 0 x87654321
Address 0 x80a0034 data content is 0 x87654321
Address 0 x80a0038 data content is 0 x87654321
Address 0 x80a003c data content is 0 x87654321
Address 0 x80a0040 data content is 0 x87654321
Address 0 x80a0044 data content is 0 x87654321
Address 0 x80a0048 data content is 0 x87654321
Address 0 x80a004c data content is 0 x87654321
Address 0 x80a0050 data content is 0 x87654321
Address 0 x80a0054 data content is 0 x87654321
Address 0 x80a0058 data content is 0 x87654321
Address 0 x80a005c data content is 0 x87654321
Address 0 x80a0060 data content is 0 XFFFFFFFF
Address 0 x80a0064 data content is 0 XFFFFFFFF
Address 0 x80a0068 data content is 0 XFFFFFFFF
Address 0 x80a006c data content is 0 XFFFFFFFF
Address 0 x80a0070 data content is 0 XFFFFFFFF
Address 0 x80a0074 data content is 0 XFFFFFFFF
Address 0 x80a0078 data content is 0 XFFFFFFFF
Address 0 x80a007c data content is 0 XFFFFFFFF
Check error count (/4 bytes) : 0 by 8

No matter how much is the boundary of the writing, are only written three times, read out is 0 XFFFFFFFF behind, in order to show the print result changes to only write data, such as 0 x80 observation is no problem when in the debug, can write the right address 0 x87654321 behind, what reason be? Please give directions, thank!

CodePudding user response:

The above procedures in the execution cycle when writing is not an error, just read out the data for FFFFFFF behind
  • Related