We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I am trying to print out a file from flash system on ITM dedug channel on STM32, but it only sends the first part, i can't figure out why...
The flash system reads the whole file (20 chars) into a buffer and i print it out with fprintf...
I have retarget the _sys_write to ITM, but it only sends the first 10 chars.
It seems like the fprintf function calls the _sys_write with a buffer of 10char's and then it seems like it forget to call the function again with the for the rest of the buffer, because when i get out of fprint function the last part of file is putted into the ram area where the first part was when printet...
It is proberly small error i have made :(
Here is my code:
#define db_print(...) fprintf(stderr, __VA_ARGS__) char line[80]; /* Read a file from default drive. */ f = fopen ("M:\\xxx.TXT","r"); if (f == NULL) { db_print ("\r\nFile not found!\n"); } else { fgets (line,30, f); db_print ("\r\ndata: %s",line); // process file content fclose (f);
And now the retarget function
int _sys_write (FILEHANDLE fh, const U8 *buf, U32 len, int mode) { #ifdef STDIO if (fh == STDOUT) { /* Standard Output device. */ // for ( ; len; len--) { // sendchar (*buf++); // } return (0); } if (fh == STDERR) { for ( ; len; len--) { if (DEMCR & TRCENA) { while (ITM_Port32(0) == 0); ITM_Port8(0) = *buf++; } } return (0); } #endif if (fh > 0x8000) { return (-1); } return (__write (fh, buf, len)); }
Is there any other function i need to re-target??
Kasper