boolean DueFlash::write(uint32_t address, byte value) { uint32_t retCode; uint32_t byteLength = 1; byte *data; retCode = flash_unlock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + byteLength - 1, 0, 0); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Failed to unlock flash for write\n"); return false; } // write data retCode = flash_write((uint32_t)FLASH_START+address, &value, byteLength, 1); //retCode = flash_write((uint32_t)FLASH_START, data, byteLength, 1); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Flash write failed\n"); return false; } // Lock page retCode = flash_lock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + byteLength - 1, 0, 0); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Failed to lock flash page\n"); return false; } return true; }
void DueFlashStorage::init() { /* Initialize flash: 6 wait states for flash writing. */ uint32_t retCode = flash_init(FLASH_ACCESS_MODE_128, 6); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Flash init failed\n"); } }
boolean DueFlashStorage::write(uint32_t address, byte *data, uint32_t dataLength, int block) { uint32_t retCode; if (block != 0) address += IFLASH0_SIZE; if ((uint32_t)FLASH_START+address >= (IFLASH1_ADDR + IFLASH1_SIZE)) { _FLASH_DEBUG("Flash write address too high\n"); return false; } if (((uint32_t)FLASH_START+address & 3) != 0) { _FLASH_DEBUG("Flash start address must be on four byte boundary\n"); return false; } SerialUSB.print("Write addr: "); SerialUSB.println((long)(FLASH_START + address), HEX); // Unlock page retCode = flash_unlock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + dataLength - 1, 0, 0); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Failed to unlock flash for write\n"); return false; } // write data retCode = flash_write((uint32_t)FLASH_START+address, data, dataLength, 1); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Flash write failed\n"); return false; } else { _FLASH_DEBUG("Success in writing a page\n"); } // Lock page retCode = flash_lock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + dataLength - 1, 0, 0); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Failed to lock flash page\n"); return false; } return true; }
boolean DueFlash::write(uint32_t address, byte *data, uint32_t dataLength) { uint32_t retCode; if ((uint32_t)FLASH_START+address < IFLASH1_ADDR) { _FLASH_DEBUG("Flash write address too low\n"); return false; } if ((uint32_t)FLASH_START+address >= (IFLASH1_ADDR + IFLASH1_SIZE)) { _FLASH_DEBUG("Flash write address too high\n"); return false; } if (((uint32_t)FLASH_START+address & 3) != 0) { _FLASH_DEBUG("Flash start address must be on four byte boundary\n"); return false; } // Unlock page retCode = flash_unlock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + dataLength - 1, 0, 0); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Failed to unlock flash for write\n"); return false; } // write data retCode = flash_write((uint32_t)FLASH_START+address, data, dataLength, 1); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Flash write failed\n"); return false; } // Lock page retCode = flash_lock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + dataLength - 1, 0, 0); if (retCode != FLASH_RC_OK) { _FLASH_DEBUG("Failed to lock flash page\n"); return false; } return true; }