I am using the ASF 4 EFC driver routines to write to internal flash on a SAMv71. I registered a callback so that I can tell when the Flash is ready to accept a new command. Before a flash_write I set m_bReady to false (busy). The callback routine sets m_bReady to true.
The problem is that as soon as I do a flash_register_callback(), the flash FRDY bit is already set (since the flash is ready) and this generates an immediate interrupt. EFC_Handler() (in hap_efc.c) then calls the callback. Once the callback is executed, the FRDY bit is still true, so it keeps calling the callback routine continuously and the program is hung.
Am I doing this wrong or is this just an ASF driver bug?
void flash_callback(struct flash_descriptor *const descr); bool m_bReady; InternalFlashDriver::InternalFlashDriver() { m_ui32PageSize = flash_get_page_size(&FLASH_0); flash_register_callback(&FLASH_0, FLASH_CB_READY, flash_callback); m_bReady = true; } void InternalFlashDriver::flash_callback(struct flash_descriptor *const descr) { m_bReady = true; } bool InternalFlashDriver::WritePage(uint8_t * pData, uint32_t ui32Address) { bool bFlag = false; if (m_bReady == true) { m_bReady = false; // Set flash busy if (flash_write(&FLASH_0, ui32Address, pData, m_ui32PageSize) != ERR_NONE) { bFlag = true; // Error } } else { bFlag = true; // Flash not ready } return(bFlag); } ---------------------------- In hpl_efc.c void EFC_Handler(void) { void *const hw = _efc_dev->hw; if (hri_efc_get_EEFC_FSR_FRDY_bit(hw)) { if (NULL != _efc_dev->flash_cb.ready_cb) { _efc_dev->flash_cb.ready_cb(_efc_dev); } } }