cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a file on STM32F7 – Returns NULL

B_D_R
Associate III

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

 

1 REPLY 1
Andrew Neil
Super User

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.

via: https://community.st.com/t5/forums/searchpage/tab/message?filter=includeTkbs&q=STM32F7%20file%20system&noSynonym=false&include_tkbs=true&collapse_discussion=true 

 

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 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.