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.

Write Bank 0 Hercules TMS570ls3137 ?

Other Parts Discussed in Thread: TMS570LS3137

CCS:5.4

F021 Flash API: 2.01.01

I am testing writing internal flash of TMS570ls3137 with FAPI.

I am using functions in bl_flash.c for erasing and writing to the flash.

I got this file from : https://e2e[dot] ti [dot] com/support/microcontrollers/hercules/f/312/t/286222

When I try to write on address 0x00180000 of bank1 everything works ok but if i repeat same process for address 0X000C0000, nothing happens

I read all 0xFFFF (blank) in memory (sometimes BAD0BAD0) and API goes in infinite loop on line

while(FAPI_GET_FSM_STATUS!= Fapi_Status_Success)

. As per customer requirement I need to write in bank0 using FAPI.

I have modified the cmd file to accommodate the FAPI section and using  _copyAPI2RAM function for running API on RAM.

While debugging I observe that FAPI is correctly copied to RAM & PC register has address of RAM during FAPI function calls.

What did I miss? Please Help, I am stuck here.

/////////////////////////////////bl_link.cmd///////////////////////////////////////////

--retain="*(.intvecs)"


MEMORY
{
    VECTORS    (X)   : origin=0x00000000 length=0x00000200
    BOOT_LOAD  (RX)  : origin=0x00000200 length=0x00001000
    FLASH_API  (RX)  : origin=0x00001200 length=0x00001000
    FLASH0     (RX)  : origin=0x00002200 length=0x00018000
    SRAM       (RW)  : origin=0x08002000 length=0x00004000
    STACK      (RW)  : origin=0x08000000 length=0x00002000
}
SECTIONS
{
   .intvecs : {} > VECTORS

   boot_code :    {src\sys_core.obj    (.text)}  > BOOT_LOAD
   eabi_start :   {src\sys_startup.obj (.text)}  > BOOT_LOAD

   flashAPI :
   {
     //..\Debug\src\Fapi_UserDefinedFunctions.obj (.text)
     ..\Debug\src\bl_flash.obj (.text)
     //..\Debug\src\ccrs\peripherals\McuFlash08.obj (.text)
     //..\Debug\src\main.obj (.text)


     --library=F021_API_CortexR4_BE.lib < FlashStateMachine.IssueFsmCommand.obj
                                           FlashStateMachine.SetActiveBank.obj
                                           FlashStateMachine.InitializeFlashBanks.obj
                                           FlashStateMachine.EnableMainSectors.obj
                                           FlashStateMachine.IssueFsmCommand.obj
                                           FlashStateMachine.ScaleFclk.obj
                                           Init.obj
                                          Utilities.CalculateEcc.obj
                                          Utilities.WaitDelay.obj
                                          Utilities.CalculateFletcher.obj
                                          Read.MarginByByte.obj
                                          Read.Common.obj
                                          Read.FlushPipeline.obj
                                           Read.WdService.obj
                                          Async.WithAddress.obj
                                          Program.obj > (.text)
   } load = FLASH_API, run = SRAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)

   .text  > FLASH0
   .const > FLASH0
   .cinit > FLASH0
   .pinit > FLASH0
   .data  > SRAM
   .bss   > SRAM
   .sysmem > SRAM
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////Writing function(called from main)/////////////////////

