FreeRTOS+TCP simulator on Linux 64bit requires ipconfigBUFFER_PADDING == 14

The instructions for building and running the TCP echo demo on a Linux simulator target should probably mention that with a 64-bit host (which are now pretty much universal) you must set ipconfigBUFFER_PADDING to 14 in FreeRTOSIPConfig.h:

diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/FreeRTOSIPConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/FreeRTOSIPConfig.h
index 82975dff5..ffffa90b4 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/FreeRTOSIPConfig.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/FreeRTOSIPConfig.h
@@ -301,6 +301,8 @@ disconnecting stage will timeout after a period of non-activity. */
 #define ipconfigTCP_KEEP_ALIVE                         ( 1 )
 #define ipconfigTCP_KEEP_ALIVE_INTERVAL                ( 20 ) /* in seconds */
+#define ipconfigBUFFER_PADDING 14
 #define portINLINE __inline
 #endif /* FREERTOS_IP_CONFIG_H */

Otherwise, the assert at line 1156 in FreeRTOS_IP.c will fail:

  1139  BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
  1140                              const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ],
  1141                              const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
  1142                              const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
  1143                              const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] )
  1144  {
  1145      BaseType_t xReturn = pdFALSE;
  1152      if( sizeof( uintptr_t ) == 8 )
  1153      {
  1154          /* This is a 64-bit platform, make sure there is enough space in
  1155           * pucEthernetBuffer to store a pointer. */
  1156          configASSERT( ipconfigBUFFER_PADDING == 14 );
  1157      }

Unfortunately, the default assert handler in the demo main.c just silently goes into an infinite loop, so it takes a fair bit of effort to figure out why the demo won’t run as-is. Therefore, I’d also suggest adding an fprintf() call in main.c. I also prefer an exit() call, but I can see that might not be what everybody would want:

diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main.c
index 0cf0a0709..c12730511 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/main.c
@@ -247,10 +247,8 @@ volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
     /* Called if an assertion passed to configASSERT() fails.  See for more information. */
-    /* Parameters are not used. */
-    ( void ) ulLine;
-    ( void ) pcFileName;
+    fprintf(stderr,"assert failed %s line %lu\n", pcFileName, ulLine);
+    exit(1);

Thank you for sharing your feedback. I agree adding more logs here will be useful in this case and we will update the demos.

Yes, thanks for reporting this. That will save time for other developers when they get stuck in vAssertCalled().
I just created PR #598 for this: “Let vAssertCalled() produce some logging to stdout”

About the configASSERT: we could also turn it into a static compiler check:

#if UINTPTR_MAX == 0xffffffffffffffff
    /* This is a 64-bit platform, make sure there is enough space in
     * pucEthernetBuffer to store a pointer. */
    #if( ipconfigBUFFER_PADDING < 14 )
        #error On a 64-bit platform, `ipconfigBUFFER_PADDING` must be greater than or equal to 14

but I am not sure if all compilers will like this construction.

Currently the test is ipconfigBUFFER_PADDING == 14, but in fact a higher value may also be used (18, 22, 26 etc).

Thanks, @htibosch for that PR! We are working on getting it merged in the mainline.

And @Grant_Edwards yes, I think we should add that detail to the documentation. Apologies for your trouble.

Can we add a conditional value of ipconfigBUFFER_PADDING in the FreeRTOSIPConfig.h source file for the POSIX demo like so:

/* Some compilers might not like this, but this is for Posix simulator only.  */
#if UINTPTR_MAX == 0xffffffffffffffff
    #define ipconfigBUFFER_PADDING 14
/* else let the default value take over. */

This would save so much time for people trying to get started with the Posix demo. What do you all think?