STM32H735ZG Flash Memory Operation
I'm developing the STM32H735ZG using IAR EW.
I wanted to design sectors 4-7 of the STM32H735ZG's flash memory as a readable/writable data storage area, so I created it by referring to the reference manual, but I can't read or write data properly.
I modified the .icf file as attached, defining sectors 4-7 (0x08080000-0x080fffff) as the data storage area(named MEMORY block).
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x24000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2404FFFF;
define symbol __ICFEDIT_region_ITCMRAM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ITCMRAM_end__ = 0x0000FFFF;
define symbol __ICFEDIT_region_MEMORY_start__ = 0x08080000;
define symbol __ICFEDIT_region_MEMORY_end__ = 0x080FFFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_heap__ = 0x200;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define region ITCMRAM_region = mem:[from __ICFEDIT_region_ITCMRAM_start__ to __ICFEDIT_region_ITCMRAM_end__];
define region MEMORY_region = mem:[from __ICFEDIT_region_MEMORY_start__ to __ICFEDIT_region_MEMORY_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
define block MEMORY with alignment = 8, size = __ICFEDIT_size_cstack__ { readwrite section .memory_section };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite,
block CSTACK, block HEAP };
place in MEMORY_region { block MEMORY };I also created a .c file to test sector deletion and data writing/reading.
#define MEM_STARTADDR 0x08080000
__attribute__((section(".memory_section")))uint8_t memHead;
bool eraseSectorData(){
bool result;
// delete sector 4~7
FLASH_EraseInitTypeDef erase;
erase.TypeErase = FLASH_TYPEERASE_SECTORS;
erase.Sector = FLASH_SECTOR_4;
erase.NbSectors = 4;
erase.VoltageRange = FLASH_VOLTAGE_RANGE_3;
uint32_t eraseAddress;
// delete
HAL_FLASH_Unlock();
HAL_FLASHEx_Erase(&erase, &eraseAddress);
HAL_FLASH_Lock();
if(eraseAddress == 0xffffffff){
result = TRUE;
}else{
result = FALSE;
}
return result;
}
bool copyTest(){
uint8_t ret;
uint8_t result;
uint8_t test[64];
uint8_t getTest[64];
// make test data
for(int i = 0; i < 64 ;i++){
test[i] = 0x00 + i;
getTest[i] = 0x00;
}
// copy test data
HAL_FLASH_Unlock();
for(uint32_t i = 0; i < 64; i++){
ret = HAL_FLASH_Program(0x00, (uint32_t)(MEM_STARTADDR + i), test[i]);
}
HAL_FLASH_Lock();
memcpy(getTest, (void*)(MEM_STARTADDR), 64);
if(ret == HAL_OK){
result = TRUE;
}else{
result = FALSE;
}
return result;
}Sector deletion (eraseSectorData()) works without any problems, but executing copyTest() immediately afterwards causes a HardFault in memcpy().
After investigating, I found:
- HAL_ERROR continues to be returned by HAL_FLASH_Program(), and checking the memory indicates that data is not being written correctly.
- It appears that the moment memcpy() is entered, address 0xffffffe9 is referenced, causing an "exception flame" and resulting in a HardFault.
To use sectors 4-7 as the data storage area, are there any settings or program issues that need to be changed other than the .icf file?
(Using Google Translate)
