static int hal_readSector(uint32 sec, uint32 *pdata){ uint32 saddr; int i; saddr = (defStartSector+sec)*defSectorSize; for(i=0;i<(defSectorSize/4);i++) { pdata[i] = *((uint32*)saddr); saddr+=4; } return defSectorSize;}static int hal_writeSector(uint32 sec, uint32 *pdata){ FLASH_Status ret; uint32 saddr; int i; saddr = (defStartSector+sec)*defSectorSize; FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR); FLASH_Unlock(); FLASH->ACR&=~(1<<10);//FLASH disable code fetch ret = FLASH_ErasePage(saddr); if(ret==FLASH_COMPLETE) { FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR); for(i=0;i<(defSectorSize/4);i++) { ret = FLASH_ProgramWord(saddr,pdata[i]); if(ret!=FLASH_COMPLETE) break; saddr+=4; } } FLASH->ACR|=1<<10; //FLASH enable code fetch FLASH_Lock(); //??FLASH??????? return defSectorSize;}