Other Parts Discussed in Thread: HALCOGEN
I have been having some issues getting the F021 API working correctly in my project. I have attached some code snippets below to demonstrate my issue.
/* Creating FaultLOG location in memory and initalizing array that will be used for the log. */ #pragma DATA_SECTION(userLOGFile, "FaultLOG"); SAFETY_DATA const uint8_t userLOGFile[] = "EMPTY";
/* Function called to erase flash sectors. Right now it is configured for just erasing log data. */ SAFETY_FUNCTION results_e ProgramEraseSector ( uint16_t sector /* One of four sectors */ ) { results_e eraseStatus = fFAIL; Fapi_StatusType flashStatus; uint8_t *dataBuffer; /* Initialize the flash erase sequence for Bank7 */ flashStatus = Fapi_initializeFlashBanks((uint32_t) HCLK_FREQ); if (flashStatus == Fapi_Status_Success) { flashStatus = Fapi_setActiveFlashBank(Fapi_FlashBank7); } /* prgBANK7_ACTIVESECTORS is equal to 0x000Fu */ if (flashStatus == Fapi_Status_Success) { flashStatus = Fapi_enableEepromBankSectors(prgBANK7_ACTIVESECTORS, (uint32_t) Fapi_FlashSector0); } if (flashStatus == Fapi_Status_Success) { /* Wait until Flash State Machine is ready */ while (FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy) { ; /* Do nothing */ } dataBuffer = LogGetJSONPointer(); Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32_t *) dataBuffer); if (sector == prgSECTOR_LOG) { m_isLOGAvailable = false; } /* Wait until Flash State Machine is ready */ while (FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy) { ; /* Do nothing */ } if (FAPI_GET_FSM_STATUS == (uint32_t) Fapi_Status_Success) { eraseStatus = fPASS; if (sector == prgSECTOR_LOG) { m_isLOGAvailable = true; } } } return(eraseStatus); }
/* Passes pointer to first address of log. */ SAFETY_FUNCTION uint8_t *LogGetJSONPointer ( void ) { uint8_t *ptr; ptr = (uint8_t *) userLOGFile; return (ptr); }
/* Memory map */ MEMORY { VECTORS (X) : origin=0x00000000 length=0x00000020 KERNEL (RX) : origin=0x00000020 length=0x00008000 FLASH0 (RX) : origin=0x00008020 length=0x000B7FE0 STACKS (RW) : origin=0x08000000 length=0x00001000 KRAM (RW) : origin=0x08001000 length=0x00000800 RAM (RW) : origin=(0x08001000+0x00000800) length=(0x0001e400 - 0x00000800) FEE (RW) : origin=0xF0200000 length=0x00004000 vfill=0xffffffff FEE1 (RW) : origin=0xF0204000 length=0x00004000 vfill=0xffffffff FEE2 (RW) : origin=0xF0208000 length=0x00004000 vfill=0xffffffff FEE3 (RW) : origin=0xF020C000 length=0x00004000 vfill=0xffffffff /* USER CODE BEGIN (2) */ /* USER CODE END */ } /* USER CODE BEGIN (3) */ /* USER CODE END */ /*----------------------------------------------------------------------------*/ /* Section Configuration */ SECTIONS { .intvecs : {} > VECTORS /* FreeRTOS Kernel in protected region of Flash */ .kernelTEXT : {} > KERNEL .cinit : {} > KERNEL .pinit : {} > KERNEL /* Rest of code to user mode flash region */ .text : {} > FLASH0 .const : {} > FLASH0 /* FreeRTOS Kernel data in protected region of RAM */ .kernelBSS : {} > KRAM .kernelHEAP : {} > RAM .bss : {} > RAM .data : {} > RAM .sysmem : {} > RAM FEE_TEXT_SECTION : {} > FLASH0 FEE_CONST_SECTION : {} > FLASH0 FEE_DATA_SECTION : {} > RAM FaultLOG : START ( ulLogStartAddr ) {} > FEE3
Stepping through the ProgramEraseSector function I seem to be able to set flash bank 7 as the active flash bank and to enable eeprom on bank 7. The RM44L520 has 16 sectors so I passed in 0x0F to allow all 16 sectors to be erased. Both of these API calls passed back success flags so they seem to have worked correctly.
After calling Fapi_issueAsyncCommandWithAddress with the erase flag and the address for the Log file the FAPI_GET_FSM_STATUS macro never returns the success flag. I checked the FlashWrapper registers and found that the FMdlStat register is set to 0x11 . According to the F021 API document this code indicates that Sector Lock Status bit and the Command Status bits are set. At this point I am a bit confused because according to the API documentation the SLOCK should not be able to be set if all sectors are set to 1 which is what I would expect from the log sectors as they were all vfilled with 0xFF in the memory map. Please let me know if there is something I am missing or is there is some additional step I need to take prior to erasing flash sectors.