.

Dependencies:   mbed EthernetInterface mbed-rtos

Fork of Bootloader_K64F by Erik -

Committer:
Sissors
Date:
Wed Mar 11 21:00:29 2015 +0000
Revision:
1:782a3ddc329e
Child:
2:8c44f28c122c
Basic UART functional + IAP functional

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 1:782a3ddc329e 1 #ifndef FREESCALEIAP_H
Sissors 1:782a3ddc329e 2 #define FREESCALEIAP_H
Sissors 1:782a3ddc329e 3
Sissors 1:782a3ddc329e 4 #include "mbed.h"
Sissors 1:782a3ddc329e 5
Sissors 1:782a3ddc329e 6 #if defined(TARGET_KLXX)
Sissors 1:782a3ddc329e 7 #define SECTOR_SIZE 1024
Sissors 1:782a3ddc329e 8 #elif defined(TARGET_K20D5M) | (TARGET_K22F)
Sissors 1:782a3ddc329e 9 #define SECTOR_SIZE 2048
Sissors 1:782a3ddc329e 10 #elif defined(TARGET_K64F)
Sissors 1:782a3ddc329e 11 #define SECTOR_SIZE 4096
Sissors 1:782a3ddc329e 12 #else
Sissors 1:782a3ddc329e 13 #warning FreescaleIAP unknown target, using default 1024B
Sissors 1:782a3ddc329e 14 #define SECTOR_SIZE 1024
Sissors 1:782a3ddc329e 15 #endif
Sissors 1:782a3ddc329e 16
Sissors 1:782a3ddc329e 17 enum IAPCode {
Sissors 1:782a3ddc329e 18 BoundaryError = -99, //Commands may not span several sectors
Sissors 1:782a3ddc329e 19 AlignError, //Data must be aligned on longword (two LSBs zero)
Sissors 1:782a3ddc329e 20 ProtectionError, //Flash sector is protected
Sissors 1:782a3ddc329e 21 AccessError, //Something went wrong
Sissors 1:782a3ddc329e 22 CollisionError, //During writing something tried to flash which was written to
Sissors 1:782a3ddc329e 23 LengthError, //The length must be multiples of 4
Sissors 1:782a3ddc329e 24 RuntimeError,
Sissors 1:782a3ddc329e 25 EraseError, //The flash was not erased before writing to it
Sissors 1:782a3ddc329e 26 Success = 0
Sissors 1:782a3ddc329e 27 };
Sissors 1:782a3ddc329e 28
Sissors 1:782a3ddc329e 29 /** Erase a flash sector
Sissors 1:782a3ddc329e 30 *
Sissors 1:782a3ddc329e 31 * The size erased depends on the used device
Sissors 1:782a3ddc329e 32 *
Sissors 1:782a3ddc329e 33 * @param address address in the sector which needs to be erased
Sissors 1:782a3ddc329e 34 * @param return Success if no errors were encountered, otherwise one of the error states
Sissors 1:782a3ddc329e 35 */
Sissors 1:782a3ddc329e 36 IAPCode erase_sector(int address);
Sissors 1:782a3ddc329e 37
Sissors 1:782a3ddc329e 38 /** Program flash
Sissors 1:782a3ddc329e 39 *
Sissors 1:782a3ddc329e 40 * Before programming the used area needs to be erased. The erase state is checked
Sissors 1:782a3ddc329e 41 * before programming, and will return an error if not erased.
Sissors 1:782a3ddc329e 42 *
Sissors 1:782a3ddc329e 43 * @param address starting address where the data needs to be programmed (must be longword alligned: two LSBs must be zero)
Sissors 1:782a3ddc329e 44 * @param data pointer to array with the data to program
Sissors 1:782a3ddc329e 45 * @param length number of bytes to program (must be a multiple of 4. must be a multiple of 8 when K64F)
Sissors 1:782a3ddc329e 46 * @param return Success if no errors were encountered, otherwise one of the error states
Sissors 1:782a3ddc329e 47 */
Sissors 1:782a3ddc329e 48 IAPCode program_flash(int address, char *data, unsigned int length);
Sissors 1:782a3ddc329e 49
Sissors 1:782a3ddc329e 50 /**
Sissors 1:782a3ddc329e 51 * Returns size of flash memory
Sissors 1:782a3ddc329e 52 *
Sissors 1:782a3ddc329e 53 * This is the first address which is not flash
Sissors 1:782a3ddc329e 54 *
Sissors 1:782a3ddc329e 55 * @param return length of flash memory in bytes
Sissors 1:782a3ddc329e 56 */
Sissors 1:782a3ddc329e 57 uint32_t flash_size(void);
Sissors 1:782a3ddc329e 58
Sissors 1:782a3ddc329e 59 #endif