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.

reading and writing txt file from PC based on TMS570LC43x HDK

Other Parts Discussed in Thread: HALCOGEN, TMS570LC4357

Hello TI engineers,

My program codes can not be run on TMS570LC43x HDK. I do not understand why? Could you help me?

/*this main program part for loading the matrix data*/
float a[1][8281];
int lines=0,r1=1,r2=8281;
FILE *fp1;
int i;
fp1 = fopen("D:\study\Master project\Msc_project\c.txt", "r");
while(lines < r1)
{
for(i = 0; i < r2; i ++)
{
if(fscanf(fp1, "%f", &a[lines][i]) == EOF)
{
break;
}
if(feof(fp1))
{
break;
}
lines++;
}
}
fclose(fp1);

/*this main program part for loading statistics algorithm*/
int j,n,t,q[r1][r2];
int m=0;
for(j=0;j<r1;j++)
{
for(n=0;n<r2;n++)
{
m=0;
for(t=0;t<r2;t++)
{
if(t!=n)
{
if(a[j][n]-a[j][t]==0)
{
m++;
q[j][n]=m;
}
}
}
}
}

int r,k,max;
float b[r1][1];
for(r=0;r<r1;r++)
{
max=q[0][0];
for(k=0;k<r2;k++)
{
if(q[r][k]>max)
{
max=q[r][k];
b[r][1]=a[r][k];
}
}
}

r=0,k=0;
float c[r1][r2];
float d[r1][r2];
for(r=0;r<r1;r++)
{
for(k=0;k<r2;k++)
{
d[r][k]=c[r][k];
c[r][k]=fabs(a[r][k]-b[r][1])/401;
c[r][k]=c[r][k]+d[r][k];
}
}

r=0,k=0;
int ecol,erow;
float e[91][91];
for(r=0;r<r1;r++)
{
for(k=0;r<r2;k++)
{
ecol=k%91;
erow=k/91;
e[ecol][erow]=c[r][k];
}

}

FILE *fp2;
int ec,er;
fp2 = fopen("D:\study\Master project\Msc_project\out.txt","w");
for (ec = 0; ec < 91; ec++)
{
for (er = 0; er < 91; er++)
{
fprintf(fp2, "%f ", e[ec][er]);
}
fputc('\n', fp2);
}
fclose(fp2);

should I set something in HALCoGen and CCS?

thanks!

Regards!