uint32_t Fapi_BlockProgram( uint32_t Bank, uint32_t Flash_Start_Address, uint32_t Data_Start_Address, uint32_t Size_In_Bytes)
{
    register uint32_t src = Data_Start_Address;
    register uint32_t dst = Flash_Start_Address;
    register uint32_t bytes_remain = Size_In_Bytes;
    uint8_t  i, ucBank;
    uint32_t status;
    uint32_t bytes;
    uint32_t Freq_In_MHz;


    Freq_In_MHz = SYS_CLK_FREQ;

    if (Size_In_Bytes < 16)
        bytes = Size_In_Bytes;
    else
        bytes = 16;

    for (i = 0; i < NUMBEROFSECTORS-1; i++){
        if (Flash_Start_Address < (uint32_t)(flash_sector[i+1].start))
        {
            ucBank     = flash_sector[i].bankNumber;
            break;
        }
    }

    if(( Flash_Start_Address == APP_START_ADDRESS ) || ( ucBank == 1 )){
        Fapi_initializeFlashBanks(Freq_In_MHz); /* used for API Rev2.01 */

        Fapi_setActiveFlashBank((Fapi_FlashBankType)ucBank);

        Fapi_enableMainBankSectors(0xFF);        /* used for API 2.01*/

        while( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy );
        while( FAPI_GET_FSM_STATUS!= Fapi_Status_Success );
    }

    while( bytes_remain > 0)
    {
        Fapi_issueProgrammingCommand((uint32_t *)dst,
                                     (uint8_t *)src,
                                     (uint32_t) bytes,
                                     0,
                                     0,
                                     Fapi_AutoEccGeneration);

         while( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy );
        while(FAPI_GET_FSM_STATUS!= Fapi_Status_Success);

        src += bytes;   //Size_In_Bytes;
        dst += bytes; //Size_In_Bytes;
        bytes_remain -= bytes; //Size_In_Bytes;
        if ( bytes_remain < 16){
           bytes = bytes_remain;
        }
    }

#ifdef DEBUG_MSG_L3

        myprintf("\r Programmed the flash:%d Bytes",Size_In_Bytes);

#endif
    status =  Flash_Program_Check(Flash_Start_Address, Data_Start_Address, Size_In_Bytes);

    return (status);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////Function Call in main/////////////////////////////////////

#define WR_ADDR  0x000C0000
#define BANK      Fapi_FlashBank0

unsigned char pucProgTest[0x100];
    for(i=0 ; i<0x100; i++)
        pucProgTest[i] = i;

    Fapi_BlockProgram(BANK, (uint32_t) WR_ADDR, pucProgTest, 0x10);

//////////////////////////////////////////////////////////////////////////////////////////////////////////

  • Nirav,

    Should be possible and every time you download your program with CCS it is using the API behind the scenes to write to bank 0.

    Normally the problem people have would be:
    a) is the MPU setup to allow for execution of code from SRAM? (make sure it's not execute never attribute)
    b) is some exception occurring like an interrupt (you should have IRQ's disabled.. ex. RTI)
    interrupts are a problem because the vector table is fixed and is always in bank 0 so if an interrupt occurs while this bank is being
    programmed there will be a problem... the code at the exception vector will not be available.
  • I tried disabling the MPU using _mpuDisable_(); and disabling Interrupts altogether using _disable_interrupt_();
    Still no use, It hangs on
    while(FAPI_GET_FSM_STATUS!= Fapi_Status_Success).

    Anything else I can try?
    I am really stuck here.

    Regards

  • Nirav,

    What does FAPI_GET_FSM_STATUS return? Maybe that will help figure out what is going on.
  • Sir

    Now we are able to write a counter of say 0x100 on Bank 0, but when we attempt to use the same routine for writing the binary(52KB) using bootloader code we get FMSTAT as 0x11. (SLOCK ,CSTAT is set)

    As oppose to this when we write counter we get FMSTAT as 0  and everything works fine.

    When we write counter

    When we write binary

    CMD File:

    --retain="*(.intvecs)"


    MEMORY
    {
        VECTORS    (X)   : origin=0x00000000 length=0x00000200
        BOOT_LOAD  (RX)  : origin=0x00000200 length=0x00001000
        FLASH_API  (RX)  : origin=0x00001200 length=0x00001000
        FLASH0     (RX)  : origin=0x00002200 length=0x000bde00
        FLASH1     (RX)  : origin=0x00180000 length=0x00018000
       SRAM       (RW)  : origin=0x08003000 length=0x0003CFFC
       STACK      (RW)  : origin=0x08000000 length=0x00003000
    }
    SECTIONS
    {
       .intvecs : {} > VECTORS

       boot_code :    {src\sys_core.obj    (.text)}  > BOOT_LOAD
       eabi_start :   {src\sys_startup.obj (.text)}  > BOOT_LOAD

       flashAPI :
       {
         //..\Debug\src\Fapi_UserDefinedFunctions.obj (.text)
         ..\Debug\src\bl_flash.obj (.text)
        // ..\Debug\src\ccrs\peripherals\McuFlash08.obj (.text)


         --library=F021_API_CortexR4_BE.lib < FlashStateMachine.IssueFsmCommand.obj
                                               FlashStateMachine.SetActiveBank.obj
                                               FlashStateMachine.InitializeFlashBanks.obj
                                               FlashStateMachine.EnableMainSectors.obj
                                               FlashStateMachine.IssueFsmCommand.obj
                                               FlashStateMachine.ScaleFclk.obj
                                               Init.obj
                                              Utilities.CalculateEcc.obj
                                              Utilities.WaitDelay.obj
                                              Utilities.CalculateFletcher.obj
                                              Read.MarginByByte.obj
                                              Read.Common.obj
                                              Read.FlushPipeline.obj
                                               Read.WdService.obj
                                              Async.WithAddress.obj
                                              Program.obj > (.text)
       } load = FLASH_API, run = SRAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)

       .text  > FLASH0
       .const > FLASH0
       .cinit > FLASH0
       .pinit > FLASH0
       .data  > SRAM
       .bss   > SRAM
       .sysmem > SRAM
    }

    Please help.

    Regards

  • Piyush Ashtikar.(piyush.ashtikar@bitmapper.com,piyushashtikar@outlook.com)

    With some experiments bootloader worked for me (tms570ls3137 FAPI 2.01.01).

    Thank you.

    In case anyone is struggling with FAPI F021, Please find attached working relevant files.

    Some points to note:

    1.Disable interrupts while programming and erasing.

    2.Copy FAPI library to RAM and run it from there.

    3.Use functions in bl_flash.c for erasing and programming.

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    --retain="*(.intvecs)"


    MEMORY
    {
        VECTORS    (X)   : origin=0x00000000 length=0x00000200
        BOOT_LOAD  (RX)  : origin=0x00000200 length=0x00001000
        FLASH_API  (RX)  : origin=0x00001200 length=0x00001000
        FLASH0     (RX)  : origin=0x00002200 length=0x000bde00
        FLASH1     (RX)  : origin=0x00180000 length=0x00018000
        SRAM       (RW)  : origin=0x08002000 length=0x0003DFF0
        STACK      (RW)  : origin=0x08000000 length=0x00002000
       //SRAM       (RW)  : origin=0x08003000 length=0x0003CFFC
       //STACK      (RW)  : origin=0x08000000 length=0x00003000
    }
    SECTIONS
    {
       .intvecs : {} > VECTORS

       boot_code :    {src\sys_core.obj    (.text)}  > BOOT_LOAD
       eabi_start :   {src\sys_startup.obj (.text)}  > BOOT_LOAD

       flashAPI :
       {
         //..\Debug\src\Fapi_UserDefinedFunctions.obj (.text)
         ..\Debug\src\bl_flash.obj (.text)
        // ..\Debug\src\ccrs\peripherals\McuFlash08.obj (.text)


         --library=F021_API_CortexR4_BE.lib < FlashStateMachine.IssueFsmCommand.obj
                                               FlashStateMachine.SetActiveBank.obj
                                               FlashStateMachine.InitializeFlashBanks.obj
                                               FlashStateMachine.EnableMainSectors.obj
                                               FlashStateMachine.IssueFsmCommand.obj
                                               FlashStateMachine.ScaleFclk.obj
                                               Init.obj
                                              Utilities.CalculateEcc.obj
                                              Utilities.WaitDelay.obj
                                              Utilities.CalculateFletcher.obj
                                              Read.MarginByByte.obj
                                              Read.Common.obj
                                              Read.FlushPipeline.obj
                                               Read.WdService.obj
                                              Async.WithAddress.obj
                                              Program.obj > (.text)
       } load = FLASH_API, run = SRAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)

       .text  > FLASH0
       .const > FLASH0
       .cinit > FLASH0
       .pinit > FLASH0
       .data  > SRAM
       .bss   > SRAM
       .sysmem > SRAM
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    5811.bl_flash.c

  • HI Nirav:

    I just lean the chip of tms570 ,and i have the same problem like yours . becasue i am a student and  not  familiar this chip . so i wana know can you give me your bootloader temp .thank you very much!!!

    if you can please send email to me :

    liyida1973@gmail.com

    thank you very very much!!!

  • Hi Nirav,

    I am facing some problems when i try to erase or program Bank 0, basically each time i write something the chip is somehow restarted. Any hints?

    regards,
    Hany