STM32F103C8T6 내부 FLASH 읽기/쓰기

1845 단어 단편기

u16	people_id[50]={1,2,3} ;                               /*       50  */
u16	people_clock_t[50] ;                         /*         */
u16	people_num = 2;                                         /*    */



#define DEBUG
#define FLASH_SIZE    64          //  MCU FLASH    (   K)
#if FLASH_SIZE<256
  #define SECTOR_SIZE           1024    //  
#else
  #define SECTOR_SIZE           2048    //  
#endif
FLASH_Status  Debug;
//Flash      8 bit     
void FLASH_WriteData(uint32_t startAddress,uint16_t *writeData,uint16_t countToWrite)
{
	uint16_t i;
	uint32_t  offsetAddress;  //    
	uint32_t  sectorPosition; //    
  uint32_t  sectorStartAddress;
 if(startAddress < FLASH_BASE||((startAddress+countToWrite)>=(FLASH_BASE+1024*FLASH_SIZE)))
  {
   return  ;//    
  }
  //     
   FLASH_Unlock();  
   
  //    0X08000000        
   offsetAddress = startAddress-FLASH_BASE;  
  //      
   sectorPosition = offsetAddress/SECTOR_SIZE;   
	//        
   sectorStartAddress=sectorPosition * SECTOR_SIZE + FLASH_BASE; 
	
	 FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

	//      
   Debug=FLASH_ErasePage(sectorStartAddress);
#ifdef DEBUG	
	 if(Debug != FLASH_COMPLETE)
	  printf("      

"); #endif for(i=0;i

main
void main(void)
{
     write_to_flash();
	read_from_flash();
    while(1)
    {

    }
}

좋은 웹페이지 즐겨찾기