cancel
Showing results for 
Search instead for 
Did you mean: 

Opening a .bin file in STM32CubeIDE

DriesVR94
Associate II

I am beginner with STM32 microcontrollers and currently building a program on the NUCLEO-F446ZE board in which I would like to open a .bin file and parse the data from this file. So far, I fail to open the file. 

To check whether my code was the problem or not, I tried to open the .bin file using VS Code. Here, it succeeded, so the code by itself is not the problem. This is the code I wrote:

 

int main()
{

    FILE *file;
    char *filepath = "Update_File.bin";

    file = fopen(filepath, "rb");
        if (file == NULL){
            printf("Error occurred opening file. \r\n");
        }
        else {
            printf("File opened successfully. \r\n");
        }   
}
 

When debugging my code in the STM32CubeIDE, I notice the following error related to the 'file' variable: 

0x20020000 <error: Cannot access memory at address 0x20020000>

 

Where is this coming from and how can I solve this error?

 

For info, this is where the .bin file is currently stored:

DriesVR94_0-1711204593838.png

Thanks in advance!

 

 

7 REPLIES 7
Pavel A.
Evangelist III

Are you trying to open a file on the PC using semihosting?

 

Hello Pavel,

Thank you for answering. This is the first time I hear about semihosting. What I understand from a quick online search is that it allows an embedded system (i.e., NUCLEO-F446 in my case) to communicate with, and utilize resources of my PC (such as the .bin file, for example). Please correct me if I'm wrong.

So, is semihosting a solution you propose? If yes, could you point me to a good source of further information?

Thanks!

Pavel A.
Evangelist III

@DriesVR94 Yes, if you want to read files from the host via fopen, fread and so on - then the semihosting is a ready solution. But it works only when the debugger is connected, and needs a special runtime library to build with.

See for more details: https://community.st.com/t5/stm32-mcus/how-to-use-semihosting-with-stm32cubeide-and-stm32/ta-p/49742

Keil and IAR IDEs have their own variant of semihosting and build instructions.

.

Typically this type of embedded does not provide for a storage medium or file system.

ie You'd need support for MicroSD card and then something like FatFS or FileX

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

Thanks a lot!

I tried this out and it works indeed when debugging. However, when running the code, it doesn't work anymore. It seems like it doesn't even reach the main() function. If indeed it will work only during debugging, and not during runtime, I don't understand the purpose of semihosting in that case. What am I missing here?

To give you some more insight in what I'm trying to accomplish, I want to send an "update" from one NUCLEO-F446ZE to another NUCLEO-F446ZE through a specific communication protocol (which one is not relevant).

My initial plan is to write a simple "update" and create a .bin file from it. Next, I want one of the boards to read this .bin file and transmit its data to the other board.

Any suggestions on how to achieve this are welcome!

 

 

Pavel A.
Evangelist III

@DriesVR94 There are a lot of uses of semihosting. You can run tests and save logs directly on the host. You can download and program data files without "external loaders" and do custom processing. Finally it can be used to simulate local storage or filesystem that is not ready yet.

My initial plan is to write a simple "update" and create a .bin file from it. Next, I want one of the boards to read this .bin file and transmit its data to the other board.

Great, just find a way to get the bin file onto one of the boards - from the development PC? or from network?

Recently I've found this thing. It is not only a logger, it can read files from SD-card. Slow, but easy.

Ok, interesting.

As a first step, I will try to load the .bin file in an empty sector of the board's Flash memory using the STM32CubeProgrammer (= from the development PC). I think that will get me started for what I want to achieve.

Thanks a lot for all the valuable information!