Xinyu

  • Xinyu Wang said:
    My program codes can not be run on TMS570LC43x HDK

    Without specific details on what errors you are getting difficult to provide help.

    However, from looking at the posted code some comments:

    1) The compiler is reporting a "warning #194-D: unrecognized character escape sequence" on the following two lines:

    	fp1 = fopen("D:\study\Master project\Msc_project\c.txt", "r");
    	fp2 = fopen("D:\study\Master project\Msc_project\out.txt","w");

    The backslashes in the Windows pathname need to be escaped, as otherwise won't open the files. i.e. change to:

    	fp1 = fopen("D:\\study\\Master project\\Msc_project\\c.txt", "r");
    	fp2 = fopen("D:\\study\\Master project\\Msc_project\\out.txt","w");

    2) The program allocates "large" arrays of floats on the stack. A initial analysis using the call_graph utility shows that at least 67764 (0x108B4) bytes of stack space are required. The default user stack length allocated by HALCoGen is 0x1500 bytes. Therefore, unless the user stack length has been set to allow for the stack usage by the program, the program will crash with an exception when attempt to run. Either:

    a) In HALCoGen under the TMS570LC4357ZWT -> RAM increase the User Stack Length to say 0x12000

    b) Change the large arrays to be global variables, rather than being allocated on the stack.

  • Hello Chester,

    2)b) how to set large arrays and stack in HALCoGen or CCS?

    Thanks!

    Regards!
    Xinyu
  • Hi Chester,

    there is no error. But no txt file is used. All variable value are 0 such as following picture

    I think the data in c.txt file is not applied. How to fix this problem. And no out.txt file is generated by this program.

    Thanks!

    Regards!

    Xinyu

  • Xinyu,

    Why don't you start with a simple program first, like something that just prints a string "Hello World" to the file and then closes the file.

    Then when you have this working and you are comfortable with the mechanics of the semihosting .. start building your bigger program up.

    -Anthony
  • Hello Anthany

    I have tried "Hello World" program. it succeeded.But it is so short. my data is vast. the most important is that data is not input into processor.

    thanks!
    Regards!

    Xinyu
  • That's great.

    So if you have already done the simple stuff, reading and writing small files from the PC, then you need to
    understand that this is an embedded system and the memory on chip is somewhat limited.

    It is only 512K bytes of on-chip SRAM total for the LC4357.

    You cannot use more RAM than this without adding more to the launchpad. (you would need a custom PCB to do this..)

    If you can fit in 512K bytes, you could increase your stack size for User/System mode in HalCoGen... Or you could declare an array as global in which case it won't be on the stack but it'll be linked into SRAM. Or you could use the heap.

    But none of these options will allow you to use more SRAM than the device has onboard.

    So if you need more than 512K bytes of array you will need to think about maybe randomly reading smaller segments from the file on the PC.. rather than reading in all the data at once.
  • BTW, our summer intern just left and she did design a PCB to add an SDRAM to the RM57L/TMS570LC4357 launchpad..
    We haven't tested it yet but could share the file w. you if you want to test it yourself.
  • Hello Anthony,

    I konw. but my program can not input data. should I set more in HALCoGen? I am very confused. Or I need to fix my main codes?

    Thanks!
    Regards!

    Xinyu
  • Sorry don't understand the question.

    In a nutshell though the chip only has 512K RAM which is a lot for a microcontroller, but is tiny for a PC.
    So you need to work within that bound or add more RAM externally (on the EMIF).
  • Let me ask specifically - will your data set fit inside 512K bytes? Or is it bigger?
  • Xinyu Wang said:
    My program codes can not be run on TMS570LC43x HDK

    Can you confirm you are using the Hercules TMS570LC43x Development Kit, rather than the Hercules TMS570LC43x LaunchPad Development Kit.

    There seems to be some confusion in this thread about which is being used.

    The Hercules TMS570LC43x Development Kit  (HDK) has an external 8MB SDRAM which can be used for "large" data, while the Hercules TMS570LC43x LaunchPad Development Kit only has the internal 512KB memory.

  • Hello Anthony,

    it is bigger than 512K. it is 401*8281 matrix in a txt file.

    regards!

    Xinyu
  • it is LauchPad.

    regards!

    Xinyu
  • Hi Xinyu,

    So if it is a LaunchPad, and your matrix is 401x8128 (if that is float data, then once you convert from text to float that would be 13Mbytes..)

    You have maybe four choices:

    1) operate on portions of the matrix at a time, whatever can fit in on chip memory, and read/write back to the PC.
    this is going to be slow...

    2) buy an HDK with additional SDRAM although even then you'll need to increase the size of the SDRAM. The HDK uses a BGA SDRAM so this is going to be expensive ($200 ish) and hard to do (because of soldering/removing BGA).

    3) be a pipe-cleaner for the SDRAM expansion board our intern created ;) I haven't even looked at it yet -- it's fresh off the press..
    so it's got some risk. this would cost you probably < $100 if you order overseas like 'dirtypcb' and she used a 54TSSOP SDRAM
    so it's easier to solder...

    4) Switch to a different ARM board if you want to benchmark on ARM. You could go to something like a 'beaglebone black'
    for example .. www.adafruit.com/.../1996
    Of course this is a completely different processor and if you work in Linux the development environment is completely different.
    But you can I think use the Student version of MATLAB w. this board which may be a good fit if you are doing matrix work.

    Just some ideas for you... Good luck.

    -Anthony
  • Hello Anthony,

    My tutor ask me do project on this LauchPad. So I can only deal with this matrix one level by one level. But even I do one by one, data still can not be input into this processor. Becuase I can see all values in the matrix are 0. Could help me to fix this problem? I just connect this LauchPad and PC by USB.

    Thanks!

    Regards!
    Xinyu
  • Xinyu Wang said:
    Becuase I can see all values in the matrix are 0.

    Which compiler are you using?

    The reason for the question is that details of "semi-hosting", to allow the target to read/write files on the host, varies according to the compiler used.

  • I'd suggest this:

    1) Take your array and cut it down to something trival, like a 4x4 array...

    2) try reading the array into memory just as 'char' (text) without converting it.

    3) then add string conversion functions to convert the string in the processor memory to the numeric value.

    if you can get this working then you should be able to:
    a) merge the file read and string conversion into a single formatted input function call.
    b) scale up to a larger file size

    but in the interim you'll be able to separate the steps to see where you are losing data...

    Anyway good luck. At this point I don't think there's anything wrong w. the toolset but it's a good exercise
    for learning how to work on the embedded parts so your prof is challenging you :)

    -Anthony
  • Hello Chester,

    I only use HALCoGen and CCS. But I do not understand why it can not read files from host?

    Thanks!

    Regards!
    Xinyu
  • Hello Anthony,

    I hope i can pass my report. it is the last thing in my master study.

    Regards!

    Xinyu