ARP response problem FreeRTOS_Plus TCP Echo Qemu MPS2

I’m trying to run the FreeRTOS_Plus_TCP_Echo_Qemu_MPS2 example in Linux, Kubuntu 22.04.
My Qemu version is 8.0.4, stable release.

My issues are really similar to the ones within “issue-with-tcp-echo-qemu-mps2-demo/15547” in the forum.

I’ve tried applying the fixes listed there and in some other posts within this forum to no result:

  1. Define #define mainCREATE_TCP_ECHO_TASKS_SINGLE ( 1 ), which is not defined by default
  2. Recheck if the port I’m sending stuff to is port 7
  3. Recheck subnet masks
  4. Add NVIC_SetPriority(13, 6) to the _start function
  5. Make sure you are using Qemu within a VM, as ARP packets might not get sent if you are doing everything in the host

Qemu still gets stuck waiting for ARP packet responses:

Log here:

checking ID
0->prvMiscInitialisation 255: Seed for randomiser: 0
0->prvMiscInitialisation 262: Random numbers: 000078B1 00007B9C 000036E4 00000766
0->main_tcp_echo_client_tasks 150: FreeRTOS_IPInit
0x2000bb70->main_tcp_echo_client_tasks 158: vTaskStartScheduler
0x2000bb70->prvIPTask 263: prvIPTask started
0x2000bb70->vApplicationIPNetworkEventHook 212: 
 
IP Address: 192.168.88.101
0x2000bb70->vApplicationIPNetworkEventHook 215: Subnet Mask: 255.255.255.0
0x2000bb70->vApplicationIPNetworkEventHook 218: Gateway Address: 192.168.88.1
0x2000bb70->vApplicationIPNetworkEventHook 221: DNS Server Address: 192.168.88.1
 
 
connecting to echo server....
0x20015a10->prvTCPConnectStart 3043: FreeRTOS_connect: 27415 to c0a858feip:7
0x20015a10->vTCPStateChange 499: Socket 27415 -> c0a858feip:7 State eCLOSED->eCONNECT_SYN
0x2000bb70->prvTCPPrepareConnect 634: ARP for c0a858feip (using c0a858feip): rc=0 00:00:00 00:00:00
0x2000bb70->prvTCPNextTimeout 560: Connect[c0a858feip:7]: next timeout 1: 500 ms

Here is a rundown of my setup:

  • Router (DNS+Gateway): 192.168.88.1/24
  • Host computer (Linux): 192.168.88.254/24
  • Virbr0 (VM ip): 192.168.88.252/24
  • QEMU (tap → virbr0-nic): 192.168.88.99/24

My FreeRTOSconfig.h:

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
 
/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
 * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
 *
 * See https://www.freertos.org/a00110.html
 *----------------------------------------------------------*/
 
#define configASSERT_DEFINED 1
extern void vAssertCalled( void );
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( )
 
#define configUSE_PREEMPTION        1
#define configUSE_TIME_SLICING      1
 
#define configUSE_IDLE_HOOK         0
#define configUSE_TICK_HOOK         0
#define configCPU_CLOCK_HZ        ( ( unsigned long ) 20000000 )
#define configTICK_RATE_HZ        ( ( TickType_t ) 1000 )
#define configMINIMAL_STACK_SIZE  ( ( unsigned short ) 2000 )
#define configTOTAL_HEAP_SIZE     ( ( size_t ) ( 279000 ) )
#define configMAX_TASK_NAME_LEN   ( 10 )
#define configUSE_TRACE_FACILITY    0
#define configUSE_16_BIT_TICKS      0
#define configIDLE_SHOULD_YIELD     0
#define configMAX_PRIORITIES            ( 10 )
#define configTIMER_QUEUE_LENGTH          20
#define configTIMER_TASK_PRIORITY       ( configMAX_PRIORITIES - 3 )
#define configUSE_COUNTING_SEMAPHORES 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define  configNUM_TX_DESCRIPTORS 15
 
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
 
