Use fopen() function to read txt file.

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Use fopen() function to read txt file.

Postby filipESP » Wed Nov 07, 2018 2:40 pm

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);
	}
}

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » Thu Nov 08, 2018 1:27 am

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.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

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

Postby Ritesh » Fri Nov 09, 2018 10:40 am

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?
Regards,
Ritesh Prajapati

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » 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.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

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

Postby Ritesh » Fri Nov 09, 2018 3:07 pm

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.
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: Baidu [Spider], DrMickeyLauer and 72 guests