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: 在同一个Bank上执行代码及擦写的问题

Part Number: TMS570LC4357


TI工程师,你好,我有问题需要咨询

背景:当前代码运行在Bank 0上,同时因为自身业务需要,我需要对Bank 0的Sector进行擦写

在调用Fapi_issueAsyncCommandWithAddress对Bank 0的一个Sector进行擦除之后会调用一个EraseWait,具体实现很简单,就是一个死循环
...
Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, /*Sector的起始地址*/);
ret = EraseWait();
...
bool IsFsmReady(void) // 获取FMSTAT的busy位
{
    return ((L2FMC->fMStat & FMSTA_BUSY_MASK) == 0 ? true : false);
}
uint32_t EraseWait(void)
{
    while (IsFsmReady() == false) { }
    return 0;
}
1.
在最开始的情况下,我发现只要到调用了Fapi_issueAsyncCommandWithAddress,板子就会卡死,并且红灯亮起
经过定位是我加入了中断的相关功能后出现的

根据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

我认为是我在擦/写时被中断打断后,中断读取存放在Bank 0中的代码,导致了CPU Stall而卡死
于是我在擦除和读写的过程中都关闭了中断,问题暂时得到了解决。
2. 
因为不希望是一个死循环,根据数据手册里提供的最大擦除/写入时间,我希望检测当前等待的时间是否已经超过数据手册提供的最大值
于是在进入while循环前,我获取了一个startTime, 并在while里每次获取currTime并作差判断经过时间是否已经超过最大时间,若超过则返回异常退出
在这样实现后,我发现板子再次卡死,经过定位,依然是在调用Fapi_issueAsyncCommandWithAddress后卡死
判断应该还是之前的问题,在对当前的Bank进行擦写的时候,读当前的Bank会导致CPU Stall
3.
猜测之前能够正常进行的原因,是Erase Wait (写对应Program Wait)函数里只有一个死循环while,函数足够小,它被预取到ICache中,所以在执行时不需要访问Bank 0
而让我恰好能够顺利执行。
为了验证我的想法,我在启动阶段,对Cache的使能进行了修改。
在Cache Enable的情况下,我可以顺利完成擦写
在Cache Disable的情况下, 在调用了Fapi_issueAsyncCommandWithAddress后,板子就会卡死,并且红灯亮起
这证明了我的想法。
现在的疑惑点是,

(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

这两句话中有提到,读取时若当前Bank正在擦写,CPU会Stall,直到擦写完成,FMSTAT的BUSY位为0,才会继续。

这里的继续是如何实现的? 是当前的机制会自己让CPU继续,还是通过什么方法通知CPU,让CPU继续进行读取

我需要在同一个Bank上执行并擦写,是否有什么解决方案

谢谢