AnsweredAssumed Answered

How to get the unused flash location to use write

Question asked by hobb.epy on May 7, 2018
Latest reply on May 10, 2018 by hobb.epy

Hi ,

I was trying to write array of 10 element in to the flash. But it was writing to used code memory. 

I am using STM32F103C8T6 and keil compiler and code generated by cubemx.

 

Here is my code.

 

uint32_t startAddress = 0x8000002;//starting from 256KB
//0x8020000 starting 128KB

uint8_t aa[12]={"Hello world\0"};
void writeFlash(void)
{
uint32_t j;
HAL_FLASH_Unlock();//unlock flash writing
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_PGERR);
FLASH_PageErase(startAddress);//erase the entire page before you can write as I //mentioned

// for(i=0; i<mSize; i++)
for(j=0; j<12; j++)
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,(startAddress + j*2),aa[j]);

HAL_FLASH_Lock();//lock the flash for writing

}

void readFlash(void)
{
uint32_t j;
// for(i=0; i<mSize; i++)
for(j=0; j<10; j++)
aa[j] = *(uint16_t *)(startAddress + (j*2));
}

 

 

When i am calling write flash function then after code doesn't work and on next power ON initial routines also  not at all working. 

 

How to find flash location which is not being used in the code memory?

 

Outcomes