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.

TMS320F28P650DK: Load Code to Flash and then Run the program from RAM

Part Number: TMS320F28P650DK
Other Parts Discussed in Thread: C2000WARE, UNIFLASH

I'm trying to load .text section to flash and then run it in RAM using BINIT Table. While doing so I'm facing this issue.

  • Hello Rishitha,

    To migrate an existing application that is configured to run from RAM to a Flash-based linker configuration, follow these steps:
    1. Replace the RAM linker command file with a Flash linker command file. For example Flash-based linker command files, see the device_support\<device>\common\cmd directory.
    2. When modifying the Flash-based linker command file, be sure to map any initialized sections to Flash memory regions.
    3. Make sure the boot mode pins are configured for Flash boot. This tells the boot ROM to redirect execution to the application programmed into Flash memory after boot code execution is complete. For more information on boot mode configuration, see "Detailed Description⏵Device Boot Modes" in the device data sheet.
    4. When the device is configured for Flash boot, the boot ROM redirects execution to the Flash entry point location (defined as BEGIN in TI-provided Flash linker command files) at the end of boot code execution. Make sure there is a branch instruction at the Flash entry point to your code initialization (for example, _c_int00) function. In the C2000Ware examples, the entry point code is specified in the CodeStartBranch.asm file.
    5. To achieve best performance for Flash execution, configure the Flash wait states as per the device operating clock frequency, as specified in the device data manual. In addition, enable prefetch mode and data cache mode. Calling the Flash_initModule() driverlib function achieves these steps. Note that code that initializes the Flash module must execute from a RAM location. This is accomplished by assigning the Flash initialization function to the .TI.ramfunc section, and then copying the function to RAM at runtime using memcpy() before executing the function. In the linker command file, map this section to Flash for load, and RAM for execution.
    6. For any functions that require 0- or 1-wait state performance, be sure to map to RAM for execution in the linker command file, similar to the Flash initialization function. The .TI.ramfunc section in the TI-provided Flash linker command files accomplishes this purpose.
    7. Align all code and data sections to 128-bit address boundaries when mapping to Flash memory, using the ALIGN directive in the linker command file.
    8. For EABI executable formats, define all uninitialized sections mapped to RAM as NOINIT sections (using the directive "type=NOINIT") in the linker command file.
    9. Be sure to program ECC bits correctly for the Flash application image. Keep the AutoEccGeneration option enabled in the Code Composer Studio Flash Plugin or UniFlash GUI.
  • As you said instead of binit tables, I tried to move .text from FLASH to RAM using memcpy(). In linker command file, I've mapped this section to LOAD in FLASH and RUN in RAM. But still facing this issue. CCS is getting breakpoint at line 82 in codestart.asm and when I try to resume it's showing no source availiable for _system_post_cinit(). When I run code from flash it's working fine. I'm Facing this issue only when I try to move entire .text section from flash to RAM while runing.

  • Rishitha,

    Could you show your linker command file? Also, if you place your init functions in .TI.ramfunc you should not need to manually do the memcpy - the code generation tools should handle that for you.

    Thanks,
    Ibukun

  • Also, when the error occurs, check the CPU_SYS_REGS.RESC and NMI_INTRUPT_REGS.NMISHDFLG registers to see what has caused the device to reset. Perhaps you have a clock setup issue.

  • LinkerFiles.zip linker command files are attached here

  • Thank you for sharing Rishitha. Just a point of clarification: the LOAD=FLASH/RUN=RAM is only needed for functions that initialize the Flash. The rest of your code can just run from Flash simply.

    But you need to have Flash_init_module() called from your code. If you have a custom function that initializes the flash, you must have #pragma CODE_SECTION(myFlashInitFunc, ".TI.ramfunc") declared so that the linker places it in the correct section. If you're calling Flash_initModule() from driverlib this pragma is already declared in the library source.

  • Yeah, I've tried runing rest of the code from Flash. It is working fine. Since flash has waitstates, I want to try moving my entire code to RAM 

  • Ah, I see. You could just make sure that all of your performance-critical code functions are placed in .TI.ramfunc by using the #pragma I described above and that should take care of them.

    For anything outside of .TI.ramfunc, you would likely need to create your own copy tables and use the copy_in() function to copy them from Flash into RAM. For more on this, take a look at www.ti.com/lit/spraa46, section 4 (Copy Tables). 

  • I've created a section, included  .text section of object files in it and moved this section from flash to RAM using boot time copy tables. But when I try to move codestart.asm object file and few others (attached below), it's showing error. What's the reason for that and how can I make sure that these run in RAM.

     

  • Hi Rishitha,

    You shouldn't move codestart.asm into RAM. This is just the initial code that branches to _c_int00. It is the entry point that the boot ROM will branch to - so if it is not present in Flash then your code won't start at all.

    Typically. you wouldn't move all your functions into RAM, just the ones running your control loop that you need to execute with 0-wait-state latency.

    Best regards,
    Ibukun