/* Program Page in Flash Memory Parameter: adr: Page Start Address sz: Page Size buf: Page Data Return Value: 0 - OK, 1 - Failed  */
uint32_t ProgramPage(uint32_t adr, uint32_t sz, uint32_t *buf)
/* Program Page in Flash Memory Parameter: adr: Page Start Address sz: Page Size buf: Page Data Return Value: 0 - OK, 1 - Failed  */
uint32_t ProgramPage(uint32_t adr, uint32_t sz, uint32_t *buf)
{
    cortex_int_state_t state = cortex_int_get_and_disable();
    int status = FLASH_Program(&g_flash, adr, buf, sz);
    if (status == kStatus_Success)
    {
        status = FLASH_VerifyProgram(&g_flash, adr, sz,
                              buf, kFLASH_marginValueUser,
                              NULL, NULL);
    }
    cortex_int_restore(state);
    return status;
}