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.

TMS320F28379D: Load code to FLASH and then Run entire code from RAM.

Part Number: TMS320F28379D

Hi, I am trying to load the entire code to FLASH so that every time a power supply is disconnected, the code can start over. I am using hrpwm and other critical functions, and would like to use the RAM for the execution of various functions. Therefore, a simple option that I would work for me to run the entire code from RAM. Could you please help in resolving this issue and also help me in finding the right reference that I can follow for accomplishing the above? 

I have tried compiling the code with option 2 Release, and it throws lot of errors. So I am simply working with option 1 Debug, excluding "2837xD_RAM_lnk_cpu1.cmd" from the build and instead using this file "2837x_FLASH_lnk_cpu1.cmd" for the build. The latter is also copied below. 

In the main.c file, I am adding these few lines: 

memcpy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

InitFlash();

Outcome: I have not been able to run the code successfully, which is verified by analyzing PWM pins that do not change state. Also, while the computer is still connected to the DSP while flashing, the code goes into this routine

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
interrupt void ILLEGAL_ISR(void)
{
//
// Insert ISR Code here
//
//
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
//
asm (" ESTOP0");
for(;;);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

"2837xD_RAM_lnk_cpu1.cmd" File is copied below

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MEMORY
{
PAGE 0 : /* Program Memory */
/* Memory (RAM/FLASH) blocks can be moved to PAGE1 for data allocation */
/* BEGIN is used for the "boot to Flash" bootloader mode */
BEGIN : origin = 0x080000, length = 0x000002
RAMM0 : origin = 0x000122, length = 0x0002DE
RAMD0 : origin = 0x00B000, length = 0x000800
RAMLS0 : origin = 0x008000, length = 0x000800
RAMLS1 : origin = 0x008800, length = 0x000800
RAMLS2 : origin = 0x009000, length = 0x000800
RAMLS3 : origin = 0x009800, length = 0x000800
RAMLS4 : origin = 0x00A000, length = 0x000800
RAMGS14 : origin = 0x01A000, length = 0x001000
RAMGS15 : origin = 0x01B000, length = 0x001000
RESET : origin = 0x3FFFC0, length = 0x000002
/* Flash sectors */
FLASHA : origin = 0x080002, length = 0x001FFE /* on-chip Flash */
FLASHB : origin = 0x082000, length = 0x002000 /* on-chip Flash */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello,

    To clarify your goal, you're trying to start the application from Flash and then load specific functions into RAM, correct?

    For the error that you're reaching, are you able to step through the program or set breakpoints to see where the issue is occurring? Have you verified that each function moved to RAM don't branch across RAM units (i.e. a single function does not branch between two different RAMLSx's). Also, have you verified that the program runs fine when just running from Flash or RAM? Are there any errors in doing this?

    Best regards,

    Omer Amir

  • Hello Omer, my program runs fine when running from RAM, but i do get these warnings. 

    My Goal: Have the code available in FLASH and then upon power reset the entire code should run from RAM. I will really appreciate if you could review my code which I cannot share here? Is there any direct link or your email that I can use to share my code with you? 

    My your remaining suggestions: The code breaks once it goes into ADC configurations. There was a delay DELAY_US(1000); used there which is now commented out. The code still does not run with FLASH. 

    Warning while running from RAM

    Description Resource Path Location Type
    #10247-D null: creating output section ".TI.ramfunc" without a SECTIONS specification FlashToRamCode C/C++ Problem
    #10247-D null: creating output section "DcsmZ1OtpFile" without a SECTIONS specification FlashToRamCode C/C++ Problem
    #10247-D null: creating output section "DcsmZ2OtpFile" without a SECTIONS specification FlashToRamCode C/C++ Problem
    #10247-D null: creating output section "EmuKeyVar" without a SECTIONS specification FlashToRamCode C/C++ Problem
    #10373-D null: library "../F2837xD_hrPWM/lib/SFO_v8_fpu_lib_build_c28_driverlib_eabi.lib" contains ELF object files which are incompatible with the TI-COFF output file. Ensure you are using the proper library. FlashToRamCode C/C++ Problem
    #10373-D null: library "../F2837xD_hrPWM/lib/SFO_v8_fpu_lib_build_c28_eabi.lib" contains ELF object files which are incompatible with the TI-COFF output file. Ensure you are using the proper library. FlashToRamCode C/C++ Problem
    #99922 null: C:\Users\RIARBA~1\AppData\Local\Temp\189402: Invalid CIE reference 0xffff0000 for the FDE at offset 0x000021fa in the .debug_frame section() FlashToRamCode C/C++ Problem

  • Hello,

    I've included a basic example of a way to move certain functions from Flash to RAM using the binit section to do this before main is actually called (there is no specific rule that you need to do this, but it saves some time and complexity in the program). This example is made for the F2838x device so you may have to change the names of some memory units, but otherwise it should work the same.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    MEMORY
    {
    /* BEGIN is used for the "boot to SARAM" bootloader mode */
    BEGIN : origin = 0x000000, length = 0x000002
    BOOT_RSVD : origin = 0x000002, length = 0x0001AF /* Part of M0, BOOT rom will use this for stack */
    RAMM0 : origin = 0x0001B1, length = 0x00024F
    RAMM1 : origin = 0x000400, length = 0x0003F8 /* on-chip RAM block M1 */
    // RAMM1_RSVD : origin = 0x0007F8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
    RAMD0 : origin = 0x00C000, length = 0x000800
    RAMD1 : origin = 0x00C800, length = 0x000800
    RAMLS0 : origin = 0x008000, length = 0x000800
    RAMLS1 : origin = 0x008800, length = 0x000800
    RAMLS2 : origin = 0x009000, length = 0x000800
    RAMLS3 : origin = 0x009800, length = 0x000800
    RAMLS4 : origin = 0x00A000, length = 0x000800
    RAMLS5 : origin = 0x00A800, length = 0x000800
    RAMLS6 : origin = 0x00B000, length = 0x000800
    RAMLS7 : origin = 0x00B800, length = 0x000800
    RAMGS0 : origin = 0x00D000, length = 0x001000
    RAMGS1 : origin = 0x00E000, length = 0x001000
    RAMGS2 : origin = 0x00F000, length = 0x001000
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In your main code, you will also need to include "#pragma CODE_SECTION(ramCounter, ".TI.ramfunc");" to load the function "ramCounter" into the .TI.ramfunc section of memory. You can change this function with whatever functions you are using. Try to make sure you don't allocate a function in such a way that it will need to jump across RAM boundaries that aren't sequential (you can check the Disassembly view and Memory Browser to confirm this).

    Best regards,

    Omer Amir

  • Thank you Omer for all your help!

    In was able to run from RAM by

    1) including "#pragma CODE_SECTION(ramCounter, ".TI.ramfunc") as suggested above to run functions from RAM

    2) SFO as needed by HrPWM does not have a source file, so its library need to be loaded to RAM for timely execution of control loops. All I had to do was modify the linker file as copied below. You can review .map file ensuring that SFO and functions run from RAM

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    .TI.ramfunc : LOAD = FLASHB | FLASHC | FLASHD | FLASHE |FLASHF | FLASHG | FLASHH, //FLASHD,
    RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,
    LOAD_START(_RamfuncsLoadStart),
    LOAD_SIZE(_RamfuncsLoadSize),
    LOAD_END(_RamfuncsLoadEnd),
    RUN_START(_RamfuncsRunStart),
    RUN_SIZE(_RamfuncsRunSize),
    RUN_END(_RamfuncsRunEnd),
    PAGE = 0, ALIGN(4)
    {
    --library=SFO_v8_fpu_lib_build_c28_coff.lib (.text)
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX