work in progress

Dependencies:   FastAnalogIn FastIO USBDevice mbed FastPWM SimpleDMA

Fork of Pinscape_Controller by Mike R

Committer:
mkalkbrenner
Date:
Wed Dec 16 15:37:59 2015 +0000
Revision:
38:697e10d8fb80
Parent:
2:c174f9ee414a
fixed default configuration for extension boards

Who changed what in which revision?

UserRevisionLine numberNew 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 2:c174f9ee414a 9 int main() {
mjr 2:c174f9ee414a 10 int address = flash_size() - SECTOR_SIZE; //Write in last sector
mjr 2:c174f9ee414a 11
mjr 2:c174f9ee414a 12 int *data = (int*)address;
mjr 2:c174f9ee414a 13 printf("Starting\r\n");
mjr 2:c174f9ee414a 14 erase_sector(address);
mjr 2:c174f9ee414a 15 int numbers[10] = {0, 1, 10, 100, 1000, 10000, 1000000, 10000000, 100000000, 1000000000};
mjr 2:c174f9ee414a 16 program_flash(address, (char*)&numbers, 40); //10 integers of 4 bytes each: 40 bytes length
mjr 2:c174f9ee414a 17 printf("Resulting flash: \r\n");
mjr 2:c174f9ee414a 18 for (int i = 0; i<10; i++)
mjr 2:c174f9ee414a 19 printf("%d\r\n", data[i]);
mjr 2:c174f9ee414a 20
mjr 2:c174f9ee414a 21 printf("Done\r\n\n");
mjr 2:c174f9ee414a 22
mjr 2:c174f9ee414a 23
mjr 2:c174f9ee414a 24 while (true) {
mjr 2:c174f9ee414a 25 }
mjr 2:c174f9ee414a 26 }
mjr 2:c174f9ee414a 27
mjr 2:c174f9ee414a 28 */
mjr 2:c174f9ee414a 29
mjr 2:c174f9ee414a 30 #ifndef FREESCALEIAP_H
mjr 2:c174f9ee414a 31 #define FREESCALEIAP_H
mjr 2:c174f9ee414a 32
mjr 2:c174f9ee414a 33 #include "mbed.h"
mjr 2:c174f9ee414a 34
mjr 2:c174f9ee414a 35 #ifdef TARGET_KLXX
mjr 2:c174f9ee414a 36 #define SECTOR_SIZE 1024
mjr 2:c174f9ee414a 37 #elif TARGET_K20D5M
mjr 2:c174f9ee414a 38 #define SECTOR_SIZE 2048
mjr 2:c174f9ee414a 39 #elif TARGET_K64F
mjr 2:c174f9ee414a 40 #define SECTOR_SIZE 4096
mjr 2:c174f9ee414a 41 #else
mjr 2:c174f9ee414a 42 #define SECTOR_SIZE 1024
mjr 2:c174f9ee414a 43 #endif
mjr 2:c174f9ee414a 44
mjr 2:c174f9ee414a 45 enum IAPCode {
mjr 2:c174f9ee414a 46 BoundaryError = -99, //Commands may not span several sectors
mjr 2:c174f9ee414a 47 AlignError, //Data must be aligned on longword (two LSBs zero)
mjr 2:c174f9ee414a 48 ProtectionError, //Flash sector is protected
mjr 2:c174f9ee414a 49 AccessError, //Something went wrong
mjr 2:c174f9ee414a 50 CollisionError, //During writing something tried to flash which was written to
mjr 2:c174f9ee414a 51 LengthError, //The length must be multiples of 4
mjr 2:c174f9ee414a 52 RuntimeError,
mjr 2:c174f9ee414a 53 EraseError, //The flash was not erased before writing to it
mjr 2:c174f9ee414a 54 Success = 0
mjr 2:c174f9ee414a 55 };
mjr 2:c174f9ee414a 56
mjr 2:c174f9ee414a 57
mjr 2:c174f9ee414a 58 class FreescaleIAP
mjr 2:c174f9ee414a 59 {
mjr 2:c174f9ee414a 60 public:
mjr 2:c174f9ee414a 61 FreescaleIAP();
mjr 2:c174f9ee414a 62 ~FreescaleIAP();
mjr 2:c174f9ee414a 63
mjr 2:c174f9ee414a 64 /** Erase a flash sector
mjr 2:c174f9ee414a 65 *
mjr 2:c174f9ee414a 66 * The size erased depends on the used device
mjr 2:c174f9ee414a 67 *
mjr 2:c174f9ee414a 68 * @param address address in the sector which needs to be erased
mjr 2:c174f9ee414a 69 * @param return Success if no errors were encountered, otherwise one of the error states
mjr 2:c174f9ee414a 70 */
mjr 2:c174f9ee414a 71 IAPCode erase_sector(int address);
mjr 2:c174f9ee414a 72
mjr 2:c174f9ee414a 73 /** Program flash
mjr 2:c174f9ee414a 74 *
mjr 2:c174f9ee414a 75 * Before programming the used area needs to be erased. The erase state is checked
mjr 2:c174f9ee414a 76 * before programming, and will return an error if not erased.
mjr 2:c174f9ee414a 77 *
mjr 2:c174f9ee414a 78 * @param address starting address where the data needs to be programmed (must be longword alligned: two LSBs must be zero)
mjr 2:c174f9ee414a 79 * @param data pointer to array with the data to program
mjr 2:c174f9ee414a 80 * @param length number of bytes to program (must be a multiple of 4)
mjr 2:c174f9ee414a 81 * @param return Success if no errors were encountered, otherwise one of the error states
mjr 2:c174f9ee414a 82 */
mjr 2:c174f9ee414a 83 IAPCode program_flash(int address, const void *data, unsigned int length);
mjr 2:c174f9ee414a 84
mjr 2:c174f9ee414a 85 /**
mjr 2:c174f9ee414a 86 * Returns size of flash memory
mjr 2:c174f9ee414a 87 *
mjr 2:c174f9ee414a 88 * This is the first address which is not flash
mjr 2:c174f9ee414a 89 *
mjr 2:c174f9ee414a 90 * @param return length of flash memory in bytes
mjr 2:c174f9ee414a 91 */
mjr 2:c174f9ee414a 92 uint32_t flash_size(void);
mjr 2:c174f9ee414a 93
mjr 2:c174f9ee414a 94 private:
mjr 2:c174f9ee414a 95 // program a word of flash
mjr 2:c174f9ee414a 96 IAPCode program_word(int address, const char *data);
mjr 2:c174f9ee414a 97
mjr 2:c174f9ee414a 98 // verify that a flash area has been erased
mjr 2:c174f9ee414a 99 IAPCode verify_erased(int address, unsigned int length);
mjr 2:c174f9ee414a 100 };
mjr 2:c174f9ee414a 101
mjr 2:c174f9ee414a 102 #endif