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.

EK-TM4C129EXL: UDP :Fault ISR

Part Number: EK-TM4C129EXL
Other Parts Discussed in Thread: EK-TM4C1294XL

Tool/software:

Hi, Community 

I imported the LWIP https server example, its working fine, so my application i want use UDP protocol.

Problem: I did ping continiously from my PC its working.

for the UDP port i used Its going ISR fault:

Problem 1: When i use the udp_connect there is no callback occurring when send data from the hw-hercules created port.

Problem2: i checked with by commenting the udp_connect , During this time i can able to receive the Data from PC only once after this its going to the isr fault. i checked by applying break points in callback function it worked fine. after reached main while(g_bLED == false){}; before reached it will go to the isr fault.

in image i mentioned 1,2,3

1=> First time i received data, it gone to the FaultISR i restart the by click on ccs icon number two is occuring.

3) i did power on recycle again 1 st data is occurred then again FaultISR 

So can you review my code, let me know if any further details are required.

UDP code as below.

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/flash.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/locator.h"
#include "utils/lwiplib.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
#include "httpserver_raw/httpd.h"
#include "drivers/pinout.h"


//added by dst


#include "ipv4/lwip/inet.h"
//*****************************************************************************

//*****************************************************************************
#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;

//*****************************************************************************
//
// Volatile global flag to manage LED blinking, since it is used in interrupt
// and main application. The LED blinks at the rate of SYSTICKHZ.
//
//*****************************************************************************
volatile bool g_bLED;

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

//*****************************************************************************
//
// Display an lwIP type IP Address.
//
//*****************************************************************************
void
DisplayIPAddress(uint32_t ui32Addr)
{
char pcBuf[16];

//
// Convert the IP Address into a string.
//
usprintf(pcBuf, "%d.%d.%d.%d", ui32Addr & 0xff, (ui32Addr >> 8) & 0xff,
(ui32Addr >> 16) & 0xff, (ui32Addr >> 24) & 0xff);

//
// Display the string.
//
UARTprintf(pcBuf);
}

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

//
// Get the current IP address.
//
ui32NewIPAddress = lwIPLocalIPAddrGet();

//
// See if the IP address has changed.
//
if(ui32NewIPAddress != g_ui32IPAddress)
{
//
// See if there is an IP address assigned.
//
if(ui32NewIPAddress == 0xffffffff)
{
//
// Indicate that there is no link.
//
UARTprintf("Waiting for link.\n");
}
else if(ui32NewIPAddress == 0)
{
//
// There is no IP address, so indicate that the DHCP process is
// running.
//
UARTprintf("Waiting for IP address.\n");
}
else
{
//
// Display the new IP address.
//
UARTprintf("IP Address: ");
DisplayIPAddress(ui32NewIPAddress);
UARTprintf("\nOpen a browser and enter the IP address.\n");
}

//
// Save the new IP address.
//
g_ui32IPAddress = ui32NewIPAddress;
}

//
// If there is not an IP address.
//
if((ui32NewIPAddress == 0) || (ui32NewIPAddress == 0xffffffff))
{
//
// Do nothing and keep waiting.
//
}
}

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

//
// Tell the application to change the state of the LED (in other words
// blink).
//
g_bLED = true;
}

//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller.
//
//*****************************************************************************

#define LWIP_DHCP 0

#define LWIP_AUTOIP 0

void echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{

volatile char *pc_ip;
pc_ip=ipaddr_ntoa(addr);

UARTprintf(pc_ip);

volatile char buff[5000]={};
if (p != NULL) {

memcpy(buff, (char*)p->payload, p->len);
buff[p->len + 1]='\n';

UARTprintf(buff);
// udp_send(pcb, p);
// pbuf_free(p);
}
}
void udp_clientsend(void){


volatile int k=0;
}
void udp_client()
{

ip_addr_t pcsrcIP;
pcsrcIP.addr = htonl(ipaddr_addr ("192.168.0.3"));
struct udp_pcb * mypcb;
err_t err;
mypcb = udp_new();
if (mypcb == NULL)
{
UARTprintf("udp failed.\n");
}
else
{
UARTprintf("udp up.\n");
}

if (udp_bind(mypcb, IPADDR_ANY, 8) != ERR_OK)
{
UARTprintf("udp bind failed.\n");
}

udp_recv(mypcb,echo_recv,NULL);

err= udp_connect(mypcb,&pcsrcIP,7);
if(err == ERR_OK)
{
udp_clientsend();
}


}