#define configUSE_MALLOC_FAILED_HOOK    1
#define configUSE_MUTEXES               1
#define configUSE_RECURSIVE_MUTEXES     1
#define INCLUDE_vTaskPrioritySet        0
#define INCLUDE_uxTaskPriorityGet       0
#define INCLUDE_vTaskDelete             0
#define INCLUDE_vTaskCleanUpResources   0
#define INCLUDE_vTaskSuspend            0
#define INCLUDE_vTaskDelayUntil         1
#define INCLUDE_vTaskDelay              1
 
 
#define configKERNEL_INTERRUPT_PRIORITY         252
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY    5 /* equivalent to 0xa0, or priority 5. */
#define configMAC_INTERRUPT_PRIORITY 2
 
 
/* networking definitions */
#define configMAC_ISR_SIMULATOR_PRIORITY     ( configMAX_PRIORITIES - 2 )
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
//#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME  pdMS_TO_TICKS(5000)
#define configNETWORK_INTERFACE_TO_USE 1L
 
/* The address of an echo server that will be used by the two demo echo client
tasks.
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Clients.html
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/UDP_Echo_Clients.html */
 
#define configECHO_SERVER_ADDR0 192
#define configECHO_SERVER_ADDR1 168
#define configECHO_SERVER_ADDR2 88
#define configECHO_SERVER_ADDR3 254
 
/* Default MAC address configuration.  The demo creates a virtual network
connection that uses this MAC address by accessing the raw Ethernet/WiFi data
to and from a real network connection on the host PC.  See the
configNETWORK_INTERFACE_TO_USE definition above for information on how to
configure the real network connection to use. */
 
#define configMAC_ADDR0    0x52
#define configMAC_ADDR1    0x54
#define configMAC_ADDR2    0x00
#define configMAC_ADDR3    0x12
#define configMAC_ADDR4    0x34
#define configMAC_ADDR5    0xAD
 
/* Default IP address configuration.  Used in ipconfigUSE_DNS is set to 0, or
ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
 
#define configIP_ADDR0      192
#define configIP_ADDR1      168
#define configIP_ADDR2      88
#define configIP_ADDR3      99
 
/* Default gateway IP address configuration.  Used in ipconfigUSE_DNS is set to
0, or ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
 
#define configGATEWAY_ADDR0 192
#define configGATEWAY_ADDR1 168
#define configGATEWAY_ADDR2 88
#define configGATEWAY_ADDR3 1
 
/* Default DNS server configuration.  OpenDNS addresses are 208.67.222.222 and
208.67.220.220.  Used in ipconfigUSE_DNS is set to 0, or ipconfigUSE_DNS is set
to 1 but a DNS server cannot be contacted.*/
 
#define configDNS_SERVER_ADDR0  192
#define configDNS_SERVER_ADDR1  168
#define configDNS_SERVER_ADDR2  88
#define configDNS_SERVER_ADDR3  1
 
/* Default netmask configuration.  Used in ipconfigUSE_DNS is set to 0, or
ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
#define configNET_MASK0     255
#define configNET_MASK1     255
#define configNET_MASK2     255
#define configNET_MASK3     0
 
/* The UDP port to which print messages are sent. */
#define configPRINT_PORT   ( 15000 )
#endif /* FREERTOS_CONFIG_H */

Might be an issue with interrupt priorities I reckon, but, as stated by jasUman in “issue-with-tcp-echo-qemu-mps2-demo/15547”, those priorities are set by default and changing the Linux distro/version should not have any effects.

Any ideas?

The wireshark dump on the host
192.168.88.254
Shows that ARP packets are reaching
And that the Router is responding to them

1698	43.587865041	RealtekU_12:34:ad	Broadcast	ARP	60	Who has 192.168.88.254? Tell 192.168.88.99

1699	43.587907441	HP_88:89:1f	RealtekU_12:34:ad	ARP	42	192.168.88.254 is at 30:24:a9:88:89:1f

As you can see, frame 1698’s source is the tap interface with the proper MAC address.
And the router is responding back properly.

Hey there @xgandiaga :

Can you check that the ipconfigNETWORK_MTU in FreeRTOSIPConfig.h matches the MTU value which your tap/bridge devices are expecting?

Edit: Please also check that your MAC address defined in FreeRTOSConfig.h matches that of your tap device / qemu config.

@xgandiaga I was able to get the demo running successfully using usermode networking with the following qemu command:

qemu-system-arm -machine mps2-an385 -cpu cortex-m3 --kernel build/freertos_tcp_mps2_demo.axf -monitor null -semihosting -semihosting-config enable=on,target=native -serial stdio -nographic -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9 -net nic,macaddr="52:54:00:12:34:AD",model=lan9118,netdev=mynet0

Against a tcp echo server running on my local machine:

$ pip3 install echo-server
$ echo-server
Echo server running on: 0.0.0.0:3682

Here’s a diff of the code changes I made to get this working:

diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSConfig.h
index 371b5f8dc..51c79d973 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSConfig.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSConfig.h
@@ -97,10 +97,10 @@ extern void vAssertCalled( void );
  * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Clients.html
  * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/UDP_Echo_Clients.html */
 
-#define configECHO_SERVER_ADDR0    10
-#define configECHO_SERVER_ADDR1    136
-#define configECHO_SERVER_ADDR2    206
-#define configECHO_SERVER_ADDR3    133
+#define configECHO_SERVER_ADDR0    192
+#define configECHO_SERVER_ADDR1    168
+#define configECHO_SERVER_ADDR2    76
+#define configECHO_SERVER_ADDR3    2
 
 /* Default MAC address configuration.  The demo creates a virtual network
  * connection that uses this MAC address by accessing the raw Ethernet/WiFi data
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSIPConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSIPConfig.h
index 08550f8ec..1175b49d3 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSIPConfig.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/FreeRTOSIPConfig.h
@@ -165,7 +165,7 @@ extern UBaseType_t uxRand();
  * set to 1 if a valid configuration cannot be obtained from a DHCP server for any
  * reason.  The static configuration used is that passed into the stack by the
  * FreeRTOS_IPInit() function call. */
-#define ipconfigUSE_DHCP                               0
+#define ipconfigUSE_DHCP                               1
 
 /* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
  * increasing time intervals until either a reply is received from a DHCP server
@@ -252,7 +252,7 @@ extern UBaseType_t uxRand();
  * lower value can save RAM, depending on the buffer management scheme used.  If
  * ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
  * be divisible by 8. */
-#define ipconfigNETWORK_MTU                            1200U
+#define ipconfigNETWORK_MTU                            1500U
 
 /* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver.  DNS is used
  * through the FreeRTOS_gethostbyname() API function. */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/TCPEchoClient_SingleTasks.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/TCPEchoClient_SingleTasks.c
index 968e044e3..53b8f0d3d 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/TCPEchoClient_SingleTasks.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/TCPEchoClient_SingleTasks.c
@@ -63,7 +63,7 @@
 
 /* The echo server is assumed to be on port 7, which is the standard echo
  * protocol port. */
-    #define echoECHO_PORT                 ( 7 )
+    #define echoECHO_PORT                 ( 3682 )
 
 /* The size of the buffers is a multiple of the MSS - the length of the data
  * sent is a pseudo random size between 20 and echoBUFFER_SIZES. */
