The remote is configured with a static IPv4 address: 192.168.1.100/24
The dut (? I don’t know this abbreviation, google wasn’t helpful) is configured as follows:
IPv4: 192.168.1.69
netmask: 255.255.255.0
gatweay: 192.168.1.33
If I’m being honest, I just grabbed a random number in IP range for the gateway as to my understanding it shouldn’t come into play in this scenario. I might be wrong.
/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "FreeRTOS_IP.h"
//
static uint8_t ucMACAddress[ 6 ] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
static const uint8_t ucIPAddress[ 4 ] = { 192, 168, 1, 69 };
static const uint8_t ucNetMask[ 4 ] = { 255, 255, 255, 0 };
static const uint8_t ucGatewayAddress[ 4 ] = { 192, 168, 1, 33 };
static const uint8_t ucDNSServerAddress[ 4 ] = { 208, 67, 222, 222 };
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
void StartDefaultTask(void *argument);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
/**
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void) {
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
FreeRTOS_IPInit(ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress);
}
#define DEST_IP_ADDR "192.168.1.100" // Destination IP
#define DEST_PORT 5005 // Destination port
#define LOCAL_PORT 5000 // Local port (can be 0 for auto)
// Data to send
static const char *messageToSend = "Hello from STM32 over UDP!\r\n";
/**
* @brief Function implementing the defaultTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN StartDefaultTask */
Socket_t xSocket;
struct freertos_sockaddr xDestinationAddress;
BaseType_t xSendResult;
// wait for IP task to be ready // TODO use semaphore
osDelay(1000);
// Create the UDP socket
xSocket = FreeRTOS_socket(FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM,
FREERTOS_SOCK_DEPENDENT_PROTO );
if (xSocket == FREERTOS_INVALID_SOCKET) {
// Handle error
printf("Inavlid socket\r\n");
vTaskDelete(NULL);
}
else
{
printf("Opened socket!\r\n");
}
// Optional: bind to a local port
struct freertos_sockaddr xBindAddress;
xBindAddress.sin_port = FreeRTOS_htons(LOCAL_PORT);
FreeRTOS_bind(xSocket, &xBindAddress, sizeof(xBindAddress));
// Set destination address
xDestinationAddress.sin_addr = FreeRTOS_inet_addr(DEST_IP_ADDR);
xDestinationAddress.sin_port = FreeRTOS_htons(DEST_PORT);
for(;;)
{
// Send the UDP message
xSendResult = FreeRTOS_sendto(xSocket,
messageToSend,
strlen(messageToSend),
0,
&xDestinationAddress,
sizeof(xDestinationAddress));
if (xSendResult < 0) {
printf("Error\r\n");
}
osDelay(1000);
}
}
I will update with a full tcpdump tomorrw, I don’t have access to my tools.