int
main(void)
{
uint32_t ui32User0, ui32User1;
uint8_t pui8MACArray[8];

//
// Make sure the main oscillator is enabled because this is required by
// the PHY. The system must have a 25MHz crystal attached to the OSC
// pins. The SYSCTL_MOSC_HIGHFREQ parameter is used when the crystal
// frequency is 10MHz or higher.
//
SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ);

//
// Run from the PLL at 120 MHz.
//
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);

//
// Configure the device pins.
//
PinoutSet(true, false);

//
// Configure UART.
//
UARTStdioConfig(0, 115200, g_ui32SysClock);

//
// Clear the terminal and print banner.
//
UARTprintf("\033[2J\033[H]");
UARTprintf("Ethernet lwIP example\n\n");

//
// Configure Port N1 for as an output for the animation LED.
//
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);

//
// Initialize LED to OFF (0)
//
MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, ~GPIO_PIN_1);

//
// Configure SysTick for a periodic interrupt.
//
MAP_SysTickPeriodSet(g_ui32SysClock / SYSTICKHZ);
MAP_SysTickEnable();
MAP_SysTickIntEnable();

//
// Configure the hardware MAC address for Ethernet Controller filtering of
// incoming packets. The MAC address will be stored in the non-volatile
// USER0 and USER1 registers.
//
MAP_FlashUserGet(&ui32User0, &ui32User1);
if((ui32User0 == 0xffffffff) || (ui32User1 == 0xffffffff))
{
//
// We should never get here. This is an error if the MAC address has
// not been programmed into the device. Exit the program.
// Let the user know there is no MAC address
//
UARTprintf("No MAC programmed!\n");
while(1)
{
}
}

//
// Tell the user what we are doing just now.
//
UARTprintf("Waiting for IP.\n");

//
// Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
// address needed to program the hardware registers, then program the MAC
// address into the Ethernet Controller registers.
//
pui8MACArray[0] = ((ui32User0 >> 0) & 0xff);
pui8MACArray[1] = ((ui32User0 >> 8) & 0xff);
pui8MACArray[2] = ((ui32User0 >> 16) & 0xff);
pui8MACArray[3] = ((ui32User1 >> 0) & 0xff);
pui8MACArray[4] = ((ui32User1 >> 8) & 0xff);
pui8MACArray[5] = ((ui32User1 >> 16) & 0xff);

//
// Initialize the lwIP library, using DHCP.


uint32_t srcIP;
srcIP = htonl(ipaddr_addr ("192.168.0.2"));
uint32_t NETMASK;
NETMASK = htonl((inet_addr("255.255.255.0")));
uint32_t desIP;
desIP = htonl((inet_addr("0.0.0.0")));
//
lwIPInit(g_ui32SysClock, pui8MACArray, srcIP, NETMASK, desIP, IPADDR_USE_STATIC);

//
// Setup the device locator service.
//
// LocatorInit();
// LocatorMACAddrSet(pui8MACArray);
// LocatorAppTitleSet("EK-TM4C1294XL enet_io");
// //
// // Initialize a sample httpd server.
// //
// httpd_init();

//
// Set the interrupt priorities. We set the SysTick interrupt to a higher
// priority than the Ethernet interrupt to ensure that the file system
// tick is processed if SysTick occurs while the Ethernet handler is being
// processed. This is very likely since all the TCP/IP and HTTP work is
// done in the context of the Ethernet interrupt.
//

udp_client();

MAP_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);

//
// Loop forever, processing the LED blinking. All the work is done in
// interrupt handlers.
//

while(1)
{
//
// Wait till the SysTick Interrupt indicates to change the state of the
// LED.
//
while(g_bLED == false)
{
}

//
// Clear the flag.
//
g_bLED = false;

//
// Toggle the LED.
//
MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,
(MAP_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1) ^
GPIO_PIN_1));
}
}

lwip opt.h file

//*****************************************************************************
//
// lwipopts.h - Configuration file for lwIP

#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__

//*****************************************************************************
//
// ---------- Stellaris / lwIP Port Options ----------
//
//*****************************************************************************
#define HOST_TMR_INTERVAL 100 // default is 0
//#define DHCP_EXPIRE_TIMER_MSECS (60 * 1000)
//#define LWIP_HTTPD_SSI 1
//#define LWIP_HTTPD_CGI 1
#define LWIP_HTTPD_DYNAMIC_HEADERS 1
//#define HTTPD_DEBUG LWIP_DBG_ON
#if !defined(EMAC_PHY_IS_EXT_MII) && !defined(EMAC_PHY_IS_EXT_RMII)
#define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_INTERNAL | EMAC_PHY_INT_MDIX_EN | \
EMAC_PHY_AN_100B_T_FULL_DUPLEX)
#define PHY_PHYS_ADDR 0
#endif
#if defined(EMAC_PHY_IS_EXT_MII)
#define EMAC_PHY_CONFIG EMAC_PHY_TYPE_EXTERNAL_MII
#define PHY_PHYS_ADDR 1
#endif
#if defined(EMAC_PHY_IS_EXT_RMII)
#define EMAC_PHY_CONFIG EMAC_PHY_TYPE_EXTERNAL_RMII
#define PHY_PHYS_ADDR 1
#endif
#define NUM_TX_DESCRIPTORS 24
#define NUM_RX_DESCRIPTORS 8

//*****************************************************************************
//
// ---------- Platform specific locking ----------
//
//*****************************************************************************
#define SYS_LIGHTWEIGHT_PROT 1 // default is 0
#define NO_SYS 1 // default is 0
//#define MEMCPY(dst,src,len) memcpy(dst,src,len)
//#define SMEMCPY(dst,src,len) memcpy(dst,src,len)

//*****************************************************************************
//
// ---------- Memory options ----------
//
//*****************************************************************************
//#define MEM_LIBC_MALLOC 0
#define MEM_ALIGNMENT 4
#define MEM_SIZE (64 * 1024)
//#define MEMP_OVERFLOW_CHECK 0
//#define MEMP_SANITY_CHECK 0
//#define MEM_USE_POOLS 0
//#define MEMP_USE_CUSTOM_POOLS 0

//*****************************************************************************
//
// ---------- Internal Memory Pool Sizes ----------
//
//*****************************************************************************
#define MEMP_NUM_PBUF 48 // Default 16
//#define MEMP_NUM_RAW_PCB 4
#define MEMP_NUM_UDP_PCB 4
#define MEMP_NUM_TCP_PCB 16 // Default 5
//#define MEMP_NUM_TCP_PCB_LISTEN 8
//#define MEMP_NUM_TCP_SEG 16
//#define MEMP_NUM_REASSDATA 5
//#define MEMP_NUM_ARP_QUEUE 30
//#define MEMP_NUM_IGMP_GROUP 8
#define MEMP_NUM_SYS_TIMEOUT 8
//#define MEMP_NUM_NETBUF 2
//#define MEMP_NUM_NETCONN 4
//#define MEMP_NUM_TCPIP_MSG_API 8
//#define MEMP_NUM_TCPIP_MSG_INPKT 8
#define PBUF_POOL_SIZE 48 // Default 16

//*****************************************************************************
//
// ---------- ARP options ----------
//
//*****************************************************************************
//#define LWIP_ARP 1
//#define ARP_TABLE_SIZE 10
//#define ARP_QUEUEING 1
//#define ETHARP_TRUST_IP_MAC 1

//*****************************************************************************
//
// ---------- IP options ----------
//
//*****************************************************************************
//#define IP_FORWARD 0
//#define IP_OPTIONS_ALLOWED 1
#define IP_REASSEMBLY 0 // default is 1
#define IP_FRAG 0 // default is 1
//#define IP_REASS_MAXAGE 3
//#define IP_REASS_MAX_PBUFS 10
//#define IP_FRAG_USES_STATIC_BUF 1
//#define IP_FRAG_MAX_MTU 1500
//#define IP_DEFAULT_TTL 255

//*****************************************************************************
//
// ---------- ICMP options ----------
//
//*****************************************************************************
//#define LWIP_ICMP 1
//#define ICMP_TTL (IP_DEFAULT_TTL)

//*****************************************************************************
//
// ---------- RAW options ----------
//
//*****************************************************************************
//#define LWIP_RAW 1
//#define RAW_TTL (IP_DEFAULT_TTL)

//*****************************************************************************
//
// ---------- DHCP options ----------
//
//*****************************************************************************
#define LWIP_DHCP 0 // default is 0
//#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP))

//*****************************************************************************
//
// ---------- UPNP options ----------
//
//*****************************************************************************
//#define LWIP_UPNP 0

//*****************************************************************************
//
// ---------- PTPD options ----------
//
//*****************************************************************************
//#define LWIP_PTPD 0

//*****************************************************************************
//
// ---------- AUTOIP options ----------
//
//*****************************************************************************
#define LWIP_AUTOIP 0 // default is 0
#define LWIP_DHCP_AUTOIP_COOP ((LWIP_DHCP) && (LWIP_AUTOIP))
// default is 0
#define LWIP_DHCP_AUTOIP_COOP_TRIES 5 // default is 9

