2025-06-27 12:33 AM - last edited on 2025-06-27 1:23 AM by Andrew Neil
Hello Guys,
I’m working on a project using the STM32F767 evaluation board with STM32CubeIDE and FreeRTOS. In this project, I want to create a .csv file inside the MCU’s storage, write data to it, and then share that file over Ethernet.
So far, I have successfully configured the Ethernet communication and can transfer strings between the MCU and PC. However, when I try to create or open the .csv file, my fopen() call returns NULL, and the file is not created.
Code is attached with the post. Please help me.
Thanks.
FILE *f; //Golobal declare for file
void create(void ) //Function to create file,write
{
{
HAL_GPIO_WritePin(GPIOB, LD2_Pin, GPIO_PIN_SET);
f = fopen("trial.txt","w");
if(f == NULL)
{
printf("\nCann't open file");
HAL_GPIO_WritePin(GPIOB, LD2_Pin, GPIO_PIN_RESET);
}
else{
fprintf (f, "Hello World ");
fclose (f);
}
}
}
2025-06-27 1:22 AM - edited 2025-06-27 2:29 AM
You haven't said what filesystem you're using - FatFS? FileX? other?
Is your filesystem correctly/successfully initialising, mounting the device, etc?
As always, start from a known-good example, which just does the file stuff - no other complications (ethernet, etc).
Here's a couple of Knowledge Base articles on setting up a filesystem on STM32:
How to create a file system on a SD card using STM32CubeIDE.
How to use FileX with eMMC for file system management.
Edit: fixed 1st link.
PS:
@B_D_R wrote:using the STM32F767 evaluation board
You mean the NUCLEO-F767ZI ?
https://www.st.com/en/evaluation-tools/nucleo-f767zi.html
2025-06-29 11:01 PM
hello @Andrew Neil
In all the above given examples file was created with in the SD card/USB. Is it possible to make file within the internal flash of controller and then transfer it to the ethernet/USB/Wifi.
Thanks.
2025-06-30 1:17 AM
Because you almost certainly call the wrong function.
The declaration "FILE *f;" suggests you are using FatFS.
However, the corresponding function to open a file in FatFS is called "f_open()".
The fopen() function is a fully Posix compatible function for buffered file access. There is no such thing in FatFS.
2025-06-30 2:09 AM
You still haven't said what filesystem you are using.
As @Ozone showed, this matters!
The FatFS documentation says this:
Media Access Interface
Since FatFs module is the Filesystem Layer independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The storage device control module is not a part of FatFs module and it needs to be provided by implementer. FatFs controls the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads.
So, yes - it can work on any storage medium.
This has come up before - try a forum search.