@@ -110,9 +110,6 @@
     {
         BaseType_t x;
 
-        /* Set Ethernet interrupt priority to configMAC_INTERRUPT_PRIORITY. */
-        NVIC_SetPriority( ETHERNET_IRQn, configMAC_INTERRUPT_PRIORITY );
-
         /* Create the echo client tasks. */
         for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
         {
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c
index 2c6ab1d85..5af2c81b2 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c
@@ -35,7 +35,6 @@
 #include <time.h>
 #include <unistd.h>
 
-
 /* FreeRTOS includes. */
 #include <FreeRTOS.h>
 #include "task.h"
@@ -44,6 +43,7 @@
 #include "FreeRTOS_IP.h"
 #include "FreeRTOS_Sockets.h"
 #include "TCPEchoClient_SingleTasks.h"
+#include "CMSIS/CMSDK_CM3.h"
 
 /* Echo client task parameters  */
 #define mainECHO_CLIENT_TASK_STACK_SIZE     ( configMINIMAL_STACK_SIZE * 2 )                /* Not used in the linux port. */
@@ -162,6 +162,9 @@ void main_tcp_echo_client_tasks( void )
     /* Initialise the network interface.*/
     FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\r\n" ) );
 
+    /* Set Ethernet interrupt priority to configMAC_INTERRUPT_PRIORITY. */
+    NVIC_SetPriority( ETHERNET_IRQn, configMAC_INTERRUPT_PRIORITY );
+
     #if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
         /* Initialise the interface descriptor for WinPCap. */
         extern NetworkInterface_t * pxMPS2_FillInterfaceDescriptor( BaseType_t xEMACIndex,

@xgandiaga, @PaulB-AWS has merged this fixed with the following PRs:

So you should not face any problem with the tip of the main. Let us know if you face any problem.

Will test is this afternoon and I’ll post about it.

Sorry for the late reply @PaulB-AWS.

I managed to get it working on User mode networking through the fixes you presented. I just had to make a slight adjustment to the Qemu launching command.
This was my setup.

  • No VM required.
  • TCP echo server is executed on host via Python (pip3 install echo-server), port 3682
  • FreeRTOSconfig.h here:
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See https://www.freertos.org/a00110.html
*----------------------------------------------------------*/

#define configASSERT_DEFINED    1
extern void vAssertCalled( void );
#define configASSERT( x )    if( ( x ) == 0 ) vAssertCalled( )

#define configUSE_PREEMPTION                1
#define configUSE_TIME_SLICING              1

#define configUSE_IDLE_HOOK                 0
#define configUSE_TICK_HOOK                 0
#define configCPU_CLOCK_HZ                  ( ( unsigned long ) 20000000 )
#define configTICK_RATE_HZ                  ( ( TickType_t ) 1000 )
#define configMINIMAL_STACK_SIZE            ( ( unsigned short ) 2000 )
#define configTOTAL_HEAP_SIZE               ( ( size_t ) ( 279000 ) )
#define configMAX_TASK_NAME_LEN             ( 10 )
#define configUSE_TRACE_FACILITY            0
#define configUSE_16_BIT_TICKS              0
#define configIDLE_SHOULD_YIELD             0
#define configMAX_PRIORITIES                ( 10 )
#define configTIMER_QUEUE_LENGTH            20
#define configTIMER_TASK_PRIORITY           ( configMAX_PRIORITIES - 3 )
#define configUSE_COUNTING_SEMAPHORES       1
#define configSUPPORT_DYNAMIC_ALLOCATION    1
#define  configNUM_TX_DESCRIPTORS           15

/* Set the following definitions to 1 to include the API function, or zero
 * to exclude the API function. */

#define configUSE_MALLOC_FAILED_HOOK            1
#define configUSE_MUTEXES                       1
#define configUSE_RECURSIVE_MUTEXES             1
#define INCLUDE_vTaskPrioritySet                0
#define INCLUDE_uxTaskPriorityGet               0
#define INCLUDE_vTaskDelete                     0
#define INCLUDE_vTaskCleanUpResources           0
#define INCLUDE_vTaskSuspend                    0
#define INCLUDE_vTaskDelayUntil                 1
#define INCLUDE_vTaskDelay                      1


#define configKERNEL_INTERRUPT_PRIORITY         255

/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
 * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY    4
#define configMAC_INTERRUPT_PRIORITY            5


/* networking definitions */
#define configMAC_ISR_SIMULATOR_PRIORITY    ( configMAX_PRIORITIES - 2 )
#define ipconfigUSE_NETWORK_EVENT_HOOK      1
/*#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME  pdMS_TO_TICKS(5000) */
#define configNETWORK_INTERFACE_TO_USE      1L

/* The address of an echo server that will be used by the two demo echo client
 * tasks.
 * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Clients.html
 * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/UDP_Echo_Clients.html */

#define configECHO_SERVER_ADDR0    192
#define configECHO_SERVER_ADDR1    168
#define configECHO_SERVER_ADDR2    88
#define configECHO_SERVER_ADDR3    250

/* Default MAC address configuration.  The demo creates a virtual network
 * connection that uses this MAC address by accessing the raw Ethernet/WiFi data
 * to and from a real network connection on the host PC.  See the
 * configNETWORK_INTERFACE_TO_USE definition above for information on how to
 * configure the real network connection to use. */

#define configMAC_ADDR0    0x52
#define configMAC_ADDR1    0x54
#define configMAC_ADDR2    0x00
#define configMAC_ADDR3    0x12
#define configMAC_ADDR4    0x34
#define configMAC_ADDR5    0xAD

/* Default IP address configuration.  Used in ipconfigUSE_DNS is set to 0, or
 * ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */

#define configIP_ADDR0    192
#define configIP_ADDR1    168
#define configIP_ADDR2    88
#define configIP_ADDR3    200

/* Default gateway IP address configuration.  Used in ipconfigUSE_DNS is set to
 * 0, or ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */

#define configGATEWAY_ADDR0    192
#define configGATEWAY_ADDR1    168
#define configGATEWAY_ADDR2    88
#define configGATEWAY_ADDR3    1

/* Default DNS server configuration.  OpenDNS addresses are 208.67.222.222 and
 * 208.67.220.220.  Used in ipconfigUSE_DNS is set to 0, or ipconfigUSE_DNS is set
 * to 1 but a DNS server cannot be contacted.*/

#define configDNS_SERVER_ADDR0    127
#define configDNS_SERVER_ADDR1    0
#define configDNS_SERVER_ADDR2    0
#define configDNS_SERVER_ADDR3    53

/* Default netmask configuration.  Used in ipconfigUSE_DNS is set to 0, or
 * ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
#define configNET_MASK0           255
#define configNET_MASK1           255
#define configNET_MASK2           255
#define configNET_MASK3           0

/* The UDP port to which print messages are sent. */
#define configPRINT_PORT          ( 15000 )
#endif /* FREERTOS_CONFIG_H */
  • .sh file I use to setup the host here:
sudo ufw disable

sudo ip link add virbr0 type bridge 
sudo ip tuntap add dev virbr0-nic mode tap 
sudo ip addr add 192.168.88.251/255.255.255.0 dev virbr0 
sudo brctl addif virbr0 enp2s0 
sudo brctl addif virbr0 virbr0-nic 
sudo ip link set virbr0 up 
sudo ip link set virbr0-nic up 
sudo ip route add default via 192.168.88.1 dev virbr0
  • .sh file I use to launch qemu here
sudo ufw disable

sudo qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-kernel build/freertos_tcp_mps2_demo.axf \
-monitor null \
-semihosting \
-semihosting-config enable=on,target=native \
-serial stdio \
-nographic \
-netdev user,id=mynet0 \
-net nic,macaddr="52:54:00:12:34:AD",model=lan9118,netdev=mynet0

I’m still having issues with the Tap interface + VM setup. But I reckon it has something to do with my Virtualbox config. Will update once I solve that.

1 Like

Got it working on my VM with the Tap interface configuration.
Main issues I would recommend anyone should double check are:

  1. Make sure you disable the firewall both on the host and VM
  2. Check if virtualbox is bridged to the proper interface on the host
  3. Set that configuration to promiscuous mode
  4. Make sure the virbr0 and VM interface IPs are the same
  5. Make sure the virbr0-nic and Qemu NIC MAC addresses are different

This was the final setup:

ROUTER:

  • IP: 192.168.88.1/24

HOST:

  • IP (enp2s0): 192.168.88.250/24
  • Python echo server running at port 3682

VM (Virtualbox) + Qemu:

  • Machine → Settings → Network → Adapter 1 → Bridged Adapter to Host enp2s0, Promiscuous All
  • IP (enp0s8): 192.168.88.248/24
  • IP (virbr0): 192.168.88.248/24
  • IP (Qemu): DHCP ON, usually gets 192.168.88.249/24
  • MAC (virbr0): c6:ac:91:66:8a:51
  • MAC (virbr0-nic): 52:54:00:12:34:ac ← different MAC to Qemu settings
  • MAC (Qemu): 52:54:00:12:34:ad ← different MAC to virbr0-nic settings

Here is my FreeRTOSConfig.h

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See https://www.freertos.org/a00110.html
*----------------------------------------------------------*/

#define configASSERT_DEFINED    1
extern void vAssertCalled( void );
#define configASSERT( x )    if( ( x ) == 0 ) vAssertCalled( )

#define configUSE_PREEMPTION                1
#define configUSE_TIME_SLICING              1

#define configUSE_IDLE_HOOK                 0
#define configUSE_TICK_HOOK                 0
#define configCPU_CLOCK_HZ                  ( ( unsigned long ) 20000000 )
#define configTICK_RATE_HZ                  ( ( TickType_t ) 1000 )
#define configMINIMAL_STACK_SIZE            ( ( unsigned short ) 2000 )
#define configTOTAL_HEAP_SIZE               ( ( size_t ) ( 279000 ) )
#define configMAX_TASK_NAME_LEN             ( 10 )
#define configUSE_TRACE_FACILITY            0
#define configUSE_16_BIT_TICKS              0
#define configIDLE_SHOULD_YIELD             0
#define configMAX_PRIORITIES                ( 10 )
#define configTIMER_QUEUE_LENGTH            20
#define configTIMER_TASK_PRIORITY           ( configMAX_PRIORITIES - 3 )
#define configUSE_COUNTING_SEMAPHORES       1
#define configSUPPORT_DYNAMIC_ALLOCATION    1
#define  configNUM_TX_DESCRIPTORS           15

/* Set the following definitions to 1 to include the API function, or zero
 * to exclude the API function. */

#define configUSE_MALLOC_FAILED_HOOK            1
#define configUSE_MUTEXES                       1
#define configUSE_RECURSIVE_MUTEXES             1
#define INCLUDE_vTaskPrioritySet                0
#define INCLUDE_uxTaskPriorityGet               0
#define INCLUDE_vTaskDelete                     0
#define INCLUDE_vTaskCleanUpResources           0
#define INCLUDE_vTaskSuspend                    0
#define INCLUDE_vTaskDelayUntil                 1
#define INCLUDE_vTaskDelay                      1


#define configKERNEL_INTERRUPT_PRIORITY         255

/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
 * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY    4
#define configMAC_INTERRUPT_PRIORITY            5


/* networking definitions */
#define configMAC_ISR_SIMULATOR_PRIORITY    ( configMAX_PRIORITIES - 2 )
#define ipconfigUSE_NETWORK_EVENT_HOOK      1
/*#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME  pdMS_TO_TICKS(5000) */
#define configNETWORK_INTERFACE_TO_USE      1L

/* The address of an echo server that will be used by the two demo echo client
 * tasks.
 * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Clients.html
 * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/UDP_Echo_Clients.html */

#define configECHO_SERVER_ADDR0    192
#define configECHO_SERVER_ADDR1    168
#define configECHO_SERVER_ADDR2    88
#define configECHO_SERVER_ADDR3    250

/* Default MAC address configuration.  The demo creates a virtual network
 * connection that uses this MAC address by accessing the raw Ethernet/WiFi data
 * to and from a real network connection on the host PC.  See the
 * configNETWORK_INTERFACE_TO_USE definition above for information on how to
 * configure the real network connection to use. */

#define configMAC_ADDR0    0x52
#define configMAC_ADDR1    0x54
#define configMAC_ADDR2    0x00
#define configMAC_ADDR3    0x12
#define configMAC_ADDR4    0x34
#define configMAC_ADDR5    0xAD

/* Default IP address configuration.  Used in ipconfigUSE_DNS is set to 0, or
 * ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */

#define configIP_ADDR0    192
#define configIP_ADDR1    168
#define configIP_ADDR2    88
#define configIP_ADDR3    5

/* Default gateway IP address configuration.  Used in ipconfigUSE_DNS is set to
 * 0, or ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */

#define configGATEWAY_ADDR0    192
#define configGATEWAY_ADDR1    168
#define configGATEWAY_ADDR2    88
#define configGATEWAY_ADDR3    1

/* Default DNS server configuration.  OpenDNS addresses are 208.67.222.222 and
 * 208.67.220.220.  Used in ipconfigUSE_DNS is set to 0, or ipconfigUSE_DNS is set
 * to 1 but a DNS server cannot be contacted.*/

#define configDNS_SERVER_ADDR0    127
#define configDNS_SERVER_ADDR1    0
#define configDNS_SERVER_ADDR2    0
#define configDNS_SERVER_ADDR3    53

/* Default netmask configuration.  Used in ipconfigUSE_DNS is set to 0, or
 * ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
#define configNET_MASK0           255
#define configNET_MASK1           255
#define configNET_MASK2           255
#define configNET_MASK3           0

/* The UDP port to which print messages are sent. */
#define configPRINT_PORT          ( 15000 )
#endif /* FREERTOS_CONFIG_H */

Here is the .sh file I use to setup the VM

sudo ufw disable

sudo ip link add virbr0 type bridge 
sudo ip tuntap add dev virbr0-nic mode tap 
sudo ip link set dev virbr0-nic address 52:54:00:12:34:AC
sudo ip addr add 192.168.88.248/255.255.255.0 dev virbr0 
sudo brctl addif virbr0 enp0s8 
sudo brctl addif virbr0 virbr0-nic 
sudo ip link set virbr0 up 
sudo ip link set virbr0-nic up 
sudo ip route add default via 192.168.88.1 dev virbr0

And here is the .sh file I use to launch Qemu:

sudo ufw disable

sudo qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-kernel ./build/freertos_tcp_mps2_demo.axf \
-netdev tap,id=mynet0,ifname=virbr0-nic,script=no \
-net nic,macaddr=52:54:00:12:34:AD,model=lan9118,netdev=mynet0 \
-object filter-dump,id=tap_dump,netdev=mynet0,file=/tmp/qemu_tap_dump \
-display gtk \
-nographic \
-serial stdio \
-monitor null \
-semihosting-config enable=on,target=native 
3 Likes

Thank you for reporting back!