//*****************************************************************************
//
// ---------- SNMP options ----------
//
//*****************************************************************************
//#define LWIP_SNMP 0
//#define SNMP_CONCURRENT_REQUESTS 1
//#define SNMP_TRAP_DESTINATIONS 1
//#define SNMP_PRIVATE_MIB 0
//#define SNMP_SAFE_REQUESTS 1

//*****************************************************************************
//
// ---------- IGMP options ----------
//
//*****************************************************************************
//#define LWIP_IGMP 0

//*****************************************************************************
//
// ---------- DNS options -----------
//
//*****************************************************************************
//#define LWIP_DNS 0
//#define DNS_TABLE_SIZE 4
//#define DNS_MAX_NAME_LENGTH 256
//#define DNS_MAX_SERVERS 2
//#define DNS_DOES_NAME_CHECK 1
//#define DNS_USES_STATIC_BUF 1
//#define DNS_MSG_SIZE 512

//*****************************************************************************
//
// ---------- UDP options ----------
//
//*****************************************************************************
#define LWIP_UDP 1
//#define LWIP_UDPLITE 0
//#define UDP_TTL (IP_DEFAULT_TTL)

//*****************************************************************************
//
// ---------- TCP options ----------
//
//*****************************************************************************
#define LWIP_TCP 1
//#define TCP_TTL (IP_DEFAULT_TTL)
#define TCP_WND 4096 // default is 2048
//#define TCP_MAXRTX 12
//#define TCP_SYNMAXRTX 6
//#define TCP_QUEUE_OOSEQ 1
#define TCP_MSS 1500 // default is 128
//#define TCP_CALCULATE_EFF_SEND_MSS 1
#define TCP_SND_BUF (4 * TCP_MSS)
// default is 256, was 6 *
//#define TCP_SND_QUEUELEN (4 * (TCP_SND_BUF/TCP_MSS))
//#define TCP_SNDLOWAT (TCP_SND_BUF/2)
//#define TCP_LISTEN_BACKLOG 0
//#define TCP_DEFAULT_LISTEN_BACKLOG 0xff

//*****************************************************************************
//
// ---------- API options ----------
//
//*****************************************************************************
//#define LWIP_EVENT_API 0
//#define LWIP_CALLBACK_API 1

//*****************************************************************************
//
// ---------- Pbuf options ----------
//
//*****************************************************************************
#define PBUF_LINK_HLEN 16 // default is 14
#define PBUF_POOL_BUFSIZE 512
// PBUF_POOL_BUFSIZE default is
// LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)
#define ETH_PAD_SIZE 0 // default is 0

//*****************************************************************************
//
// ---------- Network Interfaces options ----------
//
//*****************************************************************************
//#define LWIP_NETIF_HOSTNAME 0
//#define LWIP_NETIF_API 0
//#define LWIP_NETIF_STATUS_CALLBACK 0
//#define LWIP_NETIF_LINK_CALLBACK 0
//#define LWIP_NETIF_HWADDRHINT 0

//*****************************************************************************
//
// ---------- LOOPIF options ----------
//
//*****************************************************************************
//#define LWIP_HAVE_LOOPIF 0
//#define LWIP_LOOPIF_MULTITHREADING 1

//*****************************************************************************
//
// ---------- Thread options ----------
//
//*****************************************************************************
//#define TCPIP_THREAD_NAME "tcpip_thread"
//#define TCPIP_THREAD_STACKSIZE 0
//#define TCPIP_THREAD_PRIO 1
//#define TCPIP_MBOX_SIZE 0
//#define SLIPIF_THREAD_NAME "slipif_loop"
//#define SLIPIF_THREAD_STACKSIZE 0
//#define SLIPIF_THREAD_PRIO 1
//#define PPP_THREAD_NAME "pppMain"
//#define PPP_THREAD_STACKSIZE 0
//#define PPP_THREAD_PRIO 1
//#define DEFAULT_THREAD_NAME "lwIP"
//#define DEFAULT_THREAD_STACKSIZE 0
//#define DEFAULT_THREAD_PRIO 1
//#define DEFAULT_RAW_RECVMBOX_SIZE 0
//#define DEFAULT_UDP_RECVMBOX_SIZE 0
//#define DEFAULT_TCP_RECVMBOX_SIZE 0
//#define DEFAULT_ACCEPTMBOX_SIZE 0

//*****************************************************************************
//
// ---------- Sequential layer options ----------
//
//*****************************************************************************
//#define LWIP_TCPIP_CORE_LOCKING 0
#define LWIP_NETCONN 0 // default is 1

