This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I'm trying to erase a sector in flash but when I call Fapi_issueAsyncCommandWithAddress(), my code will not proceed further and I will get a prefetch exception. I noticed that I can get past that function and execute some number of lines after that but eventually, a prefetch exception occurs. Here's the code for erasing:
typedef struct Sectors { uint32_t start; uint32_t length; Fapi_FlashBankType bankNumber; uint8_t sectorNumber; } SECTORS; #define HCLK_FREQ 150U #define WAIT_FSM_READY() { while (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == (uint32_t)Fapi_Status_FsmBusy) {} }
#define BL_INFO_SECTOR_ID 0x3u
void dummyFunc(void)
{ Fapi_initializeFlashBanks(HCLK_FREQ); Fapi_setActiveFlashBank(flash_sector[BL_INFO_SECTOR_ID].bankNumber); WAIT_FSM_READY(); Fapi_enableMainBankSectors((uint16_t)(0x0001U << BL_INFO_SECTOR_ID)); WAIT_FSM_READY(); Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32_t*)flash_sector[BL_INFO_SECTOR_ID].start); WAIT_FSM_READY();
} const SECTORS flash_sector[NUMBEROFSECTORS]= { 0x00000000U, 0x04000U, Fapi_FlashBank0, 0U, 0x00004000U, 0x04000U, Fapi_FlashBank0, 1U, 0x00008000U, 0x04000U, Fapi_FlashBank0, 2U, 0x0000C000U, 0x04000U, Fapi_FlashBank0, 3U, 0x00010000U, 0x04000U, Fapi_FlashBank0, 4U, 0x00014000U, 0x04000U, Fapi_FlashBank0, 5U, 0x00018000U, 0x08000U, Fapi_FlashBank0, 6U, 0x00020000U, 0x20000U, Fapi_FlashBank0, 7U, 0x00040000U, 0x20000U, Fapi_FlashBank0, 8U, 0x00060000U, 0x20000U, Fapi_FlashBank0, 9U, 0x00080000U, 0x40000U, Fapi_FlashBank0, 10U, 0x000C0000U, 0x40000U, Fapi_FlashBank0, 11U, 0x00100000U, 0x40000U, Fapi_FlashBank0, 12U, 0x00140000U, 0x40000U, Fapi_FlashBank0, 13U, 0x00180000U, 0x40000U, Fapi_FlashBank0, 14U, 0x001C0000U, 0x40000U, Fapi_FlashBank0, 15U, 0x00200000U, 0x20000U, Fapi_FlashBank1, 0U, 0x00220000U, 0x20000U, Fapi_FlashBank1, 1U, 0x00240000U, 0x20000U, Fapi_FlashBank1, 2U, 0x00260000U, 0x20000U, Fapi_FlashBank1, 3U, 0x00280000U, 0x20000U, Fapi_FlashBank1, 4U, 0x002A0000U, 0x20000U, Fapi_FlashBank1, 5U, 0x002C0000U, 0x20000U, Fapi_FlashBank1, 6U, 0x002E0000U, 0x20000U, Fapi_FlashBank1, 7U, 0x00300000U, 0x20000U, Fapi_FlashBank1, 8U, 0x00320000U, 0x20000U, Fapi_FlashBank1, 9U, 0x00340000U, 0x20000U, Fapi_FlashBank1, 10U, 0x00360000U, 0x20000U, Fapi_FlashBank1, 11U, 0x00380000U, 0x20000U, Fapi_FlashBank1, 12U, 0x003A0000U, 0x20000U, Fapi_FlashBank1, 13U, 0x003C0000U, 0x20000U, Fapi_FlashBank1, 14U, 0x003E0000U, 0x20000U, Fapi_FlashBank1, 15U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 0U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 1U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 2U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 3U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 4U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 5U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 6U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 7U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 8U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 9U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 10U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 11U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 12U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 13U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 14U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 15U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 16U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 17U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 18U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 19U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 20U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 21U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 22U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 23U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 24U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 25U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 26U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 27U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 28U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 29U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 30U, 0xF0200000U, 0x01000U, Fapi_FlashBank7, 31U };
The instruction fault status register has 0x1000000001008 in it and the instruction fault address register has 0x0000000C in it. I verified that I'm enabling the banks and setting them up properly as well. I am running the fapi functions from RAM by using the following in my linker:
.flashapi : palign(32), run = RAM {
-l F021_API_CortexR4_BE_L2FMC_V3D16_NDS.lib(.text)
} > PBL_TXT, crc_table(tbl_CRC), table(tblFlashApi)
I'm not sure what is causing this issue.
Thank you
Hello Milin,
It seems to me that the code is not copied to RAM. You need to write a function to copy those flash API related function to RAM.
For example:
In cmd file:the flashAPI section contains not only the library but the bl_flash.obj and Fapi_..
flashAPI :
{
Fapi_UserDefinedFunctions.obj (.text)
bl_flash.obj (.text)
--library= ..\..\..\lib\F021_API_CortexR4_BE.lib (.text)
} load = FLASH_API, run = SRAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)
In asm or c file:
.def _copyAPI2RAM_
.asmfunc
_copyAPI2RAM_
.ref api_load
flash_load .word api_load
.ref api_run
flash_run .word api_run
.ref api_size
flash_size .word api_size
ldr r0, flash_load
ldr r1, flash_run
ldr r2, flash_size
add r2, r1, r2
copy_loop1:
ldr r3, [r0], #4
str r3, [r1], #4
cmp r1, r2
blt copy_loop1
bx lr
.endasmfunc
Copy the content in flashAPI section to SRAM
Hey QJ,
Thanks for the response! Unfortunately, that didn't help. I verified that the run address in the map file for that section was in RAM after I made the changes you suggested. I'm not sure what bl_flash.obj and Fapi_.. are though, I don't see those objects in my project. Any other suggestions?
Thank you,
Milin