/*************************************************************************/ /* */ /* FILE NAME VERSION */ /* */ /* Amd16.c 1.0 */ /* */ /* */ /* */ /* FUNCTIONS : AMD Flash program code */ /* */ /* DEPENDENCIES */ /* */ /* Copyrigth (C) 2010 JNDTECH CO.,LTD */ /*************************************************************************/ #include #include #include "common.h" #include "main.h" #define TOGGLE #define STM32F10x_16 #define PROGRAM_TIMEOUT 100 #define ERASE_SECTOR_TIMEOUT 500 #ifdef STM32F10x_16 #define DEVICE_SIZE 0x4000 // Device Size in Bytes (16kB) #define SECTOR_SIZE 1024 #endif #ifdef STM32F10x_128 #define DEVICE_SIZE 0x20000 // Device Size in Bytes (128kB) #define SECTOR_SIZE 1024 #endif #ifdef STM32F10x_512 #define DEVICE_SIZE 0x80000 // Device Size in Bytes (512kB) #define SECTOR_SIZE 1024 #endif #ifdef STM32F10x_1024 #define DEVICE_SIZE 0x00100000 // Device Size in Bytes (1024kB) #define SECTOR_SIZE 1024 #endif #ifdef STM32F10x_CL #define DEVICE_SIZE 0x40000 // Device Size in Bytes (256kB) #define SECTOR_SIZE 1024 #endif #ifdef FLASH_OPT #define DEVICE_SIZE 0x00010 // Device Size in Bytes (16) #define SECTOR_SIZE 16 #endif // Host program data & command structure extern FLASH_INFO Flash_Info; void Main(void) { Flash_Init(); switch(Flash_Info.Command) { case FPROGRAM: Program(); break; case FERASEALL: EraseAll(); break; case FERASESEC: EraseSector(); break; case FREADID: ReadChipID(); break; default : memset(&Flash_Info,0,sizeof(Flash_Info)); Flash_Info.Result = 0; } dummy(); __NOP(); __NOP(); } /* // Flash program function void Program(void) { ulong i; volatile ushort *targetP; volatile ushort *srcP; targetP = (ushort *)Flash_Info.TargetAddr; srcP = (ushort *)Flash_Info.Buf; for(i=0; iFlash_Info.TargetAddr) break; for(;i= (Flash_Info.TargetAddr+Flash_Info.Length)) break; if(!OneSectorErase(SectorTable[i])) return; } Flash_Info.Result = BlankCheck(Flash_Info.TargetAddr, Flash_Info.Length); } // Sector Erase int OneSectorErase(ulong targetAddr) { volatile ushort *targetP; targetP = (ushort *)targetAddr; if(!Wait((ulong)targetP)) return 0; *targetP = RESET_CMD; return 1; } // Read Manufacturer & Device ID void ReadChipID(void) { ushort manId,devId; manId=*((volatile ushort *)0); manId &= 0xff; devId=*((volatile ushort *)2); devId &= 0xff; Flash_Info.Result = (devId << 8) + manId; } int BlankCheck(ulong targetAddr,ulong targetSize) { ulong i; volatile ulong *targetP = (volatile ulong *)targetAddr; for (i=0; i 0) break; else if((status & POLL_MASK2) > 0) { status = *targetP; if((status & POLL_MASK1) > 0) break; else { *targetP = RESET_CMD; return 0; } } #endif } return 1; } */