This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Udp in tiva tm4c,i want to communicate between board and pc.Any forum member please help?

Other Parts Discussed in Thread: EK-TM4C1294XL

#define IP_ADDR_OCT1 192
#define IP_ADDR_OCT2 168
#define IP_ADDR_OCT3 0
#define IP_ADDR_OCT4 3

#define SUBNET_OCT1 0
#define SUBNET_OCT2 0
#define SUBNET_OCT3 0
#define SUBNET_OCT4 0

#define GATEWAY_IP_OCT1 255
#define GATEWAY_IP_OCT2 255
#define GATEWAY_IP_OCT3 255
#define GATEWAY_IP_OCT4 255

struct ip_addr *udpDestIpAddr;
struct udp_pcb *pcb;
struct udp_pcb *g_upcb1;
int i,j;

unsigned long index;
unsigned char buffer[1440];
unsigned char *UDPData;
unsigned char gain;

unsigned char u8_EtherNodeId = 0;
unsigned char pucMACArray[8];
unsigned char u8_EthNode;
unsigned char IP_AddrOct1;
uint32_t IP_addr,subnet_addr,gateway_addr;

//*****************************************************************************
//
// Defines for setting up the system clock.
//
//*****************************************************************************
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)

//*****************************************************************************
//
// Interrupt priority definitions. The top 3 bits of these values are
// significant with lower values indicating higher priority interrupts.
//
//*****************************************************************************
#define SYSTICK_INT_PRIORITY 0x80
//#define ETHERNET_INT_PRIORITY 0xC0

//*****************************************************************************
//
// The current IP address.
//
//*****************************************************************************
uint32_t g_ui32IPAddress;

//*****************************************************************************
//
// The system clock frequency.
//
//*****************************************************************************
uint32_t g_ui32SysClock;

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

// UDP transmit ...........................................
void my_udp_tx(u8_t *data, u16_t len)
{
if(g_upcb1->remote_port != (unsigned short)0)
{
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT,len, PBUF_RAM);
memcpy(p->payload, data, len);
udp_send(g_upcb1, p);
pbuf_free(p);
}
}

void my_udp_rx(struct udp_pcb *upcb,struct ip_addr *addr, u16_t port,u8_t *buf)
{
/* process the payload in p->payload */
udp_connect(upcb, addr, port); /* connect to the remote host */
my_udp_tx(buf,1456);
free(buf); /* don't leak the pbuf!*/
}


// UDP initialization ......................................
void my_udp_init(void)
{
g_upcb1 = udp_new();
IP4_ADDR(udpDestIpAddr,172,17,2,28);
udp_bind(g_upcb1,&IP_addr,sizeof(IP_addr));
udp_sendto(struct udp_pcb *pcb, struct pbuf *p,ip_addr_t *dst_ip, 777);

}

//*****************************************************************************
//
// Required by lwIP library to support any host-related timer functions.
//
//*****************************************************************************
void
lwIPHostTimerHandler(void)
{

}

//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
//
// Call the lwIP timer handler.
//
lwIPTimer(SYSTICKMS);
}

//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller.
//
//*****************************************************************************
int main(void)
{

char p[100];
char b[100];
char c[100];

sprintf(p,"%d.%d.%d.%d\n",IP_ADDR_OCT1,IP_ADDR_OCT2,IP_ADDR_OCT3,IP_ADDR_OCT4);
sprintf(b,"%d.%d.%d.%d\n",SUBNET_OCT1,SUBNET_OCT2,SUBNET_OCT3,SUBNET_OCT4);
sprintf(c,"%d.%d.%d.%d\n",GATEWAY_IP_OCT1,GATEWAY_IP_OCT2,GATEWAY_IP_OCT3,GATEWAY_IP_OCT4);

IP_addr = inet_addr(p);
subnet_addr = inet_addr(b);
gateway_addr = inet_addr(c);
lwIPInit(100,pucMACArray, IP_addr, subnet_addr, gateway_addr, IPADDR_USE_STATIC);
udpDestIpAddr = (struct ip_addr *)malloc(sizeof(struct ip_addr));


my_udp_init();

}

  • Hello Kirshnan

    Did you check the finder app in TivaWare tools?

    Regards
    Amit
  • No,
    I will check it soon.


    Regards,
    Krishnan
  • Also,
    I changed the format of IP ADDRESS 172.17.1.3 AND sub net Address 255.255.0.0 and Gate way 172.17.0.3 and tring to build ,it seems it wont works
  • Hello Krishnan,

    This post seems to be similar to the one you posted here: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/393011

    Please try not to post multiple threads for the same issue.

    As I suggested on the above mentioned thread, please go through the "locator" utility implementation. Re-posting my suggestion here:

    In "<TivaWare_C_Series Install Directory>/utils/" folder a utility called "locator" (locator.c and locator.h) is included. This implements a UDP listening port on port 23 using lwIP.
    The "<TivaWare_C_Series Install Directory>/examples/boards/ek-tm4c1294xl/enet_lwip" application demonstrates how to use this locator utility.

    Thanks,

    Sai

  • Hello Sai,

    Thank you for the message i went trough the locator library.
    The examples mostly uses pui mac array for client and server ,i am trying by giving ip address of the pc and connect the socket as in the code given above and the definitions used are as below.
    #define IP_ADDR_OCT1 169
    #define IP_ADDR_OCT2 251
    #define IP_ADDR_OCT3 251
    #define IP_ADDR_OCT4 33

    #define SUBNET_OCT1 255
    #define SUBNET_OCT2 255
    #define SUBNET_OCT3 0
    #define SUBNET_OCT4 0

    #define GATEWAY_IP_OCT1 172
    #define GATEWAY_IP_OCT2 17
    #define GATEWAY_IP_OCT3 0
    #define GATEWAY_IP_OCT4 3



    Regards,
    Krishnan
  • Hello Krishnan,

    Suggestions for the "main()" function:

    • In the code that is posted above, I don't see the system clock being configured. Also make sure that the system clock is copied into a variable like "g_ui32SysClock".
    • The system clock value passed to lwIPInit() function is wrong. Pass "g_ui32SysClock" value instead.
    • Use dynamic (or DHCP) IP address instead of Static IP. Once this works, you can try Static IP address.
    • Does the inet_addr() function, convert a string into an IP address format that lwIPInit needs?

    Please refer "<TivaWare_C_Series Install Directory>/examples/boards/ek-tm4c1294xl/enet_lwip/enet_lwip.c" file for the above mentioned suggestions.

    Suggestions for the "my_udp_init()" function:

    • A fixed IP address (IP_addr) is being passed to "udp_bind()" function. I would suggest that you first implement the UDP server to bind to all local interfaces. Please refer "LocatorInit()" function in "locator.c" file on how this is done.
    • The third parameter passed to "udp_bind()" must be the port number. In the above code, size of an IP address is passed. Please verify.
    • "udp_sendto()" is trying to send data to a remote connection that has not, so far, connected to the UDP port (of the server). Use "udp_recv()" function to assign a call back function. This function will be called when remote IP establishes a connection with the UDP server and sends data. The IP address and port number of the remote connection is passed to this call back function which can be used to send data back to the remote connection. Please refer to "LocatorInit()" and LocatorReceive() functions in "locator.c" file to see how the call back function is registered and the implementation of the call back function.

    You might also want to investigate if implementing a UDP client is a better solution.

    Hope this helps!

    Sai

  • Hello Sai,
    Thank you very much.

    Regards,
    Krishnan