/***************************************************************************** ** Function name: u32BootLoader_ProgramFlash ** ** Description: ** ** Parameters: None ** ** Returned value: 0 if programming failed, otherwise 1. ** *****************************************************************************/ static uint32_t u32BootLoader_ProgramFlash(uint8_t *pu8Data, uint16_t u16Len) { uint32_t u32Result = 0; if ((pu8Data != 0) && (u16Len != 0)) { /* Prepare the flash application sectors for reprogramming */ if (u32IAP_PrepareSectors(APP_START_SECTOR, APP_END_SECTOR) == IAP_STA_CMD_SUCCESS) { /* Ensure that amount of data written to flash is at minimum the size of a flash page */ if (u16Len < IAP_FLASH_PAGE_SIZE_BYTES) { u16Len = IAP_FLASH_PAGE_SIZE_BYTES; } /* Write the data to flash */ if (u32IAP_CopyRAMToFlash(u32NextFlashWriteAddr, (uint32_t)pu8Data, u16Len) == IAP_STA_CMD_SUCCESS) { /* Check that the write was successful */ if (u32IAP_Compare(u32NextFlashWriteAddr, (uint32_t)pu8Data, u16Len, 0) == IAP_STA_CMD_SUCCESS) { /* Write was successful */ u32NextFlashWriteAddr += u16Len; u32Result = 1; } } } } return (u32Result); }
void saveUtcOffsetToFlash() { flashImage[0] = utcOffset; __disable_irq(); if(u32IAP_PrepareSectors(16, 16) == IAP_STA_CMD_SUCCESS) { u32IAP_EraseSectors(16, 16); u32IAP_PrepareSectors(16, 16); if(u32IAP_CopyRAMToFlash(IMG_START_SECTOR, (uint32_t)flashImage, IAP_FLASH_PAGE_SIZE_BYTES) == IAP_STA_CMD_SUCCESS) { if(u32IAP_Compare(IMG_START_SECTOR, (uint32_t)flashImage, IAP_FLASH_PAGE_SIZE_BYTES, 0) == IAP_STA_CMD_SUCCESS) { __enable_irq(); ledSetState(TASK_LED, LedOn); return; } } } __enable_irq(); ledSetState(TASK_LED, LedBlink); }