cancel
Showing results for 
Search instead for 
Did you mean: 

write to flash mem stm32f429

TARHAN SAMAH
Senior
Posted on April 19, 2018 at 11:11

hello evrybody, i can write to stm32f103c8/cb with no prblms using hal functions ,

but now i need to write to stm32f429ZI nucleo cart , but no success some times i can what i wrote by coinsidence but this is very strange i dont know where is the prblm in reading or writing here is the code :

i need to write one byte so there is two ways using one byte function or half word function just for lower byte :

1-way onebyte way : i cannot write using this function

uint8_t  GDT_NUM_CHAR=8;

uint32_t gdt_data_adress=0x081E0000;//LAST sector for STM32429ZI sector 23

uint32_t SectorError;

static FLASH_EraseInitTypeDef EraseInit;

HAL_FLASH_Unlock();

EraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;

EraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInit.Sector =gdt_data_adress;//FLASH_SECTOR_23

EraseInit.NbSectors = 1;

if(HAL_FLASHEx_Erase(&EraseInit,&SectorError)==HAL_OK)//we have to erase memory needed space it is a physical issue of eeproms before any writing of data

{

printf('erase suceed');

HAL_Delay(400);

}

FLASH_Program_Byte(gdt_data_adress,GDT_NUM_CHAR);

  HAL_FLASH_Lock();

----->warning:  #223-D: function 'FLASH_Program_Byte' declared implicitly

---> L6218E: Undefined symbol FLASH_Program_Byte (referred from keypad.o).

2-way halfword way

uint8_t  GDT_NUM_CHAR=8;

uint16_t  gdt_num=0x0008;

uint32_t gdt_data_adress=0x081E0000;//LAST sector for STM32429ZI sector 23

uint32_t SectorError;

static FLASH_EraseInitTypeDef EraseInit;

HAL_FLASH_Unlock();

EraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;

EraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInit.Sector =gdt_data_adress;//FLASH_SECTOR_23

EraseInit.NbSectors = 1;

if(HAL_FLASHEx_Erase(&EraseInit,&SectorError)==HAL_OK)//we have to erase memory needed space it is a physical issue of eeproms before any writing of data

{

printf('erase suceed');

HAL_Delay(400);

}

if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,gdt_data_adress,gdt_num)==HAL_OK)//save GDT num to data adress

 {

printf('write suceed');

HAL_Delay(400);

 }

  HAL_FLASH_Lock();

i dont read same value what i wrote to flash ????where is my mistake is it about about adress , i select the last sector to avoid interfering with prgm ,help needed thanks 

5 REPLIES 5
TARHAN SAMAH
Senior
Posted on April 19, 2018 at 15:43

i tried also this 

HAL_FLASH_Unlock();

/* Fill EraseInit structure*/

EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;

EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInitStruct.Sector = 0x081E0000;

EraseInitStruct.NbSectors = 1;

HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);

HAL_Delay(400);

GDT_NUM_CHAR=49;

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, 0x081E0000,GDT_NUM_CHAR);

/* Lock the Flash to disable the flash control register access (recommended

to protect the FLASH memory against possible unwanted operation) *********/

HAL_FLASH_Lock();

if(gdt_num==0)//at the restart

{

//gdt_num=Read_Flash(0x081E0000);//extract gdt num saved in flash memory -

GDT_NUM_CHAR = *(volatile uint8_t *)0x081E0000;

printf('\n\r gdntnumfrom flash=%d-', GDT_NUM_CHAR);

}

i have smthg else what i wrote ??? i tried also sector 0x080E0000   sector 11 same result ??? 

how can i know the sectors not fulled by the prgm or ram data ? i dont want to damage my prgm ,,i mean where is my last adress used by prgm+data to know free sectors

Posted on April 19, 2018 at 16:10

i understand the prblm but i dont have the solution , it looks i cannot errase the sectors if i select any i,t doesnt matter thats why i got wrong result when reading , how i understood it when i erase all the chip the first daa i succeed to write and read it i mean i got a right result if i write 100 i got 100 az a byte , then  after that if i write another value i got a damaged byte i mean different ,, 

im sure i cannot erase well my sector or there is an option bloking my erasing ,, plz can you advice me ?

Posted on April 20, 2018 at 10:27

 tell me is this config correct for read and write between sector 0-------->23 stm32f429

0690X0000060AgaQAE.png0690X0000060AgkQAE.png0690X0000060AgpQAE.png
Posted on April 20, 2018 at 10:59

does NUCLEo 429 doesnt let any flash writing ??? because it is connected to the small chip stm32f103 to be progammed without stlink???

Posted on April 20, 2018 at 13:13

i solved the prblm my mistake was 

/* Unlock the Flash to enable the flash control register access *************/

HAL_FLASH_Unlock();

/* Fill EraseInit structure*/

EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;

EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInitStruct.Sector = FLASH_SECTOR_23;//0x081E0000;----->here write sector not adress 

EraseInitStruct.NbSectors = 1;

//you need to erase entire sector before write anything

HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);

GDT_NUM_CHAR=207;

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE,0x081E0000,GDT_NUM_CHAR);---->here write address not sector 

HAL_FLASH_Lock();

gdt_num=0;

if(gdt_num==0)//at the restart

{

GDT_NUM_CHAR = *(volatile uint8_t *)0x081E0000;//----->extract the data from flash here also write adress not sector 

printf('\n\r gdntnumfrom flash=%d-', GDT_NUM_CHAR);

}

now its perfectly writing thanks to my self