2026-03-30 6:15 AM - last edited on 2026-03-31 2:32 AM by Gyessine
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
Solved! Go to Solution.
2026-03-31 2:16 AM
@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!
2026-03-31 6:33 AM
@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".
2026-03-31 6:52 AM
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.
2026-03-31 7:12 AM
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.