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/TMS320F28069: Branch from Bootloader to Application Code

Part Number: TMS320F28069


Tool/software: Code Composer Studio

My situation involves transitioning from a bootloader to application code. I'm using a TMS320F28068 MCU. My bootloader resides in sector A of flash. If it doesn't detect that code needs be downloaded to flash, it should transition to the application code which is in sectors B to H. I'm using the linker command file to make sure the code is separated like this. My bootloader and application code all reside in one CCS project. 

I noticed that when I make changes to the application code, it would load fine using my bootloader (meaning that the application code was correctly loaded) but it wouldn't transition out of the bootloader after reset. Using Code Composer and the JTAG port, I examined the disassembly. I did this for one version of my code and another version. In each version I never modified the bootloader code. Rather, I modified the application code only. Below are two screen shots of the disassembly (each from a different version).





My "main()" function is in sector A. This calls my bootloader. "main_apl()" is the function at the start of the application code (which again is in sectors B to H). As you can see, at address 0x3F4268, the contents of that address changes even though they are both calls to "main_apl". In the first one, the contents of 0x3F4268 is 767E2C61 and the other is 767E2C3D. This is a problem because the bootloader only writes to sectors B to H. Thus, the code might load correctly, but the call from sector A to go to the application isn't the same. This would prevent a successful transition between the bootloader and the application code.

My question is this: how can I go to "main_apl" from the bootloader section while keeping the contents of sector A constant between different compilations? I was thinking about replacing "main_apl();" with "asm( "LCR 0x3D8000)", but how do I make sure from the linker command file that the function will always stay at 0x3D8000?

Thanks.
Syed

  • After doing some experimentation, it looks like I have to figure out a way to fix "main_apl" to 0x3D8000.

    In my project, "main_apl" is currently located at 0x3E23CD. Whenever I made a change to "main_apl", the contents of 0x3F4269 didn't change. But, when I changed a function at address 0x3D8269, the contents of 0x3F4269 changed.

    This seems to indicated that in the disassembly above, address 0x3F4268 to 0x3F4269 must contain the pointer to the "main_apl". Thus, if I need this to be fixed and unchanging whenever the project is compiled, "main_apl" must be fixed to 0x3D8000. This is the starting address of sector H (the top most sector). This means that any change to other functions would have no effect on the location of "main_apl".

    The question then becomes how to assign "main_apl()" to 0x3D8000 so that it will always be there no matter what other changes occur to the application code. Does anyone know how to do this? My guess is that this must be done in the linker command file, but I don't know what specifically to do. Any help would be greatly appreciated.
  • I found out I can do this: I can specify a small portion of sector H in the linker command file and then force the object file containing the function in that area.

    So in the "MEMORY" part of the linker command file, specify the following:
    FLASH_H_Apl (R) :origin=0x3D8000, length =0x0004FF

    Then, in the "SECTIONS" part, specify a labeled that's tied to that address range:
    mainAplStart :> FLASH_H_Apl, PAGE=0

    Finally, add a "CODE_SECTION" in the relevant c file that assigns the "main_apl" function to that label.

    After doing all of this, it looks like my pointer to "main_apl" is consistent between compilations. Thus, it always correctly enters the application code from the bootloader section.

    The only catch is this: if more functions are added to that c file, it's possible that "main_apl" will no longer be at 0x3D8000. If I locate additional functions after the "main_apl" definition in the c file, then I don't think it's problem. This really isn't an issue for me since my c file that has "main_apl" should never have additional functions there. Rather, they should be located elsewhere in the project. However, I just wanted to point this out in case someone is considering doing what I did.
  • Hi Syed,

    Glad to hear you solve the problem. Thanks for sharing your solution that might help other people in the future.

    Best regards,
    Chen