Building and Running an Example Application

Working Project with µC/TCP-IP

The first step before including µC/TFTPc is to have a working project with µC/TCP-IP. As previously mentioned, Micriµm may offer an example with the µC/OS-III kernel, µC/TCP-IP and even µC/TFTPc for many evalboards. 

If no project with µC/TCP-IP is available for your platform, you should follow the µC/TCP-IP Getting Started Guide to ensure you have a working project before installing µC/TFTPc. Then you can follow the steps to build and run your first µC/TFTPc sample application shown below.

Including µC/TFTPc Stack Source Code

Configuring Compiler settings

Add the following include paths to your project’s C compiler settings:

\Micrium\Software\uC-TFTPc

Copying and Modifying Template Files

Copy the file from the µC/TFTPc configuration folder into your application as illustrated below.


Figure - TFTPc Template File Copy


Adding µC/TFTPc Example Application Code

The file app.c contains the application code, and was written to illustrate the capabilities of the µC/TFTPc module. That code simply initializes the RTOS, µC/TCP-IP, and µC/FS, and creates a few tasks and other kernel objects that will give the user information about the state of the system.

Note that some sections of the source code have been removed or modified to help focus on the µC/TFTPc module use.


Listing - TFTPc Example Application Code
#define  TFTPc_TEST_SERVER_IP               "192.168.1.102"
#define  TFTPc_TEST_SERVER_PORT                         69 
            
#define  TFTPc_TEST_FILE_NAME_LOCAL          "\\file_local"
#define  TFTPc_TEST_FILE_NAME_REMOTE_GET  "file_remote_get"
#define  TFTPc_TEST_FILE_NAME_REMOTE_PUT  "test_remote_put"
            
static  void  App_TestTFTPc (void) 
{ 
    NET_IP_ADDR  ip_server; 
    NET_ERR      err_net; 
    TFTPc_ERR    err; 
            
            
    ip_server = NetASCII_Str_to_IP(TFTPc_TEST_SERVER_IP,                                     /* See Note #1. */
                                  &err_net); 
    if (err_net != NET_ASCII_ERR_NONE) { 
        printf("Error - NetASCII_Str_to_IP: %d\n\r", err_net);   
        return; 
    }
     
    TFTPc_Init(&TFTPc_Cfg, &err);                                                            /* See Note #2. */
    if (err != TFTPc_ERR_NONE) {
        printf("Error - TFTPc Initialization: %d\n\r", err);  
        return; 
    }
 
    (void)TFTPc_Get(DEF_NULL,                                                                /*See Note #3. */
                    TFTPc_TEST_FILE_NAME_LOCAL, 
                    TFTPc_TEST_FILE_NAME_REMOTE_GET, 
                    TFTPc_MODE_NETASCII,
                   &err); 
    if (err != TFTPc_ERR_NONE) { 
        printf("Error - TFTPc_Get: %d\n\r", err); 
    } 
             
    (void)TFTPc_Put(DEF_NULL,                                                                /*See Note #4. */
                    TFTPc_TEST_FILE_NAME_LOCAL, 
                    TFTPc_TEST_FILE_NAME_REMOTE_PUT, 
                    TFTPc_MODE_NETASCII,
                   &err);  
    if (err != TFTPc_ERR_NONE) { 
        printf("Error - TFTPc_Put: %d\n\r", err); 
    }
}
  1. Converts the ASCII dotted-decimal notation to a network protocol IPv4 address.
  2. Initializes the TFPTc suite.
  3. Initiates a “GET” request, that is a request for reading (RRQ) from the default server configuration.
  4. Initiates a “PUT” request, that is a request for writing (WRQ) to the default server configuration.