1 /****************************************************************************** 2 ****************************************************************************** 3 * 4 * @file flash.h 5 * 6 * @brief application entry point which performs application specific tasks. 7 * 8 ******************************************************************************* 9 * 10 * provide a demo for how to initialize the NV32, output messages via SCI, 11 * flash operations, etc. 12 * NOTE: 13 * printf call may occupy a lot of memory (around 1924 bytes), so please 14 * consider your code size before using printf. 15 ****************************************************************************** 16 * 17 * provide FLASH driver 18 * 19 ******************************************************************************/ 20 21 22 23 #ifndef FLASH_H_ 24 #define FLASH_H_ 25 26 /****************************************************************************** 27 * Includes 28 ******************************************************************************/ 29 #include "common.h" 30 /****************************************************************************** 31 * Constants 32 ******************************************************************************/ 33 34 /****************************************************************************** 35 * Macros 36 ******************************************************************************/ 37 /* Uncomment the following line to support programming flash while running code from flash */ 38 // #define FLASH_ENABLE_STALLING_FLASH_CONTROLLER 39 40 #define ETMRH_FSTAT_MGSTAT0_MASK (1) 41 #define ETMRH_FSTAT_MGSTAT1_MASK (1<<1) 42 43 #define FLASH_SECTOR_SIZE 512 // in bytes 44 45 /* Flash driver errors */ 46 #define FLASH_ERR_BASE 0x3000 47 #define FLASH_ERR_SUCCESS 0 48 #define FLASH_ERR_INVALID_PARAM (FLASH_ERR_BASE+1) // invalid parameter error code 49 #define EEPROM_ERR_SINGLE_BIT_FAULT (FLASH_ERR_BASE+2) // EEPROM single bit fault error code 50 #define EEPROM_ERR_DOUBLE_BIT_FAULT (FLASH_ERR_BASE+4) // EEPROM double bits fault error code 51 #define FLASH_ERR_ACCESS (FLASH_ERR_BASE+8) // flash access error code 52 #define FLASH_ERR_PROTECTION (FLASH_ERR_BASE+0x10) // flash protection error code 53 #define FLASH_ERR_MGSTAT0 (FLASH_ERR_BASE+0x11) // flash verification error code 54 #define FLASH_ERR_MGSTAT1 (FLASH_ERR_BASE+0x12) // flash non-correctable error code 55 #define FLASH_ERR_INIT_CCIF (FLASH_ERR_BASE+0x14) // flash driver init error with CCIF = 1 56 #define FLASH_ERR_INIT_FDIV (FLASH_ERR_BASE+0x18) // flash driver init error with wrong FDIV 57 58 /* Flash and EEPROM commands */ 59 60 61 #define FLASH_CMD_PROGRAM 0x20000000 62 #define FLASH_CMD_CLEAR 0x00005000 63 #define FLASH_CMD_ERASE_ALL 0x41000000 64 #define FLASH_CMD_ERASE_SECTOR 0x40000000 65 #define FLASH_FACTORY_KEY 0x0065fe9a 66 67 #define EFM_DONE_MASK 0x00006000 68 #define EFM_STATUS_DONE 0x00006000 69 #define EFM_STATUS_READY 0x00002000 70 71 #define FLASH_ACCERR_MASK 0x10 72 73 #define M8(adr) (*((volatile unsigned char *) (adr))) 74 #define M16(adr) (*((volatile unsigned short *) (adr))) 75 #define M32(adr) (*((volatile unsigned long *) (adr))) 76 77 78 79 /****************************************************************************** 80 * Types 81 ******************************************************************************/ 82 typedef uint16_t (*TFlash_Fun1)(uint32_t wNVMTargetAddress, uint8_t *pbData, uint8_t bByteCount); 83 typedef uint16_t (*TFlash_Fun2)(uint32_t wNVMTargetAddress, uint32_t dwData0, uint32_t dwData1); 84 typedef uint16_t (*TFlash_Fun3)(uint32_t wNVMTargetAddress, uint32_t dwData); 85 86 /****************************************************************************** 87 * Global variables 88 ******************************************************************************/ 89 90 /****************************************************************************** 91 * Global functions 92 ******************************************************************************/ 93 uint16_t Flash_Program(uint32_t wNVMTargetAddress, uint8_t *pData, uint16_t sizeBytes); 94 uint16_t Flash_Program1LongWord(uint32_t wNVMTargetAddress, uint32_t dwData); 95 uint16_t Flash_Program2LongWords(uint32_t wNVMTargetAddress, uint32_t dwData0, uint32_t dwData1); 96 97 uint16_t Flash_EraseSector(uint32_t wNVMTargetAddress); 98 99 uint16_t Flash_VerifyBackdoorKey(void); 100 101 uint16_t NVM_EraseAll(void); 102 103 uint16_t NVM_Unsecure(void); 104 105 uint16_t Flash_Init(void); 106 107 #ifdef IAR 108 void __ramfunc EFM_LaunchCMD(uint32_t EFM_CMD); 109 #else 110 void EFM_LaunchCMD(uint32_t EFM_CMD); 111 #endif 112 113 114 void Flash_CopyInRAM(void); 115 void Flash_CopyRouinte2RAM(char *func, uint16_t sizeFunc); 116 /********************************************************************/ 117 118 #endif /* FLASH_H_ */ 119