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.

C File I/O (fopen) problem

Other Parts Discussed in Thread: TMS320F28027, CCSTUDIO

Dear all

Can someone help me to create a file in Piccolo series controlCARD TMS320F28027 in CCS v3.3. I'm trying to write my data to file, but I've been receiving some linker command problems. I've to increase the RAM index but all failed.

Please I help to be able to continuing my project.

Best regards

Michael

  • Please show the exact linker command file problems you are seeing.  In the meantime, this article may help http://tiexpressdsp.com/index.php/Tips_for_using_printf .

    Thanks and regards,

    -George

     

  • Dear Georgem

    Thanks for your reply. I'm try to log my data from on-chip ADC, so that I can plot in MatLab. The first errors:

    "C:\\CCStudio_v3.3\\MyProjects\\HIP3_CCU\\DSP2802x_common\\cmd\\28027_RAM_lnk.cmd", line 121: error:
       run placement fails for object ".ebss"
    error: run placement fails for object ".cio"
    warning: entry-point symbol other than "_c_int00" specified:  "code_start"
    error: errors encountered during linking; "./Debug/HIP3_CCU.out" not built
    .

    Then I try to define sections CIO and SYSMEM but all failed: The error is:

    "C:\\CCStudio_v3.3\\MyProjects\\HIP3_CCU\\DSP2802x_common\\cmd\\28027_RAM_lnk.cmd", line 121: error:
       run placement fails for object ".ebss"
    "C:\\CCStudio_v3.3\\MyProjects\\HIP3_CCU\\DSP2802x_common\\cmd\\28027_RAM_lnk.cmd", line 125: error:
       run placement fails for object ".sysmem"
    warning: entry-point symbol other than "_c_int00" specified:  "code_start"
    error: errors encountered during linking; "./Debug/HIP3_CCU.out" not built
    .

    The linker command is for the 28027_RAM_lnk.cmd:

    MEMORY
    {
    PAGE 0 :
       /* For this example, L0 is split between PAGE 0 and PAGE 1 */
       /* BEGIN is used for the "boot to SARAM" bootloader mode   */

       BEGIN      : origin = 0x000000, length = 0x000002
       RAMM0      : origin = 0x000002, length = 0x0050FE     /*: origin = 0x000050, length = 0x0003B0*/
       PRAML0     : origin = 0x008000, length = 0x00F000     /*: origin = 0x008000, length = 0x000900*/
       RESET      : origin = 0x3FFFC0, length = 0x000002

       IQTABLES   : origin = 0x3FE000, length = 0x000B50     /* IQ Math Tables in Boot ROM */
       IQTABLES2  : origin = 0x3FEB50, length = 0x00008C     /* IQ Math Tables in Boot ROM */
       IQTABLES3  : origin = 0x3FEBDC, length = 0x0000AA     /* IQ Math Tables in Boot ROM */

       BOOTROM    : origin = 0x3FF27C, length = 0x000D44


    PAGE 1 :

       /* For this example, L0 is split between PAGE 0 and PAGE 1 */
       BOOT_RSVD   : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */
       RAMM1       : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 : origin = 0x000400, length = 0x000400 */
       DRAML0      : origin = 0x008900, length = 0x000700     /* : origin = 0x008900, length = 0x000700*/
    }


    SECTIONS
    {
       /* Setup for "boot to SARAM" mode:
          The codestart section (found in DSP28_CodeStartBranch.asm)
          re-directs execution to the start of user code.  */
       codestart        : > BEGIN,     PAGE = 0
       ramfuncs         : > RAMM0      PAGE = 0
       .text            : > PRAML0,    PAGE = 0
       .cinit           : > RAMM0,     PAGE = 0
       .pinit           : > RAMM0,     PAGE = 0
       .switch          : > RAMM0,     PAGE = 0
       .reset           : > RESET,     PAGE = 0, TYPE = DSECT /* not used, */

       .bss             : > DRAML0,    PAGE = 1
       .ebss            : > DRAML0,    PAGE = 1
       .cio             : > DRAML0,    PAGE = 1
       .econst          : > DRAML0,    PAGE = 1
       .stack           : > RAMM1,     PAGE = 1
       .sysmem          : > RAMM1,     PAGE = 1
       .esysmem         : > RAMM1,     PAGE = 1
       //.fprintf (COPY)  : {}> DRAML0   PAGE = 1
    }
    Please,I don't know if the definition is correct.

    Best regards

    Michael

  • Your RAMM1 is only 0x400 words, which is probably not big enough to hold all of .stack, .sysmem, and .esysmem.  Try using the option '-m link.map' to create a file with more information about the sizes of sections.  Try reducing the size of .stack and .sysmem, and using setvbuf() to prevent memory allocation in C I/O functions.

  • Hi, thanks  alot for your replied. I've written a small program to create an output file, but still the is not created, using setvbuf(), and now I've increased my linker command code.The code is:

    file = fopen("myfile.txt","w");
    setvbuf(file, NULL, _IONBF, 1024);
    fclose(file);

    Linker Cmd.

    MEMORY
    {
    PAGE 0 :
       /* For this example, L0 is split between PAGE 0 and PAGE 1 */
       /* BEGIN is used for the "boot to SARAM" bootloader mode   */

       BEGIN      : origin = 0x000000, length = 0x000002
       RAMM0      : origin = 0x000002, length = 0x0050FE     /*: origin = 0x000050, length = 0x0003B0*/
       PRAML0     : origin = 0x008000, length = 0x00F000     /*: origin = 0x008000, length = 0x000900*/
       RESET      : origin = 0x3FFFC0, length = 0x000002

       IQTABLES   : origin = 0x3FE000, length = 0x000B50     /* IQ Math Tables in Boot ROM */
       IQTABLES2  : origin = 0x3FEB50, length = 0x00008C     /* IQ Math Tables in Boot ROM */
       IQTABLES3  : origin = 0x3FEBDC, length = 0x0000AA     /* IQ Math Tables in Boot ROM */

       BOOTROM    : origin = 0x3FF27C, length = 0x000D44


    PAGE 1 :

       /* For this example, L0 is split between PAGE 0 and PAGE 1 */
       BOOT_RSVD   : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */
       RAMM1       : origin = 0x400000, length = 0x400000     /* on-chip RAM block M1 : origin = 0x000400, length = 0x000400 */
       DRAML0      : origin = 0x008900, length = 0x008900     /* : origin = 0x008900, length = 0x000700*/
    }


    SECTIONS
    {
       /* Setup for "boot to SARAM" mode:
     The codestart section (found in DSP28_CodeStartBranch.asm)
      re-directs execution to the start of user code.  */
       codestart        : > BEGIN,     PAGE = 0
       ramfuncs         : > RAMM0      PAGE = 0
       .text            : > PRAML0,    PAGE = 0
       .cinit           : > RAMM0,     PAGE = 0
       .pinit           : > RAMM0,     PAGE = 0
       .switch          : > RAMM0,     PAGE = 0
       .reset           : > RESET,     PAGE = 0, TYPE = DSECT /* not used, */

       .bss             : > DRAML0,    PAGE = 1
       .ebss            : > DRAML0,    PAGE = 1
       .cio             : > DRAML0,    PAGE = 1
       .econst          : > DRAML0,    PAGE = 1
       .stack           : > RAMM1,     PAGE = 1
       .sysmem          : > RAMM1,     PAGE = 1
       .esysmem         : > RAMM1,     PAGE = 1
       //.fprintf (COPY)  : {}> DRAML0   PAGE = 1
    }

    Are the any examples that one can followed.

    Regards

    Michael

  • Michael Blankson said:
    setvbuf(file, NULL, _IONBF, 1024);

    Despite being set to "no buffering", the RTS will still allocate a small buffer for use with ungetc().  To completely eliminate dynamic memory allocation, you need to declare your own char array and set that as the buffer using setvbuf, as described in the printf tips wiki page mentioned above.

    There are many unknowns in this test case, so it's hard to narrow down the problem.  Are you still getting a linker error?  Are you running under Code Composer?  What command line options are you using?  Did you remember to include stdio.h?  It would be helpful to see a complete, compilable, reproducable test case.

     

  • Hi Archaeologist,

    Are there any examples that one can look at it. Because I,ve tried everything, still it does not work. Here is a small code that I wrote:

    Uint16 static_array[200];

    void main(void)
    {  
       InitSysCtrl();

     
    // Disable CPU interrupts
       DINT;

    // Initialize PIE control registers to their default state.
       InitPieCtrl();

    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;

    // Initialize the PIE vector table (ISR).
       InitPieVectTable();
      
       fid = fopen("Data_log.txt","w");
       setvbuf(fid,
    (static_array, _IOLBF, sizeof(static_array));
       fclose(fid);


        LoopCount = 0;
        ErrorCount = 0;

        for(;;)
        {
           LoopCount++;
        }

    }

    My linker file:

    MEMORY
    {
    PAGE 0 :
       /* For this example, L0 is split between PAGE 0 and PAGE 1 */
       /* BEGIN is used for the "boot to SARAM" bootloader mode   */

       BEGIN      : origin = 0x000000, length = 0x000002
       RAMM0      : origin = 0x000050, length = 0x0003B0
       PRAML0     : origin = 0x008000, length = 0x001000     /*: origin = 0x008000, length = 0x000900*/
       RESET      : origin = 0x3FFFC0, length = 0x000002

       BOOTROM    : origin = 0x3FF27C, length = 0x000D44


    PAGE 1 :

       /* For this example, L0 is split between PAGE 0 and PAGE 1 */
       BOOT_RSVD   : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */
       RAMM1       : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
       DRAML0      : origin = 0x008900, length = 0x007000
    }


    SECTIONS
    {
       /* Setup for "boot to SARAM" mode:
          The codestart section (found in DSP28_CodeStartBranch.asm)
          re-directs execution to the start of user code.  */
       codestart        : > BEGIN,     PAGE = 0
       ramfuncs         : > RAMM0      PAGE = 0
       .text            : > PRAML0,    PAGE = 0
       .cinit           : > RAMM0,     PAGE = 0
       .pinit           : > RAMM0,     PAGE = 0
       .switch          : > RAMM0,     PAGE = 0
       .reset           : > RESET,     PAGE = 0, TYPE = DSECT /* not used, */

       .stack           : > RAMM1,     PAGE = 1
       .ebss            : > DRAML0,    PAGE = 1
       .econst          : > DRAML0,    PAGE = 1
       .sysmem          : > DRAML0,     PAGE = 1
       .esysmem         : > RAMM1,     PAGE = 1

    }
    Pls. if one is using controlCARD using USB connection, can it creates problems?

    Thanks.

    Michael


  • From the looks of your test case, I'm guessing that you are not running under Code Composer, or any other debugger that is C I/O aware.  The RTS does include low-level C I/O emulation functions, but these require cooperation with a program (for example, CCS) on a host with real C I/O capability (such as Linux and Windows).  The hosted program needs to to interpret and actually perform the C I/O requests.  If you don't use something like CCS, nothing happens.

    If you are using CCS, and it still won't work, we're going to need more details about what the symptoms are.  When you say it "doesn't work", do you still get a linker error?  Do you get an error when loading the program?  Does the program crash before it reaches fopen()?  Or is the only symptom that the file "Data_log.txt" doesn't appear on the disk?

    Also try the following minimal C I/O program; if it doesn't work, fopen() will certainly not work:

    #include <stdio.h>
    int main() { puts("Hello, world"); }

    Michael Blankson said:

    Pls. if one is using controlCARD using USB connection, can it creates problems?

    I'm sorry, I really don't know anything about the hardware you're using.

  • Hi,

    From the your answer I've included #included <stdio.h> and C/IO. But I still have warning like:

    Loader: One or more sections of your program falls into a memory region that is not writable.  These regions will not actually be written to the target.  Check your linker configuration and/or memory map.

    My small program is:

    #include <stdio.h>

    void main(void)
    {
    // Initialize System Control:
       InitSysCtrl();
     
    // Disable CPU interrupts
       DINT;

    // Initialize PIE control registers to their default state.
       InitPieCtrl();

    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;

       puts("Hello, world");

        LoopCount = 0;
        ErrorCount = 0;

        for(;;)
        {
          //test[LoopCount++];
          //LoopCount++;
        }

    }

    The linker is:

    MEMORY
    {
    PAGE 0 :

       BEGIN      : origin = 0x000000, length = 0x000002
       RAMM0      : origin = 0x000050, length = 0x0003B0
       PRAML0     : origin = 0x008000, length = 0x001000     /*: origin = 0x008000, length = 0x000900*/
       RESET      : origin = 0x3FFFC0, length = 0x000002

       BOOTROM    : origin = 0x3FF27C, length = 0x000D44


    PAGE 1 :

       /* For this example, L0 is split between PAGE 0 and PAGE 1 */
       BOOT_RSVD   : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */
       RAMM1       : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
       DRAML0      : origin = 0x890000, length = 0x009000
    }


    SECTIONS
    {
       codestart      : > BEGIN,     PAGE = 0
       ramfuncs       : > RAMM0      PAGE = 0
       .text               : > PRAML0,    PAGE = 0
       .cinit              : > RAMM0,     PAGE = 0
       .pinit              : > RAMM0,     PAGE = 0
       .switch           : > RAMM0,     PAGE = 0
       .reset             : > RESET,     PAGE = 0, TYPE = DSECT /* not used, */

       .stack            : > RAMM1,     PAGE = 1
       .cio                : > DRAML0,    PAGE = 1
       .ebss             : > DRAML0,    PAGE = 1
       .econst          : > DRAML0,    PAGE = 1
       .sysmem       : > DRAML0,    PAGE = 1
       .esysmem     : > RAMM1,     PAGE = 1

    }

    Pls. can you look at it some is rough with this simple example.

    Thanks.

    Michael.

  • Michael,

    Michael Blankson said:
    Loader: One or more sections of your program falls into a memory region that is not writable.  These regions will not actually be written to the target.  Check your linker configuration and/or memory map.

    Michael Blankson said:
       BOOTROM    : origin = 0x3FF27C, length = 0x000D44

    This block is in the ROM of the device and can not be written to.  My guess is the linker is stuffing something there so you get the error when you try to load the program.  I suggest removing this from the linker file.  Unfortunately think you may run out of memory again when you do this (allocation fails error). 

    -Lori

  • This won't help for puts, but for printf() you can specify different functionality and thus reduce the memory it takes.  See this post for more info:

    http://e2e.ti.com/support/development_tools/compiler/f/343/t/37198.aspx

     

    -Lori