IAP code for Freescale platforms

Dependents:   18_PT1000 RDA5807M-FM-Radio flashaccess TF_conops_BAEFLAGIMAN ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FreescaleIAP.h Source File

FreescaleIAP.h

00001 #ifndef FREESCALEIAP_H
00002 #define FREESCALEIAP_H
00003 
00004 #ifdef TARGET_Freescale
00005 
00006 #include "mbed.h"
00007 
00008 #if defined(TARGET_KLXX)
00009 #define SECTOR_SIZE     1024
00010 #elif defined(TARGET_K20D5M) | (TARGET_K22F) | (TARGET_TEENSY3_1)
00011 #define SECTOR_SIZE     2048
00012 #elif defined(TARGET_K64F)
00013 #define SECTOR_SIZE     4096
00014 #else
00015 #warning FreescaleIAP unknown target, using default 1024B
00016 #define SECTOR_SIZE     1024
00017 #endif
00018 
00019 enum IAPCode {
00020     BoundaryError = -99,    //Commands may not span several sectors
00021     AlignError,             //Data must be aligned on longword (two LSBs zero)
00022     ProtectionError,        //Flash sector is protected
00023     AccessError,            //Something went wrong
00024     CollisionError,         //During writing something tried to flash which was written to
00025     LengthError,            //The length must be multiples of 4
00026     RuntimeError,           
00027     EraseError,             //The flash was not erased before writing to it
00028     Success = 0
00029     };
00030 
00031 /** Erase a flash sector
00032  *
00033  * The size erased depends on the used device
00034  *
00035  * @param address address in the sector which needs to be erased
00036  * @param return Success if no errors were encountered, otherwise one of the error states
00037  */
00038 IAPCode erase_sector(int address);
00039 
00040 /** Program flash
00041  *
00042  * Before programming the used area needs to be erased. The erase state is checked
00043  * before programming, and will return an error if not erased.
00044  *
00045  * @param address starting address where the data needs to be programmed (must be longword alligned: two LSBs must be zero)
00046  * @param data pointer to array with the data to program
00047  * @param length number of bytes to program (must be a multiple of 4. must be a multiple of 8 when K64F)
00048  * @param return Success if no errors were encountered, otherwise one of the error states
00049  */
00050 IAPCode program_flash(int address, char *data, unsigned int length);
00051 
00052 /**
00053  * Returns size of flash memory
00054  * 
00055  * This is the first address which is not flash
00056  *
00057  * @param return length of flash memory in bytes
00058  */
00059 uint32_t flash_size(void);
00060 
00061 #endif
00062 #endif