コード例 #1
0
/*
  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);
}
コード例 #2
0
ファイル: flash.c プロジェクト: OpenLightingProject/ja-rule
static void PerformOperation(uint32_t nvmop) {
  // Disable flash write/erase operations
  PLIB_NVM_MemoryModifyInhibit(NVM_ID_0);

  PLIB_NVM_MemoryOperationSelect(NVM_ID_0, nvmop);

  // Allow memory modifications
  PLIB_NVM_MemoryModifyEnable(NVM_ID_0);

  /* Unlock the Flash */
  PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, 0);
  PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY1);
  PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY2);

  PLIB_NVM_FlashWriteStart(NVM_ID_0);
}