型号:TMS570LS3137
使用HAL CODE生成的驱动代码以及F021库F021_API_CortexR4_BE_L2FMC_V3D16.lib 擦除和烧写FLASH BANK0 BANK1 BANK7不成功。
但是根据官方文档编写的例程,程序显示擦除和烧写成功,不知道为什么?
备注:芯片OSC:16M,HCLK:180M
代码如下:
/* @brief 擦除块
* @param[in] oNewFlashBank:块编号
*
* return:
*/
enum e_flash_status Flash_EraseBanks(Fapi_FlashBankType oNewFlashBank)
{
int num = 0;
Fapi_StatusType oReturnCheck = Fapi_Status_Success;
num = find_sector(oNewFlashBank, 0);
oReturnCheck = Fapi_initializeFlashBanks(180); //初始化Flash Bank以进行API操作
if((oReturnCheck == Fapi_Status_Success) && (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY != Fapi_Status_FsmBusy))
{
oReturnCheck = Fapi_setActiveFlashBank(oNewFlashBank); //设置活动的Flash Bank
if( (oNewFlashBank == Fapi_FlashBank0) || (oNewFlashBank == Fapi_FlashBank1) )
oReturnCheck = Fapi_enableMainBankSectors( 0xffffffff ); //设置EEPROM存储区中可用的扇区以进行擦除和编程
else if( oNewFlashBank == Fapi_FlashBank7 )
oReturnCheck = Fapi_enableEepromBankSectors(0xffffffff, 0xffffffff); //设置EEPROM存储区中可用的扇区以进行擦除和编程
while(FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy);
Fapi_issueAsyncCommandWithAddress(Fapi_EraseBank, gSector_List[num].low_addr); //向Flash状态机发出命令
/* Place specific example code here */
/* Wait for FSM to finish */
while(FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy);
/* Check the FSM Status to see if there were no errors */
if (FLASH_CONTROL_REGISTER->FmStat.u32Register != 0)
{
/* Put Error handling code here */
return flash_failure;
}
}
return flash_succeed;
}
/* @brief 写扇区数据
* @param[in] oNewFlashBank:块编号
* @param[in] sector:扇区编号
* @param[in] offset:扇区偏移地址
* @param[in] buff:数据
* @param[in] len:数据长度
*
* return:
*/
enum e_flash_status Flash_WriteData(Fapi_FlashBankType oNewFlashBank, uint32_t sector, uint32_t offset, uint8_t * buff, uint32_t len)
{
int num = 0;
Fapi_StatusType oReturnCheck = Fapi_Status_Success;
num = find_sector(oNewFlashBank, sector);
//如果写的大小起过扇区的大小
if( (offset+len) > gSector_List[num].size )
{
return flash_failure;
}
oReturnCheck = Fapi_initializeFlashBanks(180); //初始化Flash Bank以进行API操作
if((oReturnCheck == Fapi_Status_Success) && (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY != Fapi_Status_FsmBusy))
{
oReturnCheck = Fapi_setActiveFlashBank(oNewFlashBank); //设置活动的Flash Bank
if( (oNewFlashBank == Fapi_FlashBank0) || (oNewFlashBank == Fapi_FlashBank1) )
oReturnCheck = Fapi_enableMainBankSectors( 0xffffffff ); //设置EEPROM存储区中可用的扇区以进行擦除和编程
else if( oNewFlashBank == Fapi_FlashBank7 )
oReturnCheck = Fapi_enableEepromBankSectors(0xffffffff ,0xffffffff); //设置EEPROM存储区中可用的扇区以进行擦除和编程
while(FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy);
Fapi_issueProgrammingCommand(gSector_List[num].low_addr+offset, buff, len, 0, 0, Fapi_DataOnly); //设置数据并将程序命令发送到有效的闪存地址
/* Place specific example code here */
/* Wait for FSM to finish */
while(FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy);
/* Check the FSM Status to see if there were no errors */
if (FLASH_CONTROL_REGISTER->FmStat.u32Register != 0)
{
/* Put Error handling code here */
return flash_failure;
}
}
return flash_succeed;
}