cancel
Showing results for 
Search instead for 
Did you mean: 

How to open files on Host PC with fopen on STM32L5

Domy_ST
Associate III

Title edited to clarify that this is about accessing a file located on a Host PC


hello ST Community,

I'm trying to open a binary file with the fopen function for a STM32L5 microcontroller, but it always gives me a null value. The code is like this:

char filepath[256];
sprintf(filepath,"%s","C:\\fileBIN.bin");
		  
FILE *file;
file = fopen(filepath,"rb");
if(file == NULL)
{
   printf("Error occurred opening file. \r\n");
}
else
{
   printf("File opened successfully. \r\n");
}

 

It always gives me a null value but the path exists and is correct. What's wrong?

Thanks for supports

 

23 REPLIES 23

@KnarfB wrote:

downside is, that this requires a driver on the host and is said to be slow. 


Indeed.

@Domy_ST it also relies upon the debug interface - so you might just as well use that directly to do the programming!

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.
Andrew Neil
Super User

@Domy_ST  I think your question about getting the bin file into a bootloader is now solved, so please mark the solution on whichever post you feel provided the best answer.

 

New question about issues with Semihosting split to a separate thread: Semihosting error: "Protocol error with Rcmd".

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.

hi @Andrew Neil 

I haven't solved it yet. Before proceeding with YMODEM, I was about to try the semi-hosting solution, but there's a problem with rcmd. As soon as I fix it, I'll mark it as solved.

The original question of "How to open a file on a PC from an STM32" has been answered (and turned out to be the wrong question anyhow).

"How to do YMODEM" and "How to do Semihosting", etc,  are separate follow-on questions.

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.