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: TSM570LC4357 How to Remove APP_STATUS_ADDRESS Flag

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN,

Hello,

I am using Ethernet Bootloader which designed from QJ Wang and its perfectly working fine.

But as I understand the code , Mr.Wang at the first check two conditions, is button pressed  and is flag filled(APP_STATUS_ADDRES) with  0x5A5A5A5A.

If two conditions are satisfied new image will be loaded. Everything is fine but, my purpose is ; 

When I upload my new image, if I press a button e.g PortB5(still assuming that I am inside new image)

I want to fill APP_STATUS_ADRESS with 0xFFFFFFFF . Why?

Because when I press button from new image , new image will remove flag(from APP_STATUS_ADRESS), and I will go to the 0x000000 adress(to the bootloader). Therefore, bootloader will think there is no new image so that bootloader will not go to the new image.

All I need just how to remove this 0x5A5A5A5A flag from APP_STATUS_ADRESS

Thanks in advance.

Abdulmecid Pamuk

Best regards,

  • Hi Abdulmecid,

    To remove the flag (0x5A5A5A5A), you have to erase the whole flash sector. 

  • When I upload my new image with FAPI functions , bootloader don't jump to new image.

    inside new image I just tried to initialize flash banks as you can see in my code.

    Without FAPI functions (in new image) , program works fine. ( I put comment where I call the function).

    Why my image doesn't run when I try to call FAPI functions?.

    BTW, I am using same FAPI lib in bootlader for my new image which is F021_API_CortexR4_BE_L2FMC_V3D16.lib

    #include "HL_sys_common.h"
    #include "HL_gio.h"
    #include "F021.h"
    
    
    
    
    
    uint8	emacAddress[6U] = 	{0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};
    uint32 	emacPhyAddress	=	1U;
    
    #define BOOTLOADER_START_ADDR   0x0000000 // 
    #define UPDATE_STATUS_ADDR      0x0020000 // STATUS FLAG IN HERE...
    #define SYS_CLK_FREQ            150       // CLOCK FREQUENCY
    
    
    
    
    void main(void)
    {
    
    /* USER CODE BEGIN (3) */
    /* USER CODE END */
    
        gioInit();
        gioSetDirection(gioPORTB, 0xC0);
        int a = 0;
        gioSetBit(gioPORTB, 6, 1);
        gioSetBit(gioPORTB, 7, 1);
        while (1)
        {
            if (a == 500000)
            {
    
                a = 0;
            }
            if (!gioGetBit(gioPORTB, 5))
            {
    //            gioToggleBit(gioPORTB, 6);
    
                // IF I PUT THAT CONDITION , NEW IMAGE DON'T RUN!.
                // if I comment this condition works perfectly fine.
                if ((Fapi_initializeFlashBanks((uint32_t)SYS_CLK_FREQ)) == Fapi_Status_Success)
                {
                    gioSetBit(gioPORTB, 6, 0);
    
    
                }
                else
                {
                    gioSetBit(gioPORTB, 7, 0);
                }
    
            }
            a++;
        }
    }

  • In your new image, the F021 flash APIs should be executed from MCU SRAM.

  • So Mr.Wang, which settings I have to do I couldnt figure it out.

    By the way I was thinking our program allready executed in SRAM (when bootloader jumps to the image)

  • The bootloader is a nice example showing you how to copy the flash APIS to SRAM:

    1. linker cmd file: for example

    flashAPI:
    {
    .\source\Fapi_UserDefinedFunctions.obj (.text)
    .\source\bl_flash.obj (.text)
    --library= "c:\ti\Hercules\F021 Flash API\02.01.01\F021_API_CortexR4_BE.lib" (.text)
    } palign=8 load = FLASH0, run = SRAM, LOAD_START(apiLoadStart), RUN_START(apiRunStart), SIZE(apiLoadSize)

    2. in main()

     copy this section from flash to SRAM

    memcpy(&apiRunStart, &apiLoadStart, (uint32)&apiLoadSize);

  • Thank you Mr.Wang ,

    It means that I should put 

    memcpy(&apiRunStart, &apiLoadStart, (uint32)&apiLoadSize);

    command into my new image file (before that extern them)

    As a result of this, I can use Fapi functions right?

  • Yes, you can use the Flash API. but it doesn't solve your problem: remove the flag (0x5a5a5a5a).

    You may consider to use FEE driver to program the flag to EEPROM (bank 7). The HALCoGen generates FEE driver for bank 7 which is used as EEPROM.

    The HALCoGen help includes an example for using FEE driver:

    FEE user guide is located in HALCogen installation folder.

  • Mr.Wang thank you for the advise.

    However, when I add my Fapi functions in the new image and upload it via bootloaderbootloader jump to my new image but nothing is going to happen.

    When I remove fapi functions in new image and upload it via bootloader , bootloader jump and run new image correctly.

    I also did your suggestion, (memcpy things still didnt solved..) I still could figure it out why..

  • By the way, in the new image I can't define any static or global  variables.

    If I define any static or global variables ,  program doesn't run.

    If I don't define any static or global variables (only local inside main function) program is working properly.

    Mr.Wang, Can you explain this reason why I can't any global or static variables in new image?

    Thank you,

    Abdulmecid Pamuk

  • Where are the section .bss allocated in your lonker cmd file? The .bss is for the uninitialized global and static variables, and should be linked into SRAM. The initialized global and static variables can be linked into either flash or SRAM.

    The function __TI_auto_init() is used to initialize the C environment such as, global variables, static variables and C++ constructors. It is part of the TI ARM compiler. This function should be called in _c_int00_() before calling main().

  • the .bss section is allocated in RAM ,

    Note : (These info belongs to Application[not Bootloader] Linker Cmd file)

    .intvecs : {} > VECTORS
    .text align(32) : {} > FLASH1
    .const align(32) : {} > FLASH1
    .cinit align(32) : {} > FLASH1
    .pinit align(32) : {} > FLASH1
    .bss : {} > RAM
    .data : {} > RAM
    .sysmem : {} > RAM

    VECTORS (X) : origin=0x00200020 length=0x00000020
    FLASH0 (RX) : origin=0x00000000 length=0x00200020
    FLASH1 (RX) : origin=0x00200040 length=0x001FFFC0
    RAM (RWX) : origin=0x08002000 length=0x0007E000
    STACK (RW) : origin=0x08000000 length=0x00002000

    __TI_auto_init() function has been called in HL_sys_startup.c and I didn't change anything in that file (See the picture in igure 1.1)

                      Figure 1.1

    Without any static or global variables, when the bootloader jump to the new image, it works perfectly. However, when I put one or more static or global variables, bootloader jumps but nothing happens after jumping.

  • Mr.Wang please can you help me about that circumstance. Im in trouble with my company...

    Thank you,

  • Do you know which function or which instruction in your application gets stuck? One way to debug the application code is:

    1. Change the bootloader code to make it to jump to application unconditionally: add "fnRetValue = 0;" just before if(..)

    fnRetValue = CheckForceUpdate();

    fnRetValue = 0; //1-update, 0-jump to application

    if (!fnRetValue)
    {
         g_ulTransferAddress = (uint32_t)APP_START_ADDRESS;
         ((void (*)(void))g_ulTransferAddress)();
    }

    2. Then use CCS to load the application to the flash starting at 0x200020. Then add a breakpoint to your application code 

    3. Use CCS "System Reset" to re-start code execution from bootloader, then using step commands to navigate your application code

  • When I load the application with CCS  as you said , new image works properly I mean ,  although static or global variables defined , bootloader jumps  and everything works fine.

    However, when I flash the new image via bootloader, same problems occur as before.

    The source of the problem is inside __TI_auto_init();

    DEFINE_SPECIALIZATION(".text:__TI_auto_init_nobinit_nopinit")
    void __TI_auto_init_nobinit_nopinit(void)
    {
    __TI_auto_init_template(0, 0, NULL);
    }

    The program enters that function after that  program crashes at 203'rd line in autoinit.h  (Check Figure 2.1)

                             Figure 2.1

    Thank You

    Abdulmecid Pamuk

  • The same object file works fine if it is loaded using CCS, but gets stuck if it is loaded using bootloader. Can you dump the memory content and check if there are any differences? Are the global variables initialized or not? 

    Is the runtime library used a right one for TMS570LC4357 device? It should be rtsv7R4_T_be_v3D16_eabi.lib

    Can you share your application source code? I'd like to know how the global/static variables are declared and used?

    Please refer to the compiler user guide for information regarding using global variables.

    https://www.ti.com/lit/ug/spnu151v/spnu151v.pdf?ts=1630429412997&ref_url=https%253A%252F%252Fwww.google.com%252F

  • I’ll send tomorrow morning all documents, and regarding informationd Mr.Wang

  • Hello Mr.Wang,

    I checked runtime library for TMS570LC4357  and its correct.

    Then I compared memory dump as you said and I found three differences

    The first one ,  at 0x002042B4 (phantomInterrupt) (Not Completely different but different)

    Second one  , at  0x002044C0 (s_vim_init)             (Not Completely different but different) 

    Third one      , at  0x00200FE0 ($C$L16)                 (Not Completely different but different) 

    I'm sending my project with source code, and memory dumps including  (Flashing with Bootloader - Flashing with CCS)

    SIMPLE_LED_PROJECT.rar

    memoryDumps.rar

    Thank you

    Abdulmecid Pamuk

  • can you please help me about that situation I'm in trouble .. I have to overcome from that.

    Thank You,

    Abdulmecid Pamuk

  • Hello,

    I read your code. The main() contains only one global static variable. From the map file, 

    Second one  , at  0x002044C0  --> is __TI_static_base__

    Would you please add the following statement to linker cmd file and try:

    --undef_sym=__TI_static_base__

    Please find the description of --undef_sym: 

    https://www.ti.com/lit/ug/spnu118x/spnu118x.pdf

  • Hi Mr. 

    I added --undef_sym=__TI_static_base__ into my linker cmd file and still program doesn't work..

    By the way , I tried three possibilities.

    Firstly I added --undef_sym=__TI_static_base__ into only BOOTLOADER cmd file  but new image didnt work.

    Secondly , I added  --undef_sym=__TI_static_base__ into only new Image cmd file but new image  didnt work.

    Thirdly , I added --undef_sym=__TI_static_base__ into [BOOTLOADER and new Image] (both) cmd file but new image didnt work.

    How we can solve this problem Mr.Wang?

    I can't understand why we cannot declare static variable in new image?

    If you have chance Can you try my project into your LAUNCHPAD Mr.Wang?

    Best Regards,

    Abdulmecid Pamuk

  • When I load the application with CCS  as you said , new image works properly I mean ,  although static or global variables defined , bootloader jumps  and everything works fine.

    However, when I flash the new image via bootloader, same problems occur as before.

    Given that the application works when flashed with CCS, but not when flashed by the bootloader, the bootloader might be the issue.

    Can you also post the bootloader project?

    Note that the TMS570LC4357 has a cache, and if the cache is enabled before functions are copied from flash to SRAM then you can suffer failures unless the cache is cleaned before the functions copied to SRAM are called - see TMS570LC4357: Moving a function to RAM

  • Thank you for your reply Chester.

    I am sending ethernet bootloader project which doesn't work with static or global variables.

    BOOTLOADER_STATICS_DOESNT_WORK.rar

  • I am sending ethernet bootloader project which doesn't work with static or global variables.

    In the BOOTLOADER_STATICS_DOESNT_WORK.rar which was attached I think there is a typo in the boot loader code for the application start address.

    In the test_proj\source\HL_sys_link.cmd application the start address of the VECTORS section for the application is 0x00200020

    Whereas the Build-LAUNCHXL2-TMS570LC43x\Boot\bl_config.h has:

    //*****************************************************************************
    // The starting address of the application.  This must be a multiple of 32K(sector size)
    // bytes (making it aligned to a page boundary), and can not be 0 (the first sector is 
    // boot loader). 
    //
    // The flash image of the boot loader must not be larger than this value.
    //*****************************************************************************
    #define APP_START_ADDRESS       0x0020020
    //0x8
    
    //*****************************************************************************
    // The address to store the update status of the application image
    // It contains Application Start Address, Application Image Size, etc
    //
    //*****************************************************************************
    #define APP_STATUS_ADDRESS       0x0020000   /* This is must the starting address of one of flash sectors */

    What this means is that the boot loader is placing the application in a different address in flash to the address the application was linked for.

    ARM instructions can encode addresses as relative to the address of the instruction, so some code can still execute when loaded as a different address. However, the start up code to initialise static variables requires the code to loaded at the address the application was linked for.

    Having changed bl_config.h to the following:

    //*****************************************************************************
    // The starting address of the application.  This must be a multiple of 32K(sector size)
    // bytes (making it aligned to a page boundary), and can not be 0 (the first sector is 
    // boot loader). 
    //
    // The flash image of the boot loader must not be larger than this value.
    //*****************************************************************************
    #define APP_START_ADDRESS       0x00200020
    //0x8
    
    //*****************************************************************************
    // The address to store the update status of the application image
    // It contains Application Start Address, Application Image Size, etc
    //
    //*****************************************************************************
    #define APP_STATUS_ADDRESS       0x00200000   /* This is must the starting address of one of flash sectors */
    

    The application gets further, but gets an abort in the __TI_auto_init_nobinit_nopinit() function on the following line:

            char        handler_idx = *load_addr++;

  • Then I compared memory dump as you said and I found three differences

    I have found an issue in how the bin file is generated using the Arm Hex Utility by the TI v20.2.5.LTS compiler.

    The following shows the result of running the cgxml utility to report the initialized sections in the application .out file:

    "c:\Program Files (x86)\ti\cgxml-2.61.00\utils\ofd6x" -x -g test_proj.out | "c:\Program Files (x86)\ti\cgxml-2.61.00\bin\sectti.exe"
    Reading from stdin ...
    
    ************************************************************
    REPORT FOR FILE: test_proj.out
    ************************************************************
                    Name : Size (dec)  Size (hex)  Type   Load Addr   Run Addr
    -------------------- : ----------  ----------  ----   ----------  ----------
                .intvecs :         32  0x00000020  CODE   0x00200020  0x00200020
                   .text :      17008  0x00004270  CODE   0x00200040  0x00200040
                  .const :        512  0x00000200  DATA   0x002042c0  0x002042c0
                  .cinit :         28  0x0000001c  DATA   0x002044c0  0x002044c0
                   .data :          8  0x00000008  UDATA  0x08008000  0x08008000
    
    ------------------------------------------------------------
    Totals by section type
    ------------------------------------------------------------
      Uninitialized Data :          8  0x00000008
        Initialized Data :        540  0x0000021c
                    Code :      17040  0x00004290

    Looking at the addresses in the loadable sections:

    Usage Size Start address Address range
    .intvecs section  0x00000020  0x00200020 0x00200020 .. 0x0020003F
    .text section 0x00004270 0x00200040 0x00200040 .. 0x002042AF
    <hole> 0x00000010 0x002042BO 0x002042BO .. 0x002042BF
    .const section 0x00000200 0x002042c0 0x002042C0 .. 0x002044BF
    .cinit section 0x0000001c 0x002044c0 0x002044C0 .. 0x002044DB

    The size of the test_proj.bin file created by the armhex utility is 17580 bytes (0x44AC) which is the sum of the .intvecs, .text, .const and .cinit sections. The problem is that the armhex utility has skipped the hole between the .text and .const sections which results in the .const and .cinit sections being in the incorrect addresses in the binary file.

    I had previously reported this issue in armhex from v20.2.4 can create incorrect binary output, without filling holes, if just the --binary option is used

    To get a correct bin file generated in the CCS Project Properties:

    1. Disable the Arm Hex Utility

    2. Under Build -> Steps create a post-build step containing:

    "${CCE_INSTALL_ROOT}/utils/tiobj2bin/tiobj2bin" "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin" "${CG_TOOL_ROOT}/bin/armofd" "${CG_TOOL_ROOT}/bin/armhex" "${CCE_INSTALL_ROOT}/utils/tiobj2bin/mkhex4bin"

    With the above change:

    1. The generated test_proj.bin was now the expected size of 17,596 bytes
    2. Once the boot loader had flashed test_proj.bin the application successfully started (as shown by LED3 lighting)
    3. After the boot loader has flashed test_proj.bin then the CCS debugger could successfully verify the test_proj.out file in flash, where as previously when armhex was used to create the bin file the verification failed.
  • Hello chester, I am going to do whole reports check & test  in Monday, I will inform you.

    Thank you,

    Abdulmecid Pamuk

  • Hello Mr. Gillon,

    I tried your suggestion and everything works fine (When static or global variables defined in the new image everyhing works fine.)

    However, I have another interesting problem.

    In bootloader when I  write Flash something inside same bank there is no problem, (In Example Im writing Bank0, Section15)

    But, in the new image when I try to write something inside same bank (Image starts in Bank1, Section1 , [Attempting to write Bank1,Section0] ) program is not responding. If I try to write something from new image  to (Bank0,Section15) there is no problem.

    HERCULE.rar -> Bootloader Project

    test_proj.rar   -> Led Project with FAPI

    ---------------------------------------------------------------------------------

    test_proj.rar

    HERCULE.rar

  •  For flash erase and program operations, the flash APIs have to be executed from a separate flash bank or SRAM.

  • I’m allready doing that step with memcpy. I guess overriding is not acceptable, before writing something I should erase and after that program am I right?

  • I am sure you did memcpy in bootloader. Do you copy the Flash APIs to SRAM in your application?

  • Yes I am also copying Fapi to SRAM in my application , if you want to check its inside test_proj.rar 

  • The Flash APIs also need to be called from SRAM instead of flash, so please copy sys_main.c to SRAM too.

    Please refer to bl_flash.c in bootloader. bl_flash.obj is also copied to SRAM, and executed from SRAM.