Page 1 of 1

Use fopen() function to read txt file.

Posted: Wed Nov 07, 2018 2:40 pm
by filipESP
Hi,
I have simple function to read txt file and I call it in the app_main(), but the returned value from fopen() is NULL.
File devices.txt is placed in main directory of project.

Code: Select all

void read(){
	FILE *ptr_file;
	char buf[1000];

	ptr_file = fopen("devices.txt","r");
	if (!ptr_file)
		printf("%s","error");
	else{
		while (fgets(buf,1000, ptr_file)!=NULL)
		printf("%s",buf);
		fclose(ptr_file);
	}
}

Re: Use fopen() function to read txt file.

Posted: Thu Nov 08, 2018 1:27 am
by ESP_igrr
Hi Filip,

The capability to access files present on the host computer file system (know as semihosting) is in development, and isn't released yet.
At the moment you can store files on the ESP32 itself using SPIFFS or FAT partitions in the internal flash, or on the SD card. See the examples in examples/storage directory of IDF.

Re: Use fopen() function to read txt file.

Posted: Fri Nov 09, 2018 10:40 am
by Ritesh
ESP_igrr wrote:Hi Filip,

The capability to access files present on the host computer file system (know as semihosting) is in development, and isn't released yet.
At the moment you can store files on the ESP32 itself using SPIFFS or FAT partitions in the internal flash, or on the SD card. See the examples in examples/storage directory of IDF.
Hi ESP_igrr,

Which type of file system will be used with that support?

Re: Use fopen() function to read txt file.

Posted: Fri Nov 09, 2018 10:53 am
by ESP_igrr
Whichever filesystem your host PC has... basically we redirect open/read/write/seek/close calls to the host, where openocd process executes them on our behalf. The redirection capability is already part of ESP-IDF and OpenOCD, and is used for coverage profiling (Gcov) feature. What we don't have yet is 1) a VFS driver in ESP-IDF which would use these semihosting calls, and 2) a convenient way to tell OpenOCD to accept these semihosting calls and map them to certain directory. Both of these features are in our plan, though.

Re: Use fopen() function to read txt file.

Posted: Fri Nov 09, 2018 3:07 pm
by Ritesh
ESP_igrr wrote:
Fri Nov 09, 2018 10:53 am
Whichever filesystem your host PC has... basically we redirect open/read/write/seek/close calls to the host, where openocd process executes them on our behalf. The redirection capability is already part of ESP-IDF and OpenOCD, and is used for coverage profiling (Gcov) feature. What we don't have yet is 1) a VFS driver in ESP-IDF which would use these semihosting calls, and 2) a convenient way to tell OpenOCD to accept these semihosting calls and map them to certain directory. Both of these features are in our plan, though.
Thanks for providing update. We will be waiting for update regarding same.