2025-06-10 7:07 AM - last edited on 2025-06-10 7:17 AM by Andrew Neil
Hi,
I've been trying to configure a STM32H573I-DK board as a TFTP client on NetXDuo TCP/IP stack. Just as a test, I've configured a TFTP server that hosts a simple text file. I wish for the client to be able to open the file and save the contents of the text file (a simple string) to the memory. As of now, the functions nx_tftp_client_create and nx_tftp_client_file_open return NX_SUCCESS(0x00) but that seems to be misleading given that Wireshark decodes no such RRQ. Additionally, nx_tftp_client_file_read returns (0x01) meaning that no packets are received from the server but I am quite sure that the issue is in the client creation. I've attached the TFTP bit of the code below.
P.S. I've verified the server is up and running well. I was able to open the file and read its contents using a different client.
Has anybody been able to get the TFTP client running with NetXDuo on this board/MCU and could provide some insight on how to set it up properly to fulfil the functionality, as mentioned?
(I'm quite new to working with TCP/IP stacks)
NXD_ADDRESS tftp_server_ip_address;
tftp_server_ip_address.nxd_ip_version = NX_IP_VERSION_V4;
tftp_server_ip_address.nxd_ip_address.v4 = IP_ADDRESS(192,168,0,100);
// 1. Creating the TFTP Client
status = nx_tftp_client_create(
&tftp_client,
"TFTP Client",
&NetXDuoEthIpInstance,
&NxAppPool
);
if (status != NX_SUCCESS) {
printf("TFTP Client Start Failed! Error = 0x%x\n", status);
Error_Handler();
}
// 2. Open the file for reading
status = nx_tftp_client_file_open(
&tftp_client,
"test.txt",
tftp_server_ip_address.nxd_ip_address.v4,
NX_TFTP_OPEN_FOR_READ,
NX_WAIT_FOREVER
);
if (status != NX_SUCCESS) {
printf("TFTP Client File Open Failed! Error = 0x%x\n", status);
Error_Handler();
}
// 3. Read the file contents into the buffer block-by-block
while (1) {
status = nx_tftp_client_file_read(
&tftp_client,
&packet_ptr,
1000
);
if (status != NX_SUCCESS) {
printf("TFTP Client File Read Failed! Error = 0x%x\n", status);
nx_tftp_client_file_close(&tftp_client);
return;
}
// Copy the data from the packet to the file buffer
if (buffer_offset + packet_ptr->nx_packet_length <= FILE_BUFFER_SIZE) {
memcpy(file_buffer + buffer_offset, packet_ptr->nx_packet_prepend_ptr, packet_ptr->nx_packet_length);
buffer_offset += packet_ptr->nx_packet_length;
} else {
printf("File buffer overflow!\n");
nx_packet_release(packet_ptr);
nx_tftp_client_file_close(&tftp_client);
break; // Exit the loop if buffer is full
}
// Save length before releasing packet
UINT this_packet_length = packet_ptr->nx_packet_length;
// Release the packet after reading
nx_packet_release(packet_ptr);
// Now check for end of file
if (this_packet_length < 512) {
break; // End of file reached
}
}
// Close the file
nx_tftp_client_file_close(&tftp_client);
2025-06-10 8:49 AM
Hello @cooler and welcome you to ST community,
To better understand and assist you with this issue, could you attach your STM32CubeMX configuration (.ioc file) so i can review your configuration and reproduce the problem.
Best regards,
2025-06-12 1:24 AM
Hey @STackPointer64 ,
It's basically from the example of the same name, I've just added an SNMP agent on top of the example code and then tried enabling the TFTP client.
Thanks in advance!