cancel
Showing results for 
Search instead for 
Did you mean: 

Problem where fopen() a bitmap file returns "Not enough space"

t-oka
Associate III
Hello community,
 
■Problems occurring:
When I tried to open a bitmap file with the fopen function as shown below, 
I encountered a problem that returned "Not enough space".
Do I need to change any settings on the STM32CubeID side?
Please help us solve it.
*1. It has been confirmed that the target directory and file exist.
*2. There is enough free space on C drive.
 
■Environment:
・Windows
・STM32CubeIDE_1.12.1
・nucleo-f207zgt6
・C language
・001.bmp (225 KB (230,538 bytes))
 
■Code:
char* path = "C:\\〇〇";
fileName = "C:\\〇〇\\001.bmp";
    if (access(path, F_OK) == 0) {
        struct stat st;
        if (stat(fileName, &st) == 0) {
        if ((BmpFp = fopen(filename,"rb"))==NULL) {
            // Result of the following processing: Not enough space
            char* er = strerror( errno );
            exit(1);
        }
    }
}
1 ACCEPTED SOLUTION

Accepted Solutions
Oskar_H
Senior

Hello t-oka,

We are lacking a little of your context. What are you trying to do exactly with this bitmap ?

Do you intend to do data processing on the pixels and save the result file, or do you need to display it as is on a screen ?

As the others already said, it is not possible to read entirely such a big image in MCU memory.

Maybe you could start by reading the documentation file provided in the FW pack here:

STM32Cube_FW_F2_V1.9.4/Projects/NUCLEO-F207ZG/Demonstrations/readme.txt

This demonstration displays a 128x160 pixels BMP image on a Adafruit 1.8" TFT connected to the Nucleo board extension.

You will need also to store the image on a microSD card inserted in the slot.

If that does not fit your needs, you would have to switch to an EVAL board with more capabilities...

View solution in original post

10 REPLIES 10
Peter BENSCH
ST Employee

Welcome @t-oka, to the community!

You want to open a BMP of 225KB into the STM32F207ZGT6?

Even if I subtract the usual header of 54 bytes (may vary slightly), that still leaves 230484 bytes that have to fit into the RAM of the STM32F207ZGT6. However, it only has 132KB RAM in total, which is also divided into 112KB + 16KB + 4KB backup RAM.

What format uses the BMP exactly?

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Peter, thanks for watching!

■I will respond below.:
>>You want to open a BMP of 225KB into the STM32F207ZGT6?
 →Yes, that's right.

>>Even if I subtract the usual header of 54 bytes (may vary slightly),
>>that still leaves 230484 bytes that have to fit into the RAM of the STM32F207ZGT6.
>>However, it only has 132KB RAM in total, which is also divided into 112KB + 16KB + 4KB backup RAM.
 →I tried setting the BMP file size to 1KB for reference, but it still returned "Not enough space".

>>What format uses the BMP exactly?
 →I would like to use it in binary format.
  ※I would like to open a file ⇒ Read binary ⇒ Display on STM32F207ZGT6.

If possible, please continue to cooperate.

Peter BENSCH
ST Employee

As far as I remember, fopen allocates the object (in your case the file) in the heap, which must be selected accordingly large. Depending on the other use of the heap, a BMP with a payload of 1KB could already be too large for this.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Peter, thank you again.

>> fopen allocates the object (in your case the file) in the heap.
How do you respond specifically?
If the fopen () function cannot be used, is there a way to open a bitmap file in another way?

Piranha
Chief II

The author is trying to open a file on a Windows PC by calling fopen() on a microcontroller...

I am voting for this as the topic of the year! 😂

>>is there a way to open a bitmap file in another way?

Host the file locally rather than using semi-hosting?

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

@t-oka So are you trying to open a file using semihosting? Then use low-level I/O (_open, _read, etc. ) instead of fopen because stdio functions do a lot of buffering. The names of low-level I/O functions are different in different toolchains (Keil/IAR/GNU).

Oskar_H
Senior

Hello t-oka,

We are lacking a little of your context. What are you trying to do exactly with this bitmap ?

Do you intend to do data processing on the pixels and save the result file, or do you need to display it as is on a screen ?

As the others already said, it is not possible to read entirely such a big image in MCU memory.

Maybe you could start by reading the documentation file provided in the FW pack here:

STM32Cube_FW_F2_V1.9.4/Projects/NUCLEO-F207ZG/Demonstrations/readme.txt

This demonstration displays a 128x160 pixels BMP image on a Adafruit 1.8" TFT connected to the Nucleo board extension.

You will need also to store the image on a microSD card inserted in the slot.

If that does not fit your needs, you would have to switch to an EVAL board with more capabilities...

Hello Oskar_H, thanks for watchi

>>We are lacking a little of your context. What are you trying to do exactly with this bitmap ?
>>Do you intend to do data processing on the pixels and save the result file, or do you need to display it as is on a screen ?
 ⇒Thank you for pointing this out. I will process the data for the pixels and display them on the screen as they are.

>>As the others already said, it is not possible to read entirely such a big image in MCU memory.
>>Maybe you could start by reading the documentation file provided in the FW pack here:
>>STM32Cube_FW_F2_V1.9.4/Projects/NUCLEO-F207ZG/Demonstrations/readme.txt
>>This demonstration displays a 128x160 pixels BMP image on a Adafruit 1.8" TFT connected to the Nucleo board extension.
>>You will need also to store the image on a microSD card inserted in the slot.
>>If that does not fit your needs, you would have to switch to an EVAL board with more capabilities...
⇒Thank you, as others have mentioned, instead of preparing the image on the PC,
save it on an SD card or something and use it.
 And I would like to read the demo you gave me and try again.

Thank you for your detailed explanation.