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.

TMS570LS3137: SPI Bootloader

Part Number: TMS570LS3137

Tool/software:

Hello,

Im trying to flash the microcontroler via SPI, (from a conected external memory).

Using the application notes provided:

SPI Bootloader for Hercules TMS570LS31X MCU (ti.com) 


I have moodified this function to flash from the data reead in the external memories and not as packets recived via SPI,
however im having a issue with the function Fapi_BlockProgram. 

the program gets stucked in this line 
"while( FAPI_GET_FSM_STATUS != Fapi_Status_Success );"

I can provide all the code if you wish.

bl_spi.c

//*****************************************************************************
//
// bl_spi.c - Functions used to transfer data via the SPI port.
// Author         : QJ Wang. qjwang@ti.com
// Date           : 9-19-2012
//
// Copyright (c) 2006-2011 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
// 
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
//*****************************************************************************

#include "bl_config.h"

#include "bl_commands.h"
#include "bl_spi_packet.h"
#include "bl_spi.h"
#include "Registers_FMC_LE.h"
#include "system.h"
#include "bl_flash.h"
#include "hw_spi.h"
#include "sci_common.h"
#include "bl_led_demo.h"

uint8_t g_ucStatus;

extern uint32_t transferAddress;
extern uint32_t transferSize;
extern uint32_t g_ulUpdateStatusAddr;
extern uint32_t g_ulUpdateBufferSize;  //32 bytes or 8 32-bit words

extern uint32_t g_pulUpdateSuccess[8];

#include "fram.h"
#include "general_def.h"

#define PAGE_LENGTH           16

void readPageFromExtMem(uint8_t FRAM, uint32_t packetNr, uint32_t dataDir, uint8_t *returnDir);
uint16_t rExtMem(uint32_t address, uint8_t cs, bool delay);

void cast8to32(uint8_t *dataIn, uint32_t *dataOut){
    uint8_t littleEndian = 0;
    if (littleEndian)
        *dataOut = ((uint32_t)dataIn[3] << 24) | ((uint32_t)dataIn[2] << 16) | ((uint32_t)dataIn[1] << 8) | ((uint32_t)dataIn[0]);
    else
        *dataOut = ((uint32_t)dataIn[0] << 24) | ((uint32_t)dataIn[1] << 16) | ((uint32_t)dataIn[2] << 8) | ((uint32_t)dataIn[3]);
}

#define UPD_STATUS_BANK    0
#define UPD_BANK           1

enum STATUS {
    Success = 1,
    Fail    = 0
};

