Mirror with some correction
Dependencies: mbed FastIO FastPWM USBDevice
FreescaleIAP/FreescaleIAP.h@116:7a67265d7c19, 2021-10-01 (annotated)
- Committer:
- arnoz
- Date:
- Fri Oct 01 08:19:46 2021 +0000
- Revision:
- 116:7a67265d7c19
- Parent:
- 79:682ae3171a08
- Correct information regarding your last merge
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjr | 2:c174f9ee414a | 1 | /* |
mjr | 2:c174f9ee414a | 2 | * Freescale FTFA Flash Memory programmer |
mjr | 2:c174f9ee414a | 3 | * |
mjr | 2:c174f9ee414a | 4 | * Sample usage: |
mjr | 2:c174f9ee414a | 5 | |
mjr | 2:c174f9ee414a | 6 | #include "mbed.h" |
mjr | 2:c174f9ee414a | 7 | #include "FreescaleIAP.h" |
mjr | 2:c174f9ee414a | 8 | |
mjr | 79:682ae3171a08 | 9 | int main() |
mjr | 79:682ae3171a08 | 10 | { |
mjr | 79:682ae3171a08 | 11 | int address = flashSize() - SECTOR_SIZE; //Write in last sector |
mjr | 2:c174f9ee414a | 12 | |
mjr | 2:c174f9ee414a | 13 | int *data = (int*)address; |
mjr | 2:c174f9ee414a | 14 | printf("Starting\r\n"); |
mjr | 2:c174f9ee414a | 15 | erase_sector(address); |
mjr | 2:c174f9ee414a | 16 | int numbers[10] = {0, 1, 10, 100, 1000, 10000, 1000000, 10000000, 100000000, 1000000000}; |
mjr | 79:682ae3171a08 | 17 | programFlash(address, (char*)&numbers, 40); //10 integers of 4 bytes each: 40 bytes length |
mjr | 79:682ae3171a08 | 18 | while (true) ; |
mjr | 2:c174f9ee414a | 19 | } |
mjr | 2:c174f9ee414a | 20 | |
mjr | 2:c174f9ee414a | 21 | */ |
mjr | 2:c174f9ee414a | 22 | |
mjr | 2:c174f9ee414a | 23 | #ifndef FREESCALEIAP_H |
mjr | 2:c174f9ee414a | 24 | #define FREESCALEIAP_H |
mjr | 2:c174f9ee414a | 25 | |
mjr | 2:c174f9ee414a | 26 | #include "mbed.h" |
mjr | 2:c174f9ee414a | 27 | |
mjr | 2:c174f9ee414a | 28 | #ifdef TARGET_KLXX |
mjr | 2:c174f9ee414a | 29 | #define SECTOR_SIZE 1024 |
mjr | 2:c174f9ee414a | 30 | #elif TARGET_K20D5M |
mjr | 2:c174f9ee414a | 31 | #define SECTOR_SIZE 2048 |
mjr | 2:c174f9ee414a | 32 | #elif TARGET_K64F |
mjr | 2:c174f9ee414a | 33 | #define SECTOR_SIZE 4096 |
mjr | 2:c174f9ee414a | 34 | #else |
mjr | 2:c174f9ee414a | 35 | #define SECTOR_SIZE 1024 |
mjr | 2:c174f9ee414a | 36 | #endif |
mjr | 2:c174f9ee414a | 37 | |
mjr | 2:c174f9ee414a | 38 | class FreescaleIAP |
mjr | 2:c174f9ee414a | 39 | { |
mjr | 2:c174f9ee414a | 40 | public: |
mjr | 79:682ae3171a08 | 41 | enum IAPCode { |
mjr | 79:682ae3171a08 | 42 | BoundaryError = -99, // Commands may not span several sectors |
mjr | 79:682ae3171a08 | 43 | AlignError, // Data must be aligned on longword (two LSBs zero) |
mjr | 79:682ae3171a08 | 44 | ProtectionError, // Flash sector is protected |
mjr | 79:682ae3171a08 | 45 | AccessError, // Something went wrong |
mjr | 79:682ae3171a08 | 46 | CollisionError, // During writing something tried to flash which was written to |
mjr | 79:682ae3171a08 | 47 | LengthError, // The length must be multiples of 4 |
mjr | 79:682ae3171a08 | 48 | RuntimeError, // FTFA runtime error reports |
mjr | 79:682ae3171a08 | 49 | EraseError, // The flash was not erased before writing to it |
mjr | 79:682ae3171a08 | 50 | VerifyError, // The data read back from flash didn't match what we wrote |
mjr | 79:682ae3171a08 | 51 | Success = 0 |
mjr | 79:682ae3171a08 | 52 | }; |
mjr | 79:682ae3171a08 | 53 | |
mjr | 76:7f5912b6340e | 54 | FreescaleIAP() { } |
mjr | 76:7f5912b6340e | 55 | ~FreescaleIAP() { } |
mjr | 2:c174f9ee414a | 56 | |
mjr | 76:7f5912b6340e | 57 | /** Program flash. This erases the area to be written, then writes the data. |
mjr | 2:c174f9ee414a | 58 | * |
mjr | 2:c174f9ee414a | 59 | * @param address starting address where the data needs to be programmed (must be longword alligned: two LSBs must be zero) |
mjr | 2:c174f9ee414a | 60 | * @param data pointer to array with the data to program |
mjr | 2:c174f9ee414a | 61 | * @param length number of bytes to program (must be a multiple of 4) |
mjr | 2:c174f9ee414a | 62 | * @param return Success if no errors were encountered, otherwise one of the error states |
mjr | 2:c174f9ee414a | 63 | */ |
mjr | 79:682ae3171a08 | 64 | IAPCode programFlash(int address, const void *data, unsigned int length); |
mjr | 2:c174f9ee414a | 65 | |
mjr | 2:c174f9ee414a | 66 | /** |
mjr | 2:c174f9ee414a | 67 | * Returns size of flash memory |
mjr | 2:c174f9ee414a | 68 | * |
mjr | 2:c174f9ee414a | 69 | * This is the first address which is not flash |
mjr | 2:c174f9ee414a | 70 | * |
mjr | 2:c174f9ee414a | 71 | * @param return length of flash memory in bytes |
mjr | 2:c174f9ee414a | 72 | */ |
mjr | 79:682ae3171a08 | 73 | uint32_t flashSize(void); |
mjr | 2:c174f9ee414a | 74 | |
mjr | 2:c174f9ee414a | 75 | private: |
mjr | 2:c174f9ee414a | 76 | // program a word of flash |
mjr | 2:c174f9ee414a | 77 | IAPCode program_word(int address, const char *data); |
mjr | 2:c174f9ee414a | 78 | |
mjr | 2:c174f9ee414a | 79 | // verify that a flash area has been erased |
mjr | 2:c174f9ee414a | 80 | IAPCode verify_erased(int address, unsigned int length); |
mjr | 2:c174f9ee414a | 81 | }; |
mjr | 2:c174f9ee414a | 82 | |
mjr | 2:c174f9ee414a | 83 | #endif |