FreeRTOS+TCP on SAM4E Xplained Pro: NetworkInterface.c

I am trying to set up FreeRTOS+TCP on a SAM4E Xplained Pro development board. I have set up the FreeRTOS kernel and it works as intended without +TCP extension. This is my first time trying to build +TCP so apologies for the rough state of the question. I feel like I am missing a step in setting up FreeRTOS+TCP, and I’ve been trying to figure it out for over a week now :confused:

I have added all of the “.c” files from the +TCP source, and the include directory, as well as the BufferManagement (BufferAllocation_2.c) and the GCC compiler files from portable. The include directories have been added to my project to find all the header files. At this point, the project builds correctly and I can upload to the board.

When I try to set up the network interface, however, it all falls apart. I am trying to add the “DriverSAM” files to the project, but when I do the compiler tells me that countless macros and types are undefined. I have added the phyHandling.h and .c files to the project as well, and found the conf_eth.h for the PHY chip I am using. I have also added a freeRTOSIPConfig.h file with the following defined:

#include "conf_eth.h"
#include "FreeRTOSIPConfigDefaults.h"

#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 45
#define ipconfigEVENT_QUEUE_LENGTH (ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5)
#define ipconfigNETWORK_MTU 586
#define ipconfigIP_TASK_STACK_SIZE_WORDS 0x500
#define ipconfigIP_TASK_PRIORITY 3
#define ipconfigZERO_COPY_RX_DRIVER 1
#define ETHERNET_CONF_DATA_OFFSET 2

With all of this set up, I am still getting the following compile errors. I have tried chasing down individual problems and defining things as needed, but I just wind up going down the rabbit hole and getting more and more errors. I don’t know what files I am missing or need to have created to get this to work.

|Error||implicit declaration of function 'pxPacketBuffer_to_NetworkBuffer' [-Werror=implicit-function-declaration]|C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c|788|SAM4E_RTOS121|
|Error||#error This driver works optimal if ipconfigZERO_COPY_TX_DRIVER is defined as 1|C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c|82|SAM4E_RTOS121|
|Error||'configMAC_INTERRUPT_PRIORITY' undeclared (first use in this function)|C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c|590|SAM4E_RTOS121|
|Error||'GMAC_DCFGR_TXCOEN' undeclared (first use in this function)|C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.c|447|SAM4E_RTOS121|
|Error||'gmac_device_t {aka struct gmac_device}' has no member named 'p_tx_buffer'|C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.c|355|SAM4E_RTOS121|
|Error||'p_dev_mm' undeclared (first use in this function)|C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.c|350|SAM4E_RTOS121|

Hello @Mtut,

From where did you download the libraries? I recommend to clone the +TCP main branch, or download an LTS release. In github you can also download the sourcecode as a ZIP file.

The error about pxPacketBuffer_to_NetworkBuffer()" is caused by the fact that your project doesn’t define ipconfigZERO_COPY_TX_DRIVER or ipconfigZERO_COPY_RX_DRIVER.

It also shows this error:

#if ( ipconfigZERO_COPY_RX_DRIVER == 0 )
    #error This driver works optimal if ipconfigZERO_COPY_RX_DRIVER is defined as 1
#endif

I used this copy of FreeRTOSIPConfig.h for my SAM4E project.

It has these macros defined:

#define ipconfigZERO_COPY_RX_DRIVER     ( 1 )
#define ipconfigZERO_COPY_TX_DRIVER     ( 1 )

I have this define in my project:

#define configMAC_INTERRUPT_PRIORITY  ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY )

That is the priority of the GMAC’s ISR, not a task priority. And that is why it appears in FreeRTOSConfig.h.

Note that Atmel’s ASF (Advanced Software Framework) has two instances of gmac.h ( and many other hardware related files ):

component\gmac.h
instance\gmac.h

This is very confusing for many developers and I decided to replace both with a single header file called gmac_SAM.h. it misses this define:

/**< \brief (GMAC_DCFGR) Transmitter Checksum Generation Offload Enable */
#define GMAC_DCFGR_TXCOEN             ( 0x1u << 11 )

I just compiled and linked my ATSAM4E project and looked what gmac.h is included:

/src/ASF/sam/utils/cmsis/sam4e/include/component/gmac.h

gmac_SAM.h includes:

#include "compiler.h"

which includes:

#include "io.h"

which includes:

#include "sam4e.h"

which includes:

#include "sam4e16e.h"

