/* Function: void APP_NVMwriteWord (uint32_t address, uint32_t data) Summary: Writes a word in flash memory (4 bytes) */ void APP_NVMwriteWord(uint32_t address, uint32_t data) { /* Base address of where word is to be written */ PLIB_NVM_FlashAddressToModify(NVM_ID_0, virtualToPhysical(address)); /* Word of data to be written */ PLIB_NVM_FlashProvideData(NVM_ID_0 , data); /* Disable flash write/erase operations */ PLIB_NVM_MemoryModifyInhibit(NVM_ID_0); /* Select Word Program operation */ PLIB_NVM_MemoryOperationSelect(NVM_ID_0, WORD_PROGRAM_OPERATION); /* Enable flash write/erase operations */ PLIB_NVM_MemoryModifyEnable(NVM_ID_0); /* Write the unlock key sequence */ PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, 0x0); PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, 0xAA996655); PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, 0x556699AA); /* Start Writing */ PLIB_NVM_FlashWriteStart(NVM_ID_0); bttask_setState(BTTASK_STATE_INTERNAL_NVM_WRITE_START); }
bool Flash_WriteWord(uint32_t address, uint32_t data) { PLIB_NVM_FlashAddressToModify(NVM_ID_0, KVA_TO_PA(address)); PLIB_NVM_FlashProvideData(NVM_ID_0, data); PerformOperation(WORD_PROGRAM_OPERATION); while (!PLIB_NVM_FlashWriteCycleHasCompleted(NVM_ID_0)) { {} } return !PLIB_NVM_WriteOperationHasTerminated(NVM_ID_0); }