Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

Host File System not working

AAlas3
New Contributor I
363 Views

Hey,

I built a simple Qsys system with Nios inside it and I would like to write and read from file in host machine, so I wrote the following:

 

#include "stdio.h"

#include "alt_sys_init.c"

 

int main()

{

FILE* ptr = fopen("Test.txt","w");

fprintf(ptr,"Helloooooo");

fclose(ptr);

return 0;

}

when I run this in debug mode, ptr is NULL, I checked the Host altera_hostfs but still not working

Help Please

0 Kudos
3 Replies
Ahmed_H_Intel1
Employee
254 Views

Hi,

Please first, make sure you enable the altera_hostfs package by opening the BSP editor>>Software Packages tab>> Check the box in front of the altera_hostfs package.

 

Next is a sample code to read and write to a file at the host:

 

#include <stdio.h> #include <stdlib.h> #include <string.h>   #define BUF_SIZE (50)   int main(void) {   FILE= fp_ascii = NULL; FILE = fp_bin = NULL; char buffer[BUF_SIZE]; int read_size=1;   /* Reading ASCII File from the host*/ fp_ascii = fopen("file path", "r"); if (fp_ascii == NULL) { printf("Cannot open the file\n"); exit(1); } fgets(buffer, sizeof(buffer), fp_ascii); printf("%s", buffer); fclose(fp_ascii);     /* WriteASCII File from the host*/ fp_ascii = fopen("file path", "w"); if (fp_ascii == NULL) { printf("Cannot open the file\n"); exit(1); } strcpy(buffer, "Hellow from NIOS II"); fputs(buffer, fp_ascii); fclose(fp_ascii);   return 0;       }

 

Regards,

 

AAlas3
New Contributor I
254 Views

It is enabled, anyway I solved the problem: In code when you fopen a file you should write "/mnt/host" with the file path and the pointer will locate the project directory

By the way my name is Ahmad and it is pleasure sir to meet you

Yogesh
Novice
249 Views
So suppose there is a read.txt file in project directory along side main.c code with path as below :

E:/folder1/project/read.txt

What should path of read.txt shd be in main.c file?
mnt/host/read.txt ???
Reply