FreeRTOS+TCP and FreeRTOS+FAT Examples
Running on an Atmel SAM4E ARM Cortex-M4 microcontroller
IntroductionDon’t have any hardware? You can still try the RTOS TCP and FAT examples now by using the Win32 demo, which builds with free tools, and runs in a Windows environment.
The Atmel SAM4E ARM Cortex-M4 TCP/IP and FAT demo includes the following standard examples:
- HTTP web server
- FTP server
- TCP echo server
- TCP echo clients
- Command line interface using a UDP socket
- UDP logging; sending FreeRTOS+TCP log output to a UDP port
FreeRTOS+FAT is used to mount a FAT formatted SD card. The mounted file system then provide the storage for both the HTTP and FTP server examples.
Locating the ProjectThe Atmel Studio project that builds the demo described on this page is located in the /FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_and_FAT_ATSAM4E directory of the FreeRTOS Labs download.
Software Setup #1: Setting a Static or Dynamic IP Address
Network address settings in FreeRTOSConfig.h
If a DHCP server is used on the network to which the SAM4E is connected, then set ipconfigUSE_DHCP to 1 in FreeRTOSIPConfig.h, and no further IP related network address configuration is necessary. If a hostname is configured then it is not necessary to know the IP address assigned to the SAM4E by the DHCP server because the SAM4E can be addressed directly by its hostname. The IP address can however be viewed, as it is printed out using the UDP logging facility.
If there is no DHCP server connected to the network then set ipconfigUSE_DHCP to 0 in FreeRTOSIPConfig.h, and instead configure the IP address and netmask manually using the configIP_ADDR0/3 and configNET_MASK0/3 constants in FreeRTOSConfig.h. Note the IP address constants are in FreeRTOSConfig.h, rather than FreeRTOSIPConfig.h, because they are related to the application, and not the TCP/IP stack directly.
It is necessary to ensure a manually configured IP address is compatible with the netmask. In most cases a compatible IP address will be one that uses the same first three octets as the host computer. For example, if the IP address of the host computer is 172.25.218.100, then any 172.25.218.nnn address, other than when nnn is 0, 255, or already present on the network, is compatible.
It is also necessary to set a gateway address that is correct for the network to which the SAM4E is being connected, or at least compatible with the netmask if no gateway exists. This step is necessary to prevent an internal sanity check triggering a configASSERT() failure. The gateway address is set using the configGATEWAY_ADDR0/3 constants in FreeRTOSConfig.h.
Software Setup #2: Setting the MAC AddressThe MAC address is set using the configMAC_ADDR0/5 constants in FreeRTOSConfig.h.
If only one target that is running a FreeRTOS+TCP example is connected to the network then it will not be necessary to modify the MAC address.
If multiple targets that are running FreeRTOS+TCP examples are connected to the same network then it will be necessary to ensure each target has a unique MAC address.
If only one target that is running a FreeRTOS+TCP example is connected to the network then it will not be necessary to modify the default hostname, which is set to “RTOSDemo”. If multiple targets that are running FreeRTOS+TCP examples are connected to the same network then it will be necessary to assign a different hostname to each target.
The hostname is set by the mainHOST_NAME constant at the top of the main.c source file. Depending on the network topology, it may also be possible to use a second hostname set by the mainDEVICE_NICK_NAME constant, which is also defined at the top of main.c.
Software Setup #4: Setting the Echo Server AddressIf the TCP echo client example is used then set the constants configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 in FreeRTOSConfig.h to the IP address of a suitable echo server. FreeRTOS+TCP will then send echo requests to, and receive echo replies from, the configured echo server.
Logging configuration in FreeRTOSConfig.h
Log messages are buffered for transmission by a low priority background RTOS task.
Log output can be viewed in many different terminal programs, including UDPTerm, from Cinetix.
Software Setup #6: Hardware Specific SettingsThe project is delivered pre-configured to execute on a SAM4E Xplained Pro evaluation board. It may be necessary to update the IO configure to use the demo on different hardware, or update the network driver if a different PHY is used.
Running ExamplesThe instructions below describe how to build, download then execute the application on a SAM4E Xplained Pro evaluation board:
Follow the software configuration steps detailed above.
If available, insert a clean FAT formatted SD card into the
SAM4E Xplained Pro’s SD card socket.
Inspect the comments at the top of main.c, and set the constants
that build individual examples into and out of the demo.
Note: If an SD card is not being used then do not include the HTTP or FTP server examples.
Ensure the SAM4E Xpalained Pro hardware is connected to the host
computer (the computer running Atmel Studio) using the target’s
debug USB port, and a suitable network using an Ethernet cable.
First press F7 to build the project, and then press F5 to
program the target flash memory, and start the application
LED0 will toggle every half second when the application is executing.
Basic Connectivity TestIt is advised to test basic connectivity before experimenting with the examples linked below. This can be done by pinging the target. If ping replies are received, then the application is both running and connected to the network correctly.
To ping the device, open a command prompt and type “ping
If a ping reply is not received then turn DHCP off, assign the target a
static IP address, and try again using the assigned IP address in place of the host
Instructions describing how to set a static IP address, and how to set
a hostname, are provided in the setup instructions on this page.
Pinging the target, and receiving ping responses
The project includes the following examples:
If a ping reply is not received then turn DHCP off, assign the target a static IP address, and try again using the assigned IP address in place of the host name.
Instructions describing how to set a static IP address, and how to set a hostname, are provided in the setup instructions on this page.