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.

RTOS/TMS320F28335: How to load .text section from flash to external RAM in DSP28335

Part Number: TMS320F28335

Tool/software: TI-RTOS

    I use DSP28335 to develop my program based DSP/BIOS, after the program is normally compiled and build the program in CCS3.3, the .out file of my program is 920Kb, I burn .out file into DSP28335,
the program can normally start and run.
   In order to shorten running time of the program, I want to load .text and .econst section of program from flash to external RAM in XINTF Zone 6 because On-Chip Memory of DSP28335 is small, So I
do loading work according to some example:
    Firstly, before _c_int00, I initialize .text and .econst section refering to DSP28xxx_SectionCopy_nonBIOS.asm,
   Secondly, I initialize SARAM in XINTF Zone 6 refering to InitExtMemIf.asm( ()),
   Then, I load .text and .econst section of program from flash to SARAM in XINTF Zone 6 in F28335_BIOS_flash.cmd

/*name PAGE 0:
ExtRAM origin:00100000 length:00080000
L67RAM origin:0000e000 length:00002000*/

.text : LOAD = FLASH_ABCDEFGH, PAGE = 0 /* Should be Flash */
          RUN = ExtRAM, PAGE = 0 /* Must be CSM secured RAM */
          LOAD_START(_text_loadstart),
          LOAD_SIZE(_text_loadsize),
          RUN_START(_text_runstart)

.econst : LOAD = FLASH_ABCDEFGH, PAGE = 0 /* Should be Flash */
          RUN = ExtRAM, PAGE = 0 /* Must be CSM secured RAM */
          LOAD_START(_econst_loadstart),
          LOAD_SIZE(_econst_loadsize),
          RUN_START(_econst_runstart)

    After the program is normally compiled and build the program in CCS3.3, I burn .out file into DSP28335, But the program can't start and run.
    I change running address of .text section from ExtRAM to L67SARAM section of On-Chip Memory of DSP28335, After the program is normally compiled and build the program in CCS3.3, I burn .out file
into DSP28335, the program can normally start and run.


.text : LOAD = FLASH_ABCDEFGH, PAGE = 0 /* Should be Flash */
          RUN = L67SARAM, PAGE = 0 /* Must be CSM secured RAM */
          LOAD_START(_text_loadstart),
          LOAD_SIZE(_text_loadsize),
          RUN_START(_text_runstart)
