Part Number: MSP432E401Y
Hi,
I'm using sdk version 3.20.00.10. I wrote a simple task based on UDP to discover my device on the network. Basically the PC sends a broadcast UDP datagram on the LAN and my embedded device listen on a specific port. When it receives a message it reply back with another UDP datagram. Then I know how many devices are on the network and get the ip of each one so I can later connect with TCP sockets.
Everything have been working fine until I start testing the device with Netgear switches. It seems that the NDK library doesn't like the Netgear. I have try with multiples one, and have problems with it.
Sometimes when I reboot the switch, or the embedded devices the switch indicates that the link established is 10Mbps. After that none of the TCP or UDP packets reach the PC. The sendto function return -1 sometimes, but even when it sends correctly, the PC doesn't get anything. When the link is set to 100Mbps everything works fine.
Why is not consistent the speed negotiation? With other switches seems to work fine. I have try with multiples switches of the models GS108 and GS108E and with all of them I have the same problem. I can receive the UDP packets but when it sends fails.
UDP task
void *UDPFinder_task(void *arg0)
{
int bytesRcvd;
int bytesSent;
int status;
int server;
int n;
fd_set readSet;
struct sockaddr_in localAddr;
struct sockaddr_in clientAddr;
socklen_t addrlen;
char buffer[UDPPACKETSIZE];
uint16_t portNumber = *(uint16_t *)arg0;
uint32_t IPTmp;
char response[64];
volatile tEEPROM_Data *pManufacturerInformation;
fdOpenSession(TaskSelf());
Display_printf(g_SMCDisplay, 0, 0, "UDP Server Started on Port (%d)\n", portNumber);
server = socket(AF_INET, SOCK_DGRAM, 0);
if (server == -1) {
Display_printf(g_SMCDisplay, 0, 0, "Error: socket not created.\n");
goto shutdown;
}
memset(&localAddr, 0, sizeof(localAddr));
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
localAddr.sin_port = htons(portNumber);
status = bind(server, (struct sockaddr *)&localAddr, sizeof(localAddr));
if (status == -1) {
Display_printf(g_SMCDisplay, 0, 0, "Error: bind failed.\n");
goto shutdown;
}
do {
/*
* readSet and addrlen are value-result arguments, which must be reset
* in between each select() and recvfrom() call
*/
FD_ZERO(&readSet);
FD_SET(server, &readSet);
addrlen = sizeof(clientAddr);
/* Wait forever for the reply */
status = select(server + 1, &readSet, NULL, NULL, NULL);
if (status > 0) {
if (FD_ISSET(server, &readSet)) {
bytesRcvd = recvfrom(server, buffer, UDPPACKETSIZE, 0,
(struct sockaddr *)&clientAddr, &addrlen);
buffer[bytesRcvd] = 0;
if (bytesRcvd > 0) {
IPTmp = ntohl(clientAddr.sin_addr.s_addr);
Display_printf(g_SMCDisplay, 0, 0, "remoteIp:\t:%d.%d.%d.%d:%d\n", (uint8_t)(IPTmp>>24)&0xFF,
(uint8_t)(IPTmp>>16)&0xFF,
(uint8_t)(IPTmp>>8)&0xFF,
(uint8_t)IPTmp&0xFF,
clientAddr.sin_port
);
System_printf("remoteIp:\t:%d.%d.%d.%d:%d\n", (uint8_t)(IPTmp>>24)&0xFF,
(uint8_t)(IPTmp>>16)&0xFF,
(uint8_t)(IPTmp>>8)&0xFF,
(uint8_t)IPTmp&0xFF,
clientAddr.sin_port);
System_flush();
pManufacturerInformation = INFO_get();
// n = sprintf(response, "System Master Controller ID: %06d", pManufacturerInformation->unitSerialNumber);
#ifdef TEST_FIXTURE
n = sprintf(response, "SMC Test Fixture ID: %06d", pManufacturerInformation->unitSerialNumber);
#else
n = sprintf(response, "System Master Controller ID: %06d", pManufacturerInformation->unitSerialNumber);
#endif
bytesSent = sendto(server, response, n, 0, (struct sockaddr *)&clientAddr, addrlen);
// bytesSent = sendto(server, response, n, 0, (struct sockaddr *)&clientAddr, sizeof(struct sockaddr));
if(bytesSent != n){
Display_printf(g_SMCDisplay, 0, 0, "Error: sendto failed.\n");
System_printf("Error: udp sendto failed.\n");
System_flush();
}
// bytesSent = sendto(server, buffer, bytesRcvd, 0,
// (struct sockaddr *)&clientAddr, addrlen);
// if (bytesSent < 0 || bytesSent != bytesRcvd) {
// Display_printf(g_SMCDisplay, 0, 0,
// "Error: sendto failed.\n");
// goto shutdown;
// }
}
}
}
} while (status > 0);
shutdown:
if (server != -1) {
close(server);
}
fdCloseSession(TaskSelf());
return (NULL);
}
Console log:
[CORTEX_M4_0] Starting the System Master Controller
System provider is set to SysMin. Halt the target to view any SysMin contents in ROV.
-- Compiled: Oct 30 2019 16:19:15 --
remoteIp: :192.168.1.5:53764
remoteIp: :192.168.1.5:53764
remoteIp: :192.168.1.5:53764
Error: udp sendto failed.
remoteIp: :192.168.1.5:53764
remoteIp: :192.168.1.5:53764
remoteIp: :192.168.1.5:53764
Error: udp sendto failed.
remoteIp: :192.168.1.5:53764
Error: udp sendto failed.