which includes:

#include "component/gmac.h"

And so I found out that “component/gmac.h” is still used.

I’m attaching my copy of this header file: gmac.h.gz (7.5 KB)

Hope that helps.

If you like post your copy of the two config files: FreeRTOSIPConfig.h and FreeRTOSConfig.h, and I will check them.

Ok, adding your version of FreeRTOSIPConfig.h, adding the GMAC interrupt priority to FreeRTOSConfig.h, and defining GMAC_DCFGR_TXCOEN got the project to compile, thanks for that!

I do have a lot of warnings now because a few macros are undefined, and I don’t know where these values would come from. Some of them seem application specific and I can figure out, and it might be intended that these are undefined and default to 0, but I would like to be sure that I’m not missing a nother file somewhere.

Undefined macros:

GMAC_USES_WAKEUP_CALLBACK
ipconfigETHERNET_CROSSED_LINK
ipconfigETHERNET_USE_100MB
ipconfigETHERNET_USE_FULL_DUPLEX
NETWORK_BUFFERS_CACHED
__DCACHE_PRESENT 

Warning Output:

Warning		"__DCACHE_PRESENT" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	96	SAM4E_RTOS121
Warning		"GMAC_USES_WAKEUP_CALLBACK" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.c	808	SAM4E_RTOS121
Warning		"GMAC_USES_WAKEUP_CALLBACK" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.c	975	SAM4E_RTOS121
Warning		"GMAC_USES_WAKEUP_CALLBACK" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.h	277	SAM4E_RTOS121
Warning		"GMAC_USES_WAKEUP_CALLBACK" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.h	277	SAM4E_RTOS121
Warning		"ipconfigETHERNET_AN_ENABLE" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	217	SAM4E_RTOS121
Warning		"ipconfigETHERNET_AN_ENABLE" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	234	SAM4E_RTOS121
Warning		"ipconfigETHERNET_AN_ENABLE" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	640	SAM4E_RTOS121
Warning		"ipconfigETHERNET_CROSSED_LINK" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	236	SAM4E_RTOS121
Warning		"ipconfigETHERNET_USE_100MB" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	221	SAM4E_RTOS121
Warning		"ipconfigETHERNET_USE_FULL_DUPLEX" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	227	SAM4E_RTOS121
Warning		"NETWORK_BUFFERS_CACHED" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\NetworkInterface.c	543	SAM4E_RTOS121
Warning		"__DCACHE_PRESENT" is not defined [-Wundef]	C:\Users\pherrman\Documents\Atmel Studio\7.0\SAM4E_RTOS121\SAM4E_RTOS121\src\Plus-TCP\portable\NetworkInterface\DriverSAM\gmac_SAM.c	619	SAM4E_RTOS121

Also, to answer your first question, I downloaded the +TCP main branch to start this off.

The macro __DCACHE_PRESENT should be defined in one of the library files under CMSIS.
I think that ‘SAM4E’ doesn’t have D-cache, and the macro can be defined as 0
And because of that:

#if !defined( NETWORK_BUFFERS_CACHED )
    /* Enable auto-negotiation */
    #define NETWORK_BUFFERS_CACHED         0
#endif

#if !defined( ipconfigETHERNET_AN_ENABLE )
    /* Enable auto-negotiation */
    #define ipconfigETHERNET_AN_ENABLE     1
#endif

#if !defined( ipconfigETHERNET_AUTO_CROSS_ENABLE )
    /* The device can be connected with a straight or a crossed
     * RJ45 cable. */
    #define ipconfigETHERNET_AUTO_CROSS_ENABLE    1
#endif

#if !defined( ipconfigETHERNET_USE_100MB )
    #define ipconfigETHERNET_USE_100MB    1
#endif

#if !defined( ipconfigETHERNET_CROSSED_LINK )
    #define ipconfigETHERNET_CROSSED_LINK    1
#endif

#if !defined( ipconfigETHERNET_USE_FULL_DUPLEX )
    #define ipconfigETHERNET_USE_FULL_DUPLEX    1
#endif

In practice: 99% of all projects use auto-negotiation, and the setting 100MB/CROSSED/DUPLEX do not matter.

Depending on the settings, the compiler will warn about undefined macro’s. With some settings, the compiler will silently assume that “not defined” means “0”, or “false”.
Your compiler (setting) doesn’t like undefined macros, which I think is good behaviour. It makes you aware of the choices that are taken.