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.

TMS570LS0914: F021 flashAPI causes prefetch entry

Part Number: TMS570LS0914


Hello,

i want to use the flashAPI F021 and i am using safeRTOS operation system.

I already added the flashAPI in the linker script and configure two data sections:

flashAPI : RUN_START( FLASHAPI_Start ) RUN_END( FLASHAPI_End )
{
    */library/extern/FlashAPI/Fapi_UserDefinedFunctions.c.obj (.text)
    */library/source/Hardware/flashIf/flashTMS.c.obj (.text)
    --library = */library/extern/FlashAPI/F021_API_CortexR4_BE.lib (.text)
}load = FAPIFLASH, run = FAPIRAM, palign(0x1000), table(BINIT)

MEM_DATA_SEC_0 : START( MEM_DATA_SEC_0_Start ) END( MEM_DATA_SEC_0_End )
{
    --library = */library/extern/FlashAPI/F021_API_CortexR4_BE.lib <
                FlashStateMachine.ScaleFclk.obj
                FlashStateMachine.SetActiveBank.obj > (.data)
} > RAM palign( 0x2000 )

The task in which I want to use the flashAPI runs in user mode.

Both memsections were configured as mpu sections according to Cortex-R4F techincal reference manual on page 125 and 126 (ARM DDI 0363G, ID041111; p.125-126/436).

MEM_DATA_SEC_0: AP bit value b011, XN bit value 1, TEX[2:0] value 0b000, C bit value 0 and B bit value 0

flashAPI : AP bit value b011, XN bit value 0, TEX[2:0] value 0b000, C bit value 0 and B bit value 0

 

If i try to debug the sw, the first instruction executed in the ram section caused a prefetch entry. The value of the fault status register is 0x0D. This value is an permission fault.

Function that causes the permission fault:

Fapi_StatusType Fapi_BlockErase(uint32_t Bank, uint32_t Erase_Start_Address, uint32_t Size_In_Bytes)
{
    Fapi_StatusType error      = Fapi_Status_Success;
    uint8_t ucStartBank        = 0;
    uint8_t ucStartSector      = 0;
    uint8_t ucEndBank          = 0;
    uint32_t* eraseStartAddr0  = (uint32_t*)Erase_Start_Address;
    uint32_t* eraseStartAddr   = (uint32_t*)Erase_Start_Address;
    uint32_t Erase_End_Address = Erase_Start_Address + Size_In_Bytes;

    //Bestimme Startadresse des Sektors, welcher geloescht werden soll.
    for(uint8_t i = 0; i < SECTOR_TABLE_SIZE; i++)  //     for (i = 0; i < NUMBEROFSECTORS - 1; i++) 23.02.2018 mkh
    {
        if(Erase_Start_Address == (uint32_t)(SectorTable[i].dwStartAddr))
        {
            ucStartBank     = SectorTable[i].bankNumber;
            ucStartSector   = SectorTable[i].sectorNumber;
            eraseStartAddr0 = SectorTable[i].dwStartAddr;
            eraseStartAddr  = SectorTable[i].dwStartAddr;
            break;
        }
    }

    //Bestimmt bank des Sektors, welcher geloescht werden soll.
    for(uint8_t j = ucStartSector; j < SECTOR_TABLE_SIZE; j++)
    {
        if(Erase_End_Address < ((uint32_t)(SectorTable[j].dwStartAddr) + SectorTable[j].length))
        {
            ucEndBank = SectorTable[j].bankNumber;
            break;
        }
    }

    if(error == Fapi_Status_Success)
    {
        //F021_CPU0_REGISTER_ADDRESS is defined as 0xfff87000 in FMC.h
        //Fapi_initializeAPI((Fapi_FmcRegistersType *)F021_CPU0_REGISTER_ADDRESS, freqInMHz); /*used for API Rev1.5*/
        error = Fapi_initializeFlashBanks(HCLK_FREQ); /* used for API Rev2.01 */
    }

    for(uint8_t bk = ucStartBank; (bk < (ucEndBank + 1u)) && (error == Fapi_Status_Success); bk++)
    {
        uint8_t k;
        uint32_t remaining;
        error = Fapi_setActiveFlashBank((Fapi_FlashBankType)bk);

        if(bk == 0u)
        {
            k         = ucStartSector;
            remaining = Size_In_Bytes;
        }
        else
        {
            k = 0u;
        }

        error = Fapi_enableMainBankSectors(0xFFFF); /* used for API 2.01*/


        if(!WHILE_SAFE(FAPI_CHECK_FSM_READY_BUSY != Fapi_Status_FsmReady))
        {
            error = Fapi_Status_FsmBusy;
        }

        if(error == Fapi_Status_Success)
        {
            do
            {
                error = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
                                                          eraseStartAddr);

                if(!WHILE_SAFE(FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy))
                {
                    error = Fapi_Status_FsmBusy;
                    break;
                }

                if(!WHILE_SAFE(FAPI_GET_FSM_STATUS != Fapi_Status_Success))
                {
                    error = Fapi_Status_FsmBusy;
                    break;
                }
                remaining -= SectorTable[k++].length;
                if(k < SECTOR_TABLE_SIZE)
                {
                    eraseStartAddr = SectorTable[k].dwStartAddr;
                }

            } while((remaining > 0u) && (k < SECTOR_TABLE_SIZE));
        }
    }

    if(error == Fapi_Status_Success)
    {
        error = Flash_Erase_Check((uint32_t)eraseStartAddr0, Size_In_Bytes);
    }

    return error;
}

Disassembly from the instruction that causes the permission fault:

As you can see the instruction that caused the permission fault pushes registers onto the stack. 

Register content:

The stack pointer is within the permissible range.

Task stack memory range from the map file:
address     length
08003000 00001000 safetyTask.c.obj (.bss:safetybuffer_1)

Any ideas on how to solve this problem please?

Kind regards

Aron