cancel
Showing results for 
Search instead for 
Did you mean: 

LwIP TFTP on STM boards

I was struggling to get LwIP TFTP server working on MCU boards (NUCELO-H743ZI). After debugging I have found:

  1. Why is TFTP_MAX_MODE_LEN defined as 7 (instead of >= 8)?
  2. Why is TFTP_MAX_FILENAME_LEN just defined as 20?

So, it results in:

  • sending (PUT) or receiving a file (GET) via TFTP client on Windows 10 (install Windows Features for 'tftp' available on CMD line) - without option -i - does not work! ('mode' is set as "netascci" which has 8 characters!)
  • If you want to transfer a file with name longer as 20 characters (including the dot) - it will not work!

OK, working now (if you need details or code ... don't hesitate ...).

Just to bear in mind as well: you had to set macro LWIP_UDP to 1 as well! (even TCP HTTPD server runs already fine).

So, LwIP TFTP server works, but not from scratch, some settings are needed to be modified.

3 REPLIES 3

BTW: if you want to test LwIP TFTP - no need to have FatFS, SD Card etc. on your system running. You can 'satisfy' TFTP with dummy functions, e.g.:

static FILE tftpFileHandle;
static int xLen = 0;		//just to manage READ requests
 
void* TFTP_open(const char* fname, const char* mode, u8_t write)
{
	xLen = 256;							//for testing - the file length
 
	/* open a file, use the write flag for creating new file or open for read */
	return (void *)&tftpFileHandle;
	/*
	 * return a valid file pointer handle (not NULL), not used in LwIP TFTP, just forwarded
	 * to the Read, Write and Close file system functions
	 */
}
 
void  TFTP_close(void* handle)
{
	/* close the file handle */
}
 
int   TFTP_read(void* handle, void* buf, int bytes)
{
	int availBytes = 0;
	int xbytes = bytes > xLen ? xLen : bytes;
	char *xbuf = (char *)buf;
	while (xLen)
	{
		*xbuf++ = xLen--;
		availBytes++;
	}
 
	/* function returns the number of bytes read, e.g. a full chunk, or shorter last chunk,
	 * or <0 for EOF
	 */
	if (availBytes > 0)
		return availBytes;		//how many bytes were available, could be read
	else
		return -1;				//EOF
}
 
int   TFTP_write(void* handle, struct pbuf* p)
{
	/* return how many bytes were written */
	return p->len;
}
 
/* initialize the TFTP handler functions for the file system */
const struct tftp_context TFTPctx = {
		TFTP_open,
		TFTP_close,
		TFTP_read,
		TFTP_write
};

IOvch
Associate II

Hello, Torsten Jaekel !

It would be very nice to see your code, can you please share it?

Best regards, IOvch

Aurentiaco
Associate III

Hello @Torsten Jaekel',

I would like to see your code if there is a chance could you share it with me?

Best regards,
Eray