.econst : LOAD = FLASH_ABCDEFGH, PAGE = 0 /* Should be Flash */
          RUN = ExtRAM, PAGE = 0 /* Must be CSM secured RAM */
          LOAD_START(_econst_loadstart),
          LOAD_SIZE(_econst_loadsize),
          RUN_START(_econst_runstart)

     How solve the question of loading .text section of program from flash to external RAM。

  • Hi QuanXing Liu,

    Did you perform a memcpy within your program to copy the code from flash to external RAM? Similar to what's done in the example:

        memcpy(&text_runstart, &text_loadstart,
               (Uint32)&text_loadsize);

    Best,

    Kevin

  • The copy of .text section is done in DSP28xxx_SectionCopy_nonBIOS.asm。

    MOVL XAR5,#_text_size ; Store Section Size in XAR5

    SUBB XAR5,#1
    MOVL ACC,@XAR5 ; Move Section Size to ACC
    MOVL XAR6,#_text_loadstart ; Store Load Starting Address in XAR6
    MOVL XAR7,#_text_runstart ; Store Run Address in XAR7
    LCR copy

    By this way, .econst section of program can succefully load from flash to external RAM!

    By this way, .text section of program can succefully load from flash to on chip RAM!

    But, .text section of program can't succefully load from flash to external RAM. How can I solve this question.

  • QuanXing Liu,

    Are you enabling and configuring the XINTF module before copying data from flash to external RAM? The device will not know how to interface with the external RAM until XINTF is configured.

    -Tommy
  • Thanks for your reply .According to your prompt, I enabling and configuring the XINTF module before copying data from flash to external RAM, the calling proess is:

    1.CodeStartBranch.asm
    2.InitExtMemIf.asm
    Function: enabling and configuring the XINTF module
    source:David M. Alter provide(e2e.ti.com/.../1494798
    3.DSP28xxx_SectionCopy.asm
    Function: copying data from flash to external RAM
    source:SPRA958H(Running an Application from Internal Flash Memory on the TMS320F28xxx DSP)

    In order to judge the program running status, I add LED dispaly in main() function and the timer of 1Hz

    Case1:After the program is normally compiled and build the program in CCS3.3, I burn .out file into DSP28335, But the program can't start and run. Even I change .text section load from flash to on-chip RAM,the program can't also start and run. Please see the program:

    Example( .text load).rar

    Case 2:So, I try to remove .text section from the process, only load.econst from flash to external RAM,the program can normally start and run. Please see the program

    Example(No .text load).rar

    But If I change the order of calling,

    1.CodeStartBranch.asm
    2.DSP28xxx_SectionCopy.asm
    Function: copying data from flash to external RAM
    source:SPRA958H(Running an Application from Internal Flash Memory on the TMS320F28xxx DSP)

    3.InitExtMemIf.asm
    Function: enabling and configuring the XINTF module
    source:David M. Alter provide(e2e.ti.com/.../1494798

    Case 3:And text section load from flash to on chip RAM of DSP28335, and load.econst from flash to external RAM,the program can normally start and run. Please see the below program

    Example( .text load from innerRAM).rar

    Case 4:But If I change text section load from flash to exteranl RAM, and load.econst from flash to external RAM,the program also can't start and run. Please see the below program

    Example( .text load from ExtRAM).rar

    How to solve this question? I need load .text section of program from flash to external RAM in DSP28335. Thanks 

  • QuanXing Liu,

    Please help us understand the situation a little better. Can you confirm that the data is being copied correctly to external RAM? For this observation, we can ignore the aspect of whether the program will run or not.

    We want to make sure that XINTF is working properly and all of the data is where it should be. If you connect through JTAG after boot, are variables and constants initialized to the expected values? Do the function op-codes look reasonable in external RAM? It is sufficient to sample a handful of op-codes to make sure that it is not random data.

    -Tommy
  • Tommy:
       Thanks for your prompt, I have my way to confirm whether XINFT is work properly and  whether .econst copyiing from flash to ExtRAm is right.Please see whether the process is right
       Firstly, In order to make sure whether XINFT is work properly, In my example program which only .econst section is copy from flash to ExtRAM,  I do some below setting in DSP/BIOS Config,
       1.General:Segment For malloc()/free: ExtRAM
       2.C Variable Section(.bss): ExtRAM
       3.C Variable Section(.ebss): ExtRAM
       I add malloc function in begin of main() function,  the malloc use ExtRAM, the data of write and read is right.
       Secondly ,  I find .econst section is string data, I add string const in begin of main() function, the string const data is right
       Please see the below attachment.

    Example(No .text).rar

  • QuanXing Liu,

    That sounds reasonable. I think we can assume that XINTF is working and now it's more of a BIOS startup issue. We will need to pull in some additional experts for BIOS.

    Are you executing UserInit()?

    -Tommy

  • Yes, I have executed Userinit(), You can see the Userinit function in main() in my Example(No .text) , I am sure the Userinit() function is executed.
    void UserInit(void)
    {
    #ifdef EXAMPLE_FLASH // EXAMPLE_FLASH, if defined, is in CCS project options

    // Section .trcdata is generated by DSP/BIOS.
    // It must be copied from its load to its run address BEFORE main().
    memcpy(&trcdata_runstart, &trcdata_loadstart, &trcdata_loadend - &trcdata_loadstart);

    #endif

    } // end of UserInit()

    I use CCS3.3+DSP/BIOS 5.41+CodeGeneration6.2.0

  • Hello QuanXing,

    Ignoring for a moment the issue you are having running from external RAM, I'd like to ask you what you hope to achieve by copying your code over to external RAM.  You had said:

    "In order to shorten running time of the program, I want to load .text and .econst section of program from flash to external RAM in XINTF Zone 6"

    Running the code from external RAM is going to be slower than internal flash.  Are you aware of this?

    Regards,

    David

  • Hello,David:

    Thanks for your prompt, I alsohave four question:

    1.Please help me make sure whether the configuration of inner Flash is the best

    void InitFlash(void)
    {
    asm(" EALLOW"); // Enable EALLOW protected register access
    FlashRegs.FPWR.bit.PWR = 3; // Pump and bank set to active mode
    FlashRegs.FSTATUS.bit.V3STAT = 1; // Clear the 3VSTAT bit
    FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF; // Sleep to standby transition cycles
    FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF; // Standby to active transition cycles
    FlashRegs.FBANKWAIT.bit.RANDWAIT = 5; // Random access waitstates
    FlashRegs.FBANKWAIT.bit.PAGEWAIT = 5; // Paged access waitstates
    FlashRegs.FOTPWAIT.bit.OTPWAIT = 8; // OTP waitstates
    FlashRegs.FOPT.bit.ENPIPE = 1; // Enable the flash pipeline
    asm(" EDIS"); // Disable EALLOW protected register access

    // Force a complete pipeline flush to ensure that the write to the last register
    // configured occurs before returning. Safest thing is to wait 8 full cycles.

    asm(" RPT #6 || NOP");

    } // end of InitFlash()

    2.I use 6.67ns 32-bit External SRAM, How to configure the speed of external SRAM is to 150MIPS?
    3. Because my hardware already use DSP28335,my program mainly do matrix compute. Because my program is big, but the inner SRAM is so small, I must use external
    SRAM (for example .bss and .ebss section), I want to shorten running time of the program, how to shorten the time of matrix compute.
    4. I also want to know the reason of the question:
    The calling proess is:
    1)CodeStartBranch.asm
    2)InitExtMemIf.asm
    3)DSP28xxx_SectionCopy.asm
    Case1:After the program is normally compiled and build the program in CCS3.3, I burn .out file into DSP28335, But the program can't start and run. Even I change
    .text section load from flash to on-chip RAM,the program can't also start and run. Please see the program.

    7484.Example( .text load).rar

    Regards,

    scqxlxc

  • QuanXing,

    >> 1.Please help me make sure whether the configuration of inner Flash is the best

    The configuration you are showing is correct for 150 MHz.

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

    >> 2.I use 6.67ns 32-bit External SRAM, How to configure the speed of external SRAM is to 150MIPS?

    A 6.67 ns SRAM is very fast, but in fact it will perform no better with F28335 DSP than a 10 ns SRAM.  You can run the numbers in section 5.9.6 of the datasheet SPRS439n.  For example, the read timings:

    With X2TIMING=0 ==> tc(XTIM)=6.67 ns.

    For XRDLEAD=1, XRDACTIVE=2, XRDTRAIL=0 ==>

      LR = 6.67 ns, AR = 20 ns, TR = 0 ns.

      ta(A) = LR + AR - 16 = 10.67 ns.  This will work with a 10 or 6.67 ns SRAM.

    If you make XRDACTIVE=1, similarly with above you end up with ta(A) = 4 ns.  This won't work with a 6.67 ns SRAM.

    So, you need XRDLEAD=1, XRDACIVE=2, XRDTRAIL=0.

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

    >> 3. Because my hardware already use DSP28335,my program mainly do matrix compute. Because my program is big, but the inner SRAM is so small, I must use external SRAM (for example .bss and .ebss section), I want to shorten running time of the program, how to shorten the time of matrix compute.

    Are you saying that your key algorithms for matrix compute are too large to fit into internal memory?  I don't mean your entire program.  I mean just the matrix compute routines.  I would think these should fit into internal memory, and could be put there using the technique shown in appnote SPRA958.

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

    >> 4. I also want to know the reason of the question:
    The calling proess is:
    1)CodeStartBranch.asm
    2)InitExtMemIf.asm
    3)DSP28xxx_SectionCopy.asm
    Case1:After the program is normally compiled and build the program in CCS3.3, I burn .out file into DSP28335, But the program can't start and run. Even I change
    .text section load from flash to on-chip RAM,the program can't also start and run. Please see the program.

    One thing I see is that you said you are using 32-bit SRAM, but your InitExtMemIf() function is configuring for 16-bit wide SRAM.  You have XSIZE set to 3 (16-bit), and also did not configure the shared GPIO for the data pins 16-31.

    You will need to debug this on your hardware.  After running DSP28xxx_SectionCopy(), do you see the code in the external memory using CCS?  What I'd suggest doing is first getting the XINTF working correctly.  Do not run any code from there.  Initialize it, and then just try to copy and read back some data.  Get it working like that first.

    Regards,

    David

  • David:

    Sorry, I make a mistake in my post. I am using 16-bit SRAM not 32-bit SRAM

    About the fourth question, I also describe all the process.
          Thanks for your prompt, I have my way to confirm whether XINFT is work properly and  whether .econst copying from flash to ExtRAm is right. Please see whether the process is right
          Firstly, In order to make sure whether XINFT is work properly, In my example program which only .econst section is copy from flash to ExtRAM,  I do some below setting in DSP/BIOS Config, 
          1.General:Segment For malloc()/free: ExtRAM
          2.C Variable Section(.bss): ExtRAM
          3.C Variable Section(.ebss): ExtRAM
          I add malloc function in begin of main() function,  the malloc use ExtRAM, the data of write and read is right.
          Secondly ,  I find .econst section is string data, I add string const in begin of main() function, the string const data is right

     Example_CheckExtRAM.rar

         The main question is below:

    According to normal sequence, The calling process is:
    1)CodeStartBranch.asm
    2)InitExtMemIf.asm
    3)DSP28xxx_SectionCopy.asm

    .text section load from flash to on-chip RAM

    econst section load from flash to ExtRAM
          After the program is normally compiled and build the program in CCS3.3, I burn .out file into DSP28335, But the program can't start and run.

     1.InitExtMemIf 2.DSP28xxx_SectionCopy.rar

    I do some try, If The calling proess is:
    1)CodeStartBranch.asm
    2)DSP28xxx_SectionCopy.asm

    .text section load from flash to on-chip RAM

    .econst section load from flash to ExtRAM
    3)InitExtMemIf.asm

    After the program is normally compiled and build the program in CCS3.3, I burn .out file into DSP28335, But the program can normally start and run.

    1.DSP28xxx_SectionCopy 2.InitExtMemIf.rar

        Why is this happening? I need your help to explain the reason.Thanks

    Regards

    scqxlxc

  • QuanXing,

    The correct procedure is as you said:

    1)CodeStartBranch.asm
    2)InitExtMemIf.asm
    3)DSP28xxx_SectionCopy.asm

    In your case, you've got InitExtMemIf() as part of the .text section, and you've located .text in external RAM.  In the sequence above, you are trying to run InitExtMemIf() before you've copied stuff to external RAM.  You cannot do this.  I would locate InitExtMemIf() in a different section, say .text2 (or whatever you want to call the section).  Just leave this section alone in flash.  Then, the above sequence should work.

    But I think you have something else wrong in your code as it doesn't run correctly.  I do not know what.  You will have to debug it with a combination of stepping and hardware breakpoints.

    I still wonder what you are trying to achieve here.  Running your code from external RAM is not going to be faster than the internal flash.

    Regards,

    David

  • David:

    As your said, I only load the main matrix compute function from flash to internal memory using the technique shown in appnote SPRA958,
    But the compute time can't be shortened. Can you give me other adivice to shorten the compute time

    Regards

    scqxlxc

  • QuanXing Liu said:

    As your said, I only load the main matrix compute function from flash to internal memory using the technique shown in appnote SPRA958,

    But the compute time can't be shortened. Can you give me other adivice to shorten the compute time

    Check to make sure the matrix functions are not in the same RAM block with the matrix data itself.  I doubt they are, but check.  If they are in the same RAM block, move one of them to a different RAM block.

    After that, all you can do is try to hand optimize the matrix function(s) using hand assembly code.

    Regards,

    David

  • David:

    Thanks for your reply. I shorten the compute time as your said.

            Regards

    scqxlxc