Hi,
here is what I am using : MQX 4.0.2.2 \ CW 10.2 \ Kinetis K60
I am trying to use the « fopen » on a SDCARD passing a hardcoded string for the filename. For some reason, It fails when I do so :
CfgFile = fopen ("a:\\config.txt", "r");
If I put the name into a ram buffer, then it works :
char FileName[16] = "a:\\config.txt";
CfgFile = fopen (FileName, "r");
I traced into the fopen function and I am not exactly sure what happen, but the loop that scans for all available devices (“ttya:”, “gpio:”, …) doesn’t break at the same place. A difference I can see between the two calls is that the one using the hardcoded string uses a pointer that is not 32 bit aligned (address is “0x1fff0569”) while the second one uses a 32 bit aligned adresss (0x1fffb47c). I am thinking that maybe this does a difference when comparing the strings.
Although I have a workaround for that problem (using a ram buffer), I would very like to know why it does that and how I can avoid it.
Thanks for any advice.
Hello,
No idea why that wouldn't work.
I did a simple test using the web_hvac example and could do the following
log_fp = fopen("c:\\hvac_log.txt","a"); //DES worked
#define LOG_FILE "c:\\hvac_log.txt"
log_fp = fopen(LOG_FILE,"a"); //DES worked
I wonder if something funky with your flash case where the string is not NULL terminated???
As an additional test after closing the file I then re-opened it using following code and it worked fine.
log_fp = fopen("c:\\hvac_log.txt","r");
if (log_fp) {
char temparray[31];
fgets((char *)&temparray[0], (int_32)30, log_fp);
}
Lastly when you step into the fopen() can you use your Variable window to see what the "tmp_ptr" is set to?
In my picture below it is shown as "c:\\hvac_log.txt"
Regards,
David