Skip to main content
Graduate
January 20, 2024
Question

Usage of file handling library functions

  • January 20, 2024
  • 1 reply
  • 1489 views

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

    This topic has been closed for replies.

    1 reply

    Graduate II
    January 20, 2024

    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

    Graduate
    January 20, 2024

    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?