cancel
Showing results for 
Search instead for 
Did you mean: 

Usage of file handling library functions

rdevisetti
Associate II

I tried to use fopen() on STM32Cude IDE, but it is always returning null. Please let me know how I can use the file handing functions on STM32Cube IDE. Please see my code I am using. What printf() will do here?

uint num;

File *fptr;

if ((fptr = fopen("C:\\newprogram.txt","r")) == NULL)

{

printf("Error! opening file");

 

// Program exits if the file pointer returns NULL.

exit(1);

}

 

fscanf(fptr,"%d", &num);

 

printf("Value of n=%d", num);

fclose(fptr);

2 REPLIES 2

There isn't an operating system or file system in operation here.

printf() can be plumbed to a UART, on GCC via _write() in syscalls.c

File system work can be done via FatFs, but you must plumb to a block storage device using SD Card, NOR Flash, USB MSC, etc

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

How can I load a file system or an operating system like Linux to the board (NUCLEO-F767ZI) I am using? Is there any way to load Linux to this board?

How can I use _write() call for printf? Any example available for that? Do I need to connect the UART on the board to my PC to see the data sent from UART?