void UpdaterSPI(spiBASE_t *node) {
    uint32_t dataDir = APP_BANK_B;
    uint32_t dataInMem_32[PAGE_LENGTH*2];
    uint8_t  dataInMem_8[PAGE_LENGTH*8];
    uint16_t NrPages, statusOk;
    uint32_t FLASH_FIRST_SECTOR_SIZE;
    uint8_t  i;
    uint8_t  ulSize = PAGE_LENGTH*2;
    transferAddress = APP_START_ADDRESS;

    uExtMem(FRAM1);
    NrPages = rExtMem(APP_BANK_B_LEN, FRAM1, true);
    sExtMem(FRAM1);

    transferSize    = ulSize*NrPages;

    FLASH_FIRST_SECTOR_SIZE = BLInternalFlashFirstSectorSizeGet();

    if(transferSize > FLASH_FIRST_SECTOR_SIZE) {
        sciSend(scilinREG, 22, "\n\rProgram Flash failed");
        sciSend(scilinREG, 18, "\n\r\tFile to large\n\r");
        return;
    }

    sciSend(scilinREG, 17, "\n\rNr of pages: 0x");
    sciDisplayData(scilinREG, (uint8 *) &NrPages, 2);
    sciSend(scilinREG,  2, "\n\r");

    while(transferSize) {
        sciSend(scilinREG, 18, "\n\rPackets left: 0x");
        sciDisplayData(scilinREG, (uint8 *) &transferSize, 4);

        readPageFromExtMem(FRAM1, PAGE_LENGTH, dataDir, dataInMem_8);

        for(i = 0; i < PAGE_LENGTH*2; i++){
            cast8to32(dataInMem_8+(i*4), dataInMem_32+i);
        }

        statusOk = !Fapi_BlockProgram(UPD_BANK, transferAddress, (uint32_t)dataInMem_32, ulSize);
        //the program does not move beyond this point

        if (!statusOk) {
            sciSend(scilinREG, 22, "\n\rProgram Flash failed");
            return;
        }

        dataDir         += ulSize*4;
        transferAddress += ulSize;
        transferSize    -= ulSize;
    }

    sciSend(scilinREG, 36, "\n\r\n\rApplication load was successful!");

    statusOk = !Fapi_UpdateStatusProgram(UPD_STATUS_BANK, g_ulUpdateStatusAddr, (uint32_t)&g_pulUpdateSuccess[0], g_ulUpdateBufferSize);

    if (statusOk) {
        sciSend(scilinREG, 17, "\n\r\n\rReseting...\n\r");
        systemREG1->SYSECR = (0x10) << 14;
        // The microcontroller should have reset, so this should never be reached.
        while(1){}
    }
}
...............
 

  • Hi Marco,

    Are you saying your code got stuck at below line?

    I don't see any issues in your code to get it stuck in "Fapi_BlockProgram".

    Just make sure you are passing correct SYS_CLK_FREQ in "Fapi_BlockProgram".

    And i created one example project with your inputs and i am able to successfully write to the bank-1 without any issues:

    As you can see i am able to right into the flash without any issues.

    I am attaching my project for your reference:

    FAPI_BANK1_TEST_LS3137.zip

    --
    Thanks & regards,
    Jagadish.

  • Running a minnimal example, im having ths same problem,
    the first run goes well, but on the second one, it gets stucked.
    Here is the code, i also have sent the full file to you in a privete message.

    bl_main.c
    
    
    #include "hal_stdtypes.h"
    #include "bl_config.h"
    #include "bl_spi.h"
    #include "hw_spi.h"
    #include "system.h"
    #include "sci_common.h"
    #include "bl_led_demo.h"
    
    uint32_t transferAddress; /*  Address that is being written to. */
    
    void main(void){
        uint32_t flashRequired = 1;
    
    	sciInit();
    	sciSend(scilinREG, 24, "OBC BootLoader program\n\r");
    
        if(flashRequired){
            sciSend(scilinREG, 23, "\n\rProgram Flash begin\n\r");
            spiInit();
            UpdaterSPI(SPI_PORT);
        }
    
        sciSend(scilinREG, 24, "\n\rJump to application...");
    
        transferAddress = (uint32_t)APP_START_ADDRESS;
        ((void (*)(void))transferAddress)();
    }
    bl_spi.c
    
    
    extern uint32_t transferAddress;
    
    #include "fram.h"
    #include "general_def.h"
    
    #define PAGE_LENGTH           16
    #define UPD_STATUS_BANK    0
    #define UPD_BANK           1
    
    void readPageFromExtMem(uint8_t FRAM, uint32_t dataDir, uint32_t *returnDir);
    uint16_t rExtMem(uint32_t address, uint8_t cs, bool delay);
    void cast8to32(uint8_t *dataIn, uint32_t *dataOut);
    
    uint8_t dataInMem_32[16*2] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
    uint16_t nrPages = 5;
    uint16_t statusOk;
    
    void UpdaterSPI(spiBASE_t *node) {
        uint32_t dataDir = APP_BANK_B;
        uint32_t FLASH_FIRST_SECTOR_SIZE;
        uint8_t  ulSize = PAGE_LENGTH*2;
    
        FLASH_FIRST_SECTOR_SIZE = BLInternalFlashFirstSectorSizeGet();
        transferAddress = APP_START_ADDRESS;
    
        if((ulSize*nrPages) > FLASH_FIRST_SECTOR_SIZE) {
            sciSend(scilinREG, 22, "\n\rProgram Flash failed");
            sciSend(scilinREG, 18, "\n\r\tFile to large\n\r");
            return;
        }
    
        sciSend(scilinREG, 23, "\n\rTotal nr of pages: 0x");
        sciDisplayData(scilinREG, (uint8 *) &nrPages, 2);
        sciSend(scilinREG,  2, "\n\r");
    
        while(nrPages--) {
    
            statusOk = !Fapi_BlockProgram(UPD_BANK, transferAddress, (uint32_t)dataInMem_32, ulSize);
            //the program does not move beyond this point
    
            if (!statusOk) {
                sciSend(scilinREG, 22, "\n\rProgram Flash failed");
                return;
            }
    
            sciSend(scilinREG, 16, "\n\rPages left: 0x");
            sciDisplayData(scilinREG, (uint8 *) &nrPages, 2);
    
            dataDir         += ulSize*4;
            transferAddress += ulSize;
        }
    
        sciSend(scilinREG, 36, "\n\r\n\rApplication load was successful!");
    
        sciSend(scilinREG, 17, "\n\r\n\rReseting...\n\r");
        systemREG1->SYSECR = (0x10) << 14;
        while(1){
            // The microcontroller should have reset, so this should never be reached.
        }
    }
    ...........


  • Hi Marco,

    Did you test my code directly, is it executing successfully?

    What is your start address, is it 0x00180000?

    And can you please also share your linker cmd file? If possible share complete project? You can also send it through private chat, if required.

    Regards,

    Jagadish.

  • I have provided you the full code through private chat.

  • Hi Macro Mecha,

    I don't understand exactly what is the root cause, i took the SPI bootloader code in application notes and i directly modified the UpdaterSPI to directly write into the flash on bank1.

    And still i don't see any issues in writing.

    So, i am attaching my code for reference, just try to replace the bl_spi.c file i shared with your file and see whether you were able to write into the flash or not.

    5732.SafetyMCU_Bootloader.zip

    --
    Thanks & regards,
    Jagadish.

  • The thing is that i also changed a few configurations of the spi, in order to use it as needed, it was working correcly but now, after some changes, it's not working. Im going to see if i can change it back an test where the problem is. 

  • Im going to see if i can change it back an test where the problem is. 

    Please try it from your end first, if you are unable to find the root cause for the problem then we will setup live debugging session based on the observations.