求救!在LM3s8962使用LwIP建立TCP连接时遇到的问题

2019-03-24 14:15发布

    无操作系统,通过以下程序在keil中建立TCP客户端时,总是会在 tcp_connect()函数里出现问题(FaultISR),但在IAR中式可以的,为什么?lwipopt.h配置是一样的,只不过在IAR中使用的是LwIP1.3.0而在Keil中使用的是LwIP1.3.1.。现在我将源码俯下:     #include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "inc/hw_types.h"
#include "driverlib/ethernet.h" #include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/lwiplib.h"
#include "drivers/rit128x96x4.h"
        
#define My_Mac_ID   {0XFF,0xFF,0xFF,0xFF,0xF1,0xF1}
static const unsigned char pucMACAddress[] = My_Mac_ID;

#define SYSTICKHZ                100
#define SYSTICKMS               (1000 / SYSTICKHZ)
#define SYSTICKUS               (1000000 / SYSTICKHZ)
#define SYSTICKNS               (1000000000 / SYSTICKHZ)  
#define SYSTICK_INT_PRIORITY    0x80
#define ETHERNET_INT_PRIORITY   0xC0   unsigned char IPAddress[] = MY_IP_ID;
unsigned char NetMaskAddr[] = IP_MARK_ID;
unsigned char GwWayAddr[] = MY_GATEWAY_ID;   const static char TCP_TestData[]="This is LwIP TCP Client 在Luminary Cortex-M3上的测试! ";  
void
SysTickIntHandler(void)
{
   
  lwIPTimer(SYSTICKMS);
} void Delay(unsigned long ulVal)
{
   while(--ulVal!=0);
}

void
DisplayIPAddress(unsigned long ipaddr, unsigned long ulCol,
                 unsigned long ulRow)
{
    char pucBuf[16];
    unsigned char *pucTemp = (unsigned char *)&ipaddr;
     usprintf(pucBuf, "%d.%d.%d.%d", pucTemp[0], pucTemp[1], pucTemp[2],
             pucTemp[3]);   RIT128x96x4StringDraw(pucBuf, ulCol, ulRow, 15);
}   err_t TcpCli_Connected(void *arg,struct tcp_pcb *pcb,err_t err)
{
   tcp_write(pcb,TCP_TestData,sizeof(TCP_TestData),0);     
  
   tcp_close(pcb);
  
   return ERR_OK;
}
void TCP_Client_Init()
{
  struct tcp_pcb *Clipcb;
  struct ip_addr ipaddr;
 
  IP4_ADDR(&ipaddr,192,168,0,127);
 
  Clipcb = tcp_new();                       
 
  tcp_bind(Clipcb,IP_ADDR_ANY,1026);      
 
  tcp_connect(Clipcb,&ipaddr,1026,TcpCli_Connected);
}  
int
main(void)
{
 unsigned long,ulIPAddr,ulNetMask,ulGWAddr;
 
  unsigned long ulIPAddress;     SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
  
     
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("BOARD A IP ADDRESS", 12, 0, 15);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);     SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
    SysTickEnable();
    SysTickIntEnable();     IntMasterEnable();
 ulIPAddr=0xC0A80064;  //192.168.0.100
    ulNetMask=0xFFFFFF00;  //255.255.255.0
 ulGWAddr=0xC0A80001;  //192.168.0.1         lwIPInit(pucMACAddress,ulIPAddr, ulNetMask, ulGWAddr, IPADDR_USE_STATIC);   
   ulIPAddress = lwIPLocalIPAddrGet();
     RIT128x96x4StringDraw("IP:   ", 0, 16, 15);
        RIT128x96x4StringDraw("MASK: ", 0, 24, 15);
        RIT128x96x4StringDraw("GW:   ", 0, 32, 15);
  RIT128x96x4StringDraw("AS A TCP CLIENT!", 0, 40, 15);
        DisplayIPAddress(ulIPAddress, 36, 16);
        ulIPAddress = lwIPLocalNetMaskGet();
        DisplayIPAddress(ulIPAddress, 36, 24);
        ulIPAddress = lwIPLocalGWAddrGet();
        DisplayIPAddress(ulIPAddress, 36, 32);     while(1)
    {
   TCP_Client_Init();
      Delay(1000000UL); 
      Delay(1000000UL);
      Delay(1000000UL);
    }
}
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
11条回答
fengzhang2002
2019-03-26 05:45
 精彩回答 2  元偷偷看……0人看过

一周热门 更多>

相关问题

    相关文章