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.

CCS/TMS570LS0432: Implementing a Bootloader, after call to Fapi_issueProgrammingCommand() FMSTAT indicates that a sector is locked.

Part Number: TMS570LS0432


Tool/software: Code Composer Studio

I am implementing a Bootloader based on QJ Wang's boot_uart example. After call to Fapi_issueProgrammingCommand() FMSTAT indicates that a sector is locked.

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;
    uint32_t uwTemp = 0;

    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_FsmReady );
        while( FAPI_GET_FSM_STATUS != Fapi_Status_Success );
    }

    while( bytes_remain > 0)
    {
         uwTemp = Fapi_issueProgrammingCommand((uint32_t *)dst,    // dst = 0x00020000
                                              (uint8_t *)src,                                                        // src = 0x080030B8
                                              (uint32_t) bytes,                                                    // bytes = 16
                                              0,
                                              0,
                                              Fapi_AutoEccGeneration);
        if (uwTemp != Fapi_Status_Success)
        {
            return uwTemp;
        }

         while( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy );

         while(FAPI_GET_FSM_STATUS != Fapi_Status_Success)
         {
             uwTemp = FAPI_GET_FSM_STATUS;

// hangs here as uwTemp is 0x00000011
// bit 0 indicates that the sector is locked.

         }

        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
        UART_putString(UART, "\r Programmed the flash: ");
        UART_send32BitData(UART, Size_In_Bytes);
        UART_putString(UART, "   Bytes. \r ");
#endif
    status =  Flash_Program_Check(Flash_Start_Address, Data_Start_Address, Size_In_Bytes);

    return (status);
}

Your advice is much appreciated.

        ken

  • Hello Ken,

    Please enable all the sector in the flash bank.

    Only 8 sector are enabled in your code, and 0x20000 is sector 13. Please use the following API call to enable all the sectors:

    Fapi_enableMainBankSectors(0xFFFF);
  • That did the trick. Thanks!

    That begs the question, should I disable the block sectors when done?

  • Hi Ken,

    The sector enable bits are cleared automatically after reset. You don't have to disable the sectors when done flash erase/program operations.

  • When I jump to my application at address 0x00020000 after uploading my .bin file my application does not launch. If I suspend execution Code Composer shows "Break at address "0x2000c" with no debug information available, or outside of program code.

    If I view bytes 0x00020000 and after they match what I downloaded (at least the first 250 or so bytes and some random samples).

    If I upload the application from Code Composer and run the bootloader it launches my application successfully. I then review 0x0002000 using the Memory Browser and it matches what I uploaded using the bootloader. Any ideas why I would get different results when the executable appears to be the same?

    Thanks,

    ken
  • Found it... My error reading the .bin file.
  • Nice to know you have solved the problem. Thanks

  • OK, one last question, I promise...

    In my application I implemented a Modbus register for warm-booting to the bootloader. When modbus writes a magic number to this register the application should do a warmboot into the bootloader where it waits for a command from the upgrade program on my PC.

    I have not found how to do a warm-boot or any other transfer to the bootloader from my application.

    I've seen posts that say to set bits 14 and 15 in systemREG1->SYSECR. That did not work. My app hung looping in prefetchEntry.

    Our devices will be mounted in inconvenient and oft times dangerous locations. We cannot ask our customers to push a button on the device. They must be able to do a firmware upgrade over RS-485.

    Your assistance is appreciated.
  • Hi Ken,

    Normally we use bits 14 and 15 in systemREG1->SYSECR to reset the device after application is updated through the bootloader. The prefetch error may be caused by the ECC error or by an instruction that is trying to access a protected memory location.