//*****************************************************************************
//
// ---------- Socket Options ----------
//
//*****************************************************************************
#define LWIP_SOCKET 0 // default is 1
//#define LWIP_COMPAT_SOCKETS 1
//#define LWIP_POSIX_SOCKETS_IO_NAMES 1
//#define LWIP_TCP_KEEPALIVE 0
//#define LWIP_SO_RCVTIMEO 0
//#define LWIP_SO_RCVBUF 0
//#define SO_REUSE 0

//*****************************************************************************
//
// ---------- Statistics options ----------
//
//*****************************************************************************
//#define LWIP_STATS 1
//#define LWIP_STATS_DISPLAY 0
//#define LINK_STATS 1
//#define ETHARP_STATS (LWIP_ARP)
//#define IP_STATS 1
//#define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG)
//#define ICMP_STATS 1
//#define IGMP_STATS (LWIP_IGMP)
#define UDP_STATS (LWIP_UDP)
//#define TCP_STATS (LWIP_TCP)
//#define MEM_STATS 1
//#define MEMP_STATS 1
//#define SYS_STATS 1

//*****************************************************************************
//
// ---------- PPP options ----------
//
//*****************************************************************************
//#define PPP_SUPPORT 0
//#define PPPOE_SUPPORT 0
//#define PPPOS_SUPPORT PPP_SUPPORT

#if PPP_SUPPORT
//#define NUM_PPP 1
//#define PAP_SUPPORT 0
//#define CHAP_SUPPORT 0
//#define MSCHAP_SUPPORT 0
//#define CBCP_SUPPORT 0
//#define CCP_SUPPORT 0
//#define VJ_SUPPORT 0
//#define MD5_SUPPORT 0
//#define FSM_DEFTIMEOUT 6
//#define FSM_DEFMAXTERMREQS 2
//#define FSM_DEFMAXCONFREQS 10
//#define FSM_DEFMAXNAKLOOPS 5
//#define UPAP_DEFTIMEOUT 6
//#define UPAP_DEFREQTIME 30
//#define CHAP_DEFTIMEOUT 6
//#define CHAP_DEFTRANSMITS 10
//#define LCP_ECHOINTERVAL 0
//#define LCP_MAXECHOFAILS 3
//#define PPP_MAXIDLEFLAG 100

//#define PPP_MAXMTU 1500
//#define PPP_DEFMRU 296
#endif

//*****************************************************************************
//
// ---------- checksum options ----------
//
//*****************************************************************************
#define CHECKSUM_GEN_IP 0
#define CHECKSUM_GEN_ICMP 0
#define CHECKSUM_GEN_UDP 0
#define CHECKSUM_GEN_TCP 0
#define CHECKSUM_CHECK_IP 0
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_TCP 0

//*****************************************************************************
//
// ---------- Debugging options ----------
//
//*****************************************************************************
#if 0
#define U8_F "c"
#define S8_F "c"
#define X8_F "x"
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
extern void UARTprintf(const char *pcString, ...);
#define LWIP_DEBUG
#endif

//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF
//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_WARNING
//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_SERIOUS
//#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_SEVERE

//#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE| \
LWIP_DBG_STATE|LWIP_DBG_FRESH)

//#define ETHARP_DEBUG LWIP_DBG_ON // default is OFF
//#define NETIF_DEBUG LWIP_DBG_ON // default is OFF
//#define PBUF_DEBUG LWIP_DBG_OFF
//#define API_LIB_DEBUG LWIP_DBG_OFF
//#define API_MSG_DEBUG LWIP_DBG_OFF
//#define SOCKETS_DEBUG LWIP_DBG_OFF
//#define ICMP_DEBUG LWIP_DBG_OFF
//#define IGMP_DEBUG LWIP_DBG_OFF
//#define INET_DEBUG LWIP_DBG_OFF
//#define IP_DEBUG LWIP_DBG_ON // default is OFF
//#define IP_REASS_DEBUG LWIP_DBG_OFF
//#define RAW_DEBUG LWIP_DBG_OFF
//#define MEM_DEBUG LWIP_DBG_OFF
//#define MEMP_DEBUG LWIP_DBG_OFF
//#define SYS_DEBUG LWIP_DBG_OFF
//#define TCP_DEBUG LWIP_DBG_OFF
//#define TCP_INPUT_DEBUG LWIP_DBG_OFF
//#define TCP_FR_DEBUG LWIP_DBG_OFF
//#define TCP_RTO_DEBUG LWIP_DBG_OFF
//#define TCP_CWND_DEBUG LWIP_DBG_OFF
//#define TCP_WND_DEBUG LWIP_DBG_OFF
//#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
//#define TCP_RST_DEBUG LWIP_DBG_OFF
//#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_ON // default is OFF
//#define TCPIP_DEBUG LWIP_DBG_OFF
//#define PPP_DEBUG LWIP_DBG_OFF
//#define SLIP_DEBUG LWIP_DBG_OFF
//#define DHCP_DEBUG LWIP_DBG_ON // default is OFF
//#define AUTOIP_DEBUG LWIP_DBG_OFF
//#define SNMP_MSG_DEBUG LWIP_DBG_OFF
//#define SNMP_MIB_DEBUG LWIP_DBG_OFF
//#define DNS_DEBUG LWIP_DBG_OFF

#endif /* __LWIPOPTS_H__ */

  • Hi,

      The fault could be due to insufficient heap or stack. Can you increase the heap and stack size and see if they make a difference? 

      Please also use this app note to diagnose the fault exception. https://www.ti.com/lit/pdf/spma043

      There are also some udp examples in this app note. Can you reference and compare with your own code? https://www.ti.com/lit/pdf/spna248

  • Hi,

     What is the status of this issue? Can you provide some update if you are able to resolve and identify the cause of the fault?

  • No after increasing the heap and stack memory, able to receive the udp frame but when i invoke udp_connect udp port not working can you check above 

    shared code once.

     enet_lwip_udp3.zip

    Regards, 

    Sandeep C

  • Why don't you try this example. I can run it and communicate with the PC in UDP.  I use DHCP but that shouldn't make a difference. You will need to change the server address per your PC on your network as mine will be different than yours. 

    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/flash.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/gpio.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "utils/lwiplib.h"
    #include "utils/ustdlib.h"
    #include "utils/uartstdio.h"
    #include "drivers/pinout.h"
    #include "lwip/udp.h"
    #include "lwip/inet.h"
    
    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Ethernet UDP Echo Client with lwIP (enet_udpecho_client_lwip)</h1>
    //!
    //! This UDP Echo client application demonstrates the operation of the Tiva
    //! Ethernet controller using the lwIP TCP/IP Stack.  DHCP is used to obtain
    //! an Ethernet address.  If DHCP times out without obtaining an address,
    //! AutoIP will be used to obtain a link-local address.  The address that is
    //! selected will be shown on the UART.
    //!
    //! UART0, connected to the ICDI virtual COM port and running at 115,200,
    //! 8-N-1, is used to display messages from this application.
    //!
    //! For additional details on lwIP, refer to the lwIP web page at:
    //! http://savannah.nongnu.org/projects/lwip/
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // Defines for the Sever IP Address.
    // NOTE: User must enter the correct server IP address
    //
    // Port 23 is chosen for telenet connection.
    //
    //*****************************************************************************
    #define SERVER_IPADDR "192.168.254.79"
    #define CLIENT_PORT 8
    #define SERVER_PORT 7
    
    //*****************************************************************************
    //
    // 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
    
    
    
    //*****************************************************************************
    //
    // Global flag that will be set to 1 when the DHCP address is acquired
    //
    //*****************************************************************************
    uint32_t g_ui32ipAddrValid = 0;
    
    //*****************************************************************************
    //
    // The current IP address.
    //
    //*****************************************************************************
    uint32_t g_ui32IPAddress;
    
    //*****************************************************************************
    //
    // The system clock frequency.
    //
    //*****************************************************************************
    uint32_t g_ui32SysClock;
    
    //*****************************************************************************
    //
    // Volatile global flag to manage LED blinking, since it is used in interrupt
    // and main application.  The LED blinks at the rate of SYSTICKHZ.
    //
    //*****************************************************************************
    volatile bool g_bLED;
    
    //*****************************************************************************
    //
    // Global LwIP variables
    //
    //*****************************************************************************
    struct udp_pcb *upcb;
    
    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif
    
    //*****************************************************************************
    //
    // Display an lwIP type IP Address.
    //
    //*****************************************************************************
    void
    DisplayIPAddress(uint32_t ui32Addr)
    {
        char pcBuf[16];
    
        //
        // Convert the IP Address into a string.
        //
        usprintf(pcBuf, "%d.%d.%d.%d", ui32Addr & 0xff, (ui32Addr >> 8) & 0xff,
                (ui32Addr >> 16) & 0xff, (ui32Addr >> 24) & 0xff);
    
        //
        // Display the string.
        //
        UARTprintf(pcBuf);
    
        //
        // Set the flag to indicate the IP address is acquired
        g_ui32ipAddrValid = 1;
    
    }
    
    //*****************************************************************************
    //
    // Required by lwIP library to support any host-related timer functions.
    //
    //*****************************************************************************
    void
    lwIPHostTimerHandler(void)
    {
        uint32_t ui32NewIPAddress;
    
        //
        // Get the current IP address.
        //
        ui32NewIPAddress = lwIPLocalIPAddrGet();
    
        //
        // See if the IP address has changed.
        //
        if(ui32NewIPAddress != g_ui32IPAddress)
        {
            //
            // See if there is an IP address assigned.
            //
            if(ui32NewIPAddress == 0xffffffff)
            {
                //
                // Indicate that there is no link.
                //
                UARTprintf("Waiting for link.\n");
            }
            else if(ui32NewIPAddress == 0)
            {
                //
                // There is no IP address, so indicate that the DHCP process is
                // running.
                //
                UARTprintf("Waiting for IP address.\n");
            }
            else
            {
                //
                // Display the new IP address.
                //
                UARTprintf("IP Address: ");
                DisplayIPAddress(ui32NewIPAddress);
            }
    
            //
            // Save the new IP address.
            //
            g_ui32IPAddress = ui32NewIPAddress;
        }
    
        //
        // If there is not an IP address.
        //
        if((ui32NewIPAddress == 0) || (ui32NewIPAddress == 0xffffffff))
        {
            //
            // Do nothing and keep waiting.
            //
        }
    }
    
    //*****************************************************************************
    //
    // The interrupt handler for the SysTick interrupt.
    //
    //*****************************************************************************
    void
    SysTickIntHandler(void)
    {
        //
        // Call the lwIP timer handler.
        //
        lwIPTimer(SYSTICKMS);
    
        //
        // Tell the application to change the state of the LED (in other words
        // blink).
        //
        g_bLED = true;
    }
    
    //*****************************************************************************
    //
    // This callback function is called when payload is received
    //
    //*****************************************************************************
    void
    UdpEchoRecv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
    {
        if (p != NULL) {
            //
            // send received packet back to sender
            //
            UARTprintf("\r\nReceiving %d bytes of data\n\r", p->tot_len);
            udp_sendto(pcb, p, addr, port);
            //
            //free the pbuf
            //
            pbuf_free(p);
        }
    }
    
    //*****************************************************************************
    //
    // Initialize UDP client and send a greeting message to the server
    //
    //*****************************************************************************
    void
    UdpClientInit(void)
    {
        struct pbuf *p;
        struct ip_addr ServerIPaddr;
        err_t err;
        char *greeting = "Hello! Greeting from EK-TM4C129XL LaunchPad \r\n";
    
        //
        // Create a new UDP control block
        //
        upcb = udp_new();
    
        if (upcb!=NULL)
        {
            //
            // Bind the pcb to local address=IP_ADDR_ANY at port 23.
            // Also register the callback function to call when receiving payload
            //
            udp_bind(upcb, IP_ADDR_ANY, CLIENT_PORT);
            udp_recv(upcb, UdpEchoRecv, NULL);
    
            //
            // assign destination server IP address
            //
            ServerIPaddr.addr = inet_addr(SERVER_IPADDR);
    
            //
            // configure destination IP address and port
            //
            err = udp_connect(upcb, &ServerIPaddr, SERVER_PORT);
    
            if (err == ERR_OK)
            {
                //
                // allocate pbuf from pool
                //
                p = pbuf_alloc(PBUF_TRANSPORT,strlen((char*)greeting), PBUF_RAM);
    
                if (p != NULL)
                {
                    //
                    // copy greeting to pbuf
                    //
                    pbuf_take(p, (char*)greeting, strlen((char*)greeting));
    
                    //
                    // send udp data
                    //               */
                    udp_send(upcb, p);
    
                    //
                    // free pbuf
                    //
                    pbuf_free(p);
    
                }
                else
                {
                    //
                    // free the UDP connection, so we can accept new clients
                    //
                    udp_remove(upcb);
                    UARTprintf("\n\r can not allocate pbuf ");
                }
            }
            else
            {
                //
                // free the UDP connection, so we can accept new clients
                //
                udp_remove(upcb);
                UARTprintf("\n\r can not connect udp pcb");
            }
        }
        else
        {
            UARTprintf("\n\r can not create udp pcb");
        }
    
        //
        // Disconnect the remote address from the PCB
        // CT 02182021. Looks like I must have udp_bind and udp_disconnect in order for
        // this example to work. I don't know exactly why. I think the udp_disconnect is
        // to remove the server address from PCB. When we use udp_connect we were sending
        // to a specific server address with the udp_send. After we send the greeting
        // message the program becomes a client to simply echo back data it receives from
        // the server. Since the UDP is a connectionless protocol, I think this is the
        // reason we need to remove the server address using udp_disconnect. We want to
        // receive datagram from any servers, not tied to a specific server address.
        //  We are going to use udp_sendto to send back to any address we receive the
        // data from. The udp_sendto does not associate with any address but whatever
        // address the PCB receive the remote address. Maybe
        // this is the reason we need to also use udp_bind so we can bind the local PCB
        // to any address to receive the datagram.
        //
        udp_disconnect(upcb);
    
    }
    
    //*****************************************************************************
    //
    // This example demonstrates the use of the Ethernet Controller.
    //
    //*****************************************************************************
    int
    main(void)
    {
        uint32_t ui32User0, ui32User1;
        uint8_t pui8MACArray[8];
    
        //
        // Make sure the main oscillator is enabled because this is required by
        // the PHY.  The system must have a 25MHz crystal attached to the OSC
        // pins. The SYSCTL_MOSC_HIGHFREQ parameter is used when the crystal
        // frequency is 10MHz or higher.
        //
        MAP_SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ);
    
        //
        // Run from the PLL at 120 MHz.
        // Note: SYSCTL_CFG_VCO_240 is a new setting provided in TivaWare 2.2.x and
        // later to better reflect the actual VCO speed due to SYSCTL#22.
        //
        g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                 SYSCTL_OSC_MAIN |
                                                 SYSCTL_USE_PLL |
                                                 SYSCTL_CFG_VCO_240), 120000000);
    
        //
        // Configure the device pins.
        //
        PinoutSet(true, false);
        //
        // Configure UART.
        //
        UARTStdioConfig(0, 115200, g_ui32SysClock);
    
        //
        // Clear the terminal and print banner.
        //
        UARTprintf("\033[2J\033[H");
        UARTprintf("Ethernet lwIP UDP Echo client example\n\n");
    
        //
        // Configure Port N1 for as an output for the animation LED.
        //
        MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);
    
        //
        // Initialize LED to OFF (0)
        //
        MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, ~GPIO_PIN_1);
    
        //
        // Configure SysTick for a periodic interrupt.
        //
        MAP_SysTickPeriodSet(g_ui32SysClock / SYSTICKHZ);
        MAP_SysTickEnable();
        MAP_SysTickIntEnable();
    
        //
        // Configure the hardware MAC address for Ethernet Controller filtering of
        // incoming packets.  The MAC address will be stored in the non-volatile
        // USER0 and USER1 registers.
        //
        MAP_FlashUserGet(&ui32User0, &ui32User1);
        if((ui32User0 == 0xffffffff) || (ui32User1 == 0xffffffff))
        {
            //
            // We should never get here.  This is an error if the MAC address has
            // not been programmed into the device.  Exit the program.
            // Let the user know there is no MAC address
            //
            UARTprintf("No MAC programmed!\n");
            while(1)
            {
            }
        }
    
        //
        // Tell the user what we are doing just now.
        //
        UARTprintf("Waiting for IP.\n");
    
        //
        // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
        // address needed to program the hardware registers, then program the MAC
        // address into the Ethernet Controller registers.
        //
        pui8MACArray[0] = ((ui32User0 >>  0) & 0xff);
        pui8MACArray[1] = ((ui32User0 >>  8) & 0xff);
        pui8MACArray[2] = ((ui32User0 >> 16) & 0xff);
        pui8MACArray[3] = ((ui32User1 >>  0) & 0xff);
        pui8MACArray[4] = ((ui32User1 >>  8) & 0xff);
        pui8MACArray[5] = ((ui32User1 >> 16) & 0xff);
    
        //
        // Initialize the lwIP library, using DHCP.
        //
    
        lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_DHCP);
    
        //
        // Wait until the IP address is acquired before the client connect
        // to the server.
        //
        while (g_ui32ipAddrValid == 0);
    
        //
        // Start the client to send a greeting message to the external host
        //
        UdpClientInit();
    
        //
        // Set the interrupt priorities.  We set the SysTick interrupt to a higher
        // priority than the Ethernet interrupt to ensure that the file system
        // tick is processed if SysTick occurs while the Ethernet handler is being
        // processed.  This is very likely since all the TCP/IP and HTTP work is
        // done in the context of the Ethernet interrupt.
        //
        MAP_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
        MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);
    
        //
        // Loop forever, processing the LED blinking.  All the work is done in
        // interrupt handlers.
        //
        while(1)
        {
            //
            // Wait till the SysTick Interrupt indicates to change the state of the
            // LED.
            //
            while(g_bLED == false)
            {
            }
    
            //
            // Clear the flag.
            //
            g_bLED = false;
    
            //
            // Toggle the LED.
            //
            MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,
                             (MAP_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1) ^
                              GPIO_PIN_1));
        }
    }