Hello friends. How to write a number to and read from internal flash. My information about the microcontroller is very weak. I use STM32F103RET6 . I test The following program but it did not work.
int u2; uint32_t address = 0x8020000; /** writeFlash / HAL_FLASH_Unlock(); FLASH_PageErase(address); HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD ,address ,u2); HAL_FLASH_Lock(); / readFlash **/ u2= (uint32_t )(address); read from Flash **/
I found following program but my compiler (keil) shows Syntax error when insert : (FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR)
uint32_t startAddress = 0x8000000;//starting from 256KB //0x8020000 starting 128KB void writeFlash(void) { u32 i, j; FLASH_Unlock();//unlock flash writing FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR); FLASH_ErasePage(0x8000000); for(i=0; i<16; i++) for(j=0; j<16; j++) FLASH_ProgramHalfWord((0x8000000 + (i*16+j)*2),16[i][j]); FLASH_Lock();//lock the flash for writing } void readFlash(void) { u32 i, j; for(i=0; i<16; i++) for(j=0; j<16; j++) 16[i][j] = *(uint16_t )(0x8000000 + (i16+j)*2); } Please help me. I need a simple example. I'm sorry that your time with my terrible English.