Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "DueFlash.h"
00025
00026 DueFlash::DueFlash()
00027 {
00028 uint32_t retCode;
00029
00030
00031
00032 retCode = flash_init(FLASH_ACCESS_MODE_128, 6);
00033 if (retCode != FLASH_RC_OK) {
00034 _FLASH_DEBUG("Flash init failed\n");
00035 }
00036 }
00037
00038 boolean DueFlash::write(uint32_t *flashStart, uint32_t *data, uint32_t dataLength)
00039 {
00040 uint32_t retCode;
00041 uint32_t byteLength = dataLength * sizeof(uint32_t);
00042
00043 if ((uint32_t)flashStart < IFLASH1_ADDR) {
00044 _FLASH_DEBUG("Flash write address too low\n");
00045 return false;
00046 }
00047
00048 if ((uint32_t)flashStart >= (IFLASH1_ADDR + IFLASH1_SIZE)) {
00049 _FLASH_DEBUG("Flash write address too high\n");
00050 return false;
00051 }
00052
00053 if (((uint32_t)flashStart & 3) != 0) {
00054 _FLASH_DEBUG("Flash start address must be on four byte boundary\n");
00055 return false;
00056 }
00057
00058
00059
00060 retCode = flash_unlock((uint32_t)flashStart, (uint32_t)flashStart + byteLength - 1, 0, 0);
00061 if (retCode != FLASH_RC_OK) {
00062 _FLASH_DEBUG("Failed to unlock flash for write\n");
00063 return false;
00064 }
00065
00066
00067
00068 retCode = flash_write((uint32_t)flashStart, data, byteLength, 1);
00069
00070 if (retCode != FLASH_RC_OK) {
00071 _FLASH_DEBUG("Flash write failed\n");
00072 return false;
00073 }
00074
00075
00076
00077 retCode = flash_lock((uint32_t)flashStart, (uint32_t)flashStart + byteLength - 1, 0, 0);
00078 if (retCode != FLASH_RC_OK) {
00079 _FLASH_DEBUG("Failed to lock flash page\n");
00080 return false;
00081 }
00082 return true;
00083 }