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.

TMS570LC4357: Problems with executing code and erasing on the same bank

Part Number: TMS570LC4357

Hi Team,

I'm asking for some help for my customer:

Hello TI engineer, I have a question for consultation

Background: The current code is running on Bank 0, and I need to erase the Sector of Bank 0 because of my own business needs

After the call Fapi_issueAsyncCommandWithAddress erases a Sector of Bank 0, one is calledEraseWait, the specific implementation is very simple, it is an endless loop
...
Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, /*Sector's starting address*/);
ret = EraseWait();
...
bool IsFsmReady(void) // Get the busy bit of FMSTAT
{
    return ((L2FMC->fMStat & FMSTA_BUSY_MASK) == 0 ? true false);
}
uint32_t EraseWait(void)
{
    while (IsFsmReady() == false) { }
    return 0;
}
1.
In the very beginning, I found that as soon as the Fapi_issueAsyncCommandWithAddress was called, the board would freeze and the red light would come on
After locating, it came after I added the relevant function of the break

According to the prompts in F021 Flash API Reference Guide Version 2.01.01:

(1) Reading a Flash memory location from the bank that an erase command (sector or bank) is currently being performed will stall the CPU until the erase command finishes and the FMSTAT register indicates the FSM is not busy.

(2) Reading a Flash memory location from the bank that an program command is currently being performed will stall the CPU until the program command finishes and the FMSTAT register indicates the FSM is not busy

I think it was me who interrupted reading the code stored in Bank 0 after being interrupted by an interrupt while erasing/writing, causing the CPU Stall to freeze
So I turned off interrupts during both erasing and reading and writing, and the problem was temporarily resolved.
2. 
Since I don't want to be an endless loop, I want to check if the current wait time has exceeded the maximum amount provided by the datasheet, based on the maximum erase/write time provided in the datasheet
So before entering the while loop, I get a startTime, and every time I get the currTime in the while, I make a difference to determine whether the elapsed time has exceeded the maximum time, and if it does, it will return an abnormal exit
After doing this, I found that the board was stuck again, and after positioning, it was still stuck after calling the Fapi_issueAsyncCommandWithAddress
When erasing the current bank, reading the current bank will cause a CPU stall
3.
The reason why it can be done normally is that there is only one dead loop while in the Erase Wait function, which is small enough that it is prefetched into ICache, so it does not need to access Bank 0 when executed
And it just so happened to be able to execute it smoothly.
In order to verify my idea, I made changes to the Cache enablement during the startup phase.
In the case of Cache Enable, I can complete the erase without any problems
In the case of Cache Disable, after the Fapi_issueAsyncCommandWithAddress is called, the board will freeze and the red light will come on
This proves what I think.
Now the point of doubt is,

(1) Reading a Flash memory location from the bank that an erase command (sector or bank) is currently being performed will stall the CPU until the erase command finishes and the FMSTAT register indicates the FSM is not busy.

(2) Reading a Flash memory location from the bank that an program command is currently being performed will stall the CPU until the program command finishes and the FMSTAT register indicates the FSM is not busy

It is mentioned in these two sentences that if the current bank is being erased during reading, the CPU will stall until the erase is completed and the BUSY bit of FMSTAT is 0, and it will continue.

How is the continuation here achieved? Whether the current mechanism will let the CPU continue on its own, or will it notify the CPU by some method to continue reading

I need to do and erase on the same Bank, is there any solution

Best Regards,

Ben

  • Hi Ben,

    You are not supposed to do executing and erasing on the same bank.

    "The F021 Flash API library cannot be executed from the same bank as the active bank selected for the API commands to operate on".

    I need to do and erase on the same Bank, is there any solution

    If you really want to do this operation, then you should copy the all the Flash APIs from flash bank-0 to the RAM. Once you copy the Flash APIs to the RAM then you can erase and write to the sectors in Flash Bank-0.

    Please refer below thread for more details:

    (+) TMS570LS3137: TMS570LS3137: Writing Flash During Runtime - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    --

    Thanks & regards,
    Jagadish.

  • Hi Jagadish,

    Understood, now we will move the code that calls the two FAPIs Fapi_issueAsyncCommandWithAddress and Fapi_issueProgrammingCommand to start the process of FSM Ready into SRAM to solve this problem, but under the condition of turning off interrupts.

    After reading the manual and other questions in TI forums, I tested using the macro FAPI_SUSPEND_FSM to suspend the ongoing erase or write, and then continue to execute the code of the bank where it is erased or written.

    Now we hope to use this macro to suspend the erase/write operation of Flash at the beginning of interrupt processing, and then come back to continue erasing and writing Flash after the interrupt is completed. However, the current interrupt vector table and other interrupt-related code contents are all at 0x0. In the starting address, is there any way that I can still perform interrupts or task scheduling normally when erasing the bank 0 sector?

    Best Regards,

    Ben

  • Hi Ben,

    In the starting address, is there any way that I can still perform interrupts or task scheduling normally when erasing the bank 0 sector?

    If you are trying to be erasing Bank 0 then the code in the same Bank 0 will not get execute. 

    --
    Thanks & regards,
    Jagadish.