cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to receive file via tftp

jmyoo
Associate II

I am working on a tftp client program that receives a file from a tftp server.

I found the tftp client library below and ported it.

https://github.com/particle-iot/lwip/blob/master/contrib/examples/tftp/tftp_example.c

 

The file is received in debugging mode, but it is not received at runtime.

I checked and confirmed that 'fopen' does not work at runtime. I don't know why.

Below is the fopen code. 

-------------------------------------------------------------------------------------

static void *
tftp_open_file(const char* fname, u8_t is_write)
{
snprintf(full_filename, sizeof(full_filename), "%s%s", LWIP_TFTP_EXAMPLE_BASE_DIR, fname);
full_filename[sizeof(full_filename)-1] = 0;

if (is_write) {
return (void*)fopen(full_filename, "wb");
} else {
return (void*)fopen(full_filename, "rb");
}
}

-------------------------------------------------------------------------------------

I tried delaying before the tftp_client_init() function because it seemed to be a timing issue.

Please help.

 

8 REPLIES 8
Pavel A.
Evangelist III

Do you know why fopen works in debug mode? Do you use semihosting? 

 

Imen.D
ST Employee

Hello @jmyoo ,

Ensure that the tftp configuration parameters are correctly set and the tftp server software is up to date and properly configured.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

I don't know

Please let me know

Yes, I found it and read the contents.

How do I make it work at runtime?

No

Hi, usually fopen on embedded board works via semihosting - unless of course the embedded software has some filesystem, not your case.

So the answer is, without the debugger connection it won't work. If you have some other connection to the host (serial, ethernet, USB and so on) you can write code for STM32 to access files on the host and even your own fopen function.

 

Thank you. Now I understand.

So you mean to use fatfs for embedded. Am I right?

Then can I write files to internal flash memory too?

If your files are on some storage device or memory that can work with fatfs then yes, you can use fatfs.

But the internal flash is very limited. Fatfs is not the good way to write to it.