Hi all,
I'm using TMS570LC43x Hercules Development Kit in my project, I'm trying to implement Ethernet program and I'm referring below link for it.
http://processors.wiki.ti.com/index.php/LAUNCHXL2_570LC43:_lwIP_Demo
But I'm getting an error. I'm not understanding where are I'm missing the follow. On my console it showing
HERCULES MICROCONTROLLERS
Texas Instruments
Little Endian device
Initializing ethernet (DHCP)
DEBUG - Getting PHY ID....SUCCESS
DEBUG - Getting PHY Alive Status...SUCCESS
DEBUG - Getting PHY Link Status...!!! ERROR !!!..DONE
-------- ERROR INITIALIZING HARDWARE --------
(I connected board Ethernet cable to my pc. I'm trying to make a local network and I attached my code)How to solve it?
/** @file HL_sys_main.c * @brief Application main file * @date 28.Aug.2015 * @version 04.05.01 * * This file contains an empty main function, * which can be used for the application. */ /* * Copyright (C) 2009-2015 Texas Instruments Incorporated - www.ti.com * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ /* USER CODE BEGIN (0) */ /* USER CODE END */ /* Include Files */ #include "HL_sys_common.h" #include "err.h" #include "tcp.h" /* USER CODE BEGIN (1) */ /* USER CODE BEGIN (1) */ #include "HL_gio.h" #include "HL_emac.h" extern void EMAC_LwIP_Main (uint8_t * emacAddress); // CONSTANT #define MAX_TCP_CONNECTIONS 10 // depende de MEMP_NUM_TCP_PCB em lwipopts.h #define SIZE_OF_BUFFER_TCP 3000 #define PORTNUMBER 6000 /* ECHO protocol states */ enum tcp_states { ES_NOT_CONNECTED = 0, ES_CONNECTED, ES_ACCEPTED, ES_RECEIVED, ES_CLOSING }; /* structure for maintaing connection infos to be passed as argument to LwIP callbacks*/ struct tcp_struct { u8_t state; /* current connection state */ struct tcp_pcb *pcb; /* pointer on the current tcp_pcb */ struct pbuf *p; /* pointer on the received/to be transmitted pbuf */ }; /*static uint8_t bufferTxTCP[SIZE_OF_BUFFER_TCP]; static uint8_t bufferRxTCP[SIZE_OF_BUFFER_TCP]; */ static uint8_t bufferTxTCP[SIZE_OF_BUFFER_TCP]; static uint8_t bufferRxTCP[SIZE_OF_BUFFER_TCP]; volatile uint8_t *pRxTCP_HEAD = bufferRxTCP; volatile uint8_t *pRxTCP_TAIL = bufferRxTCP; volatile uint8_t *pTxTCP_HEAD = bufferTxTCP; volatile uint8_t *pTxTCP_TAIL = bufferTxTCP; // LOCAL FUNCTIONS void gioInit(void); //void EMAC_LwIP_Main (uint8_t * macAddress); static err_t tcp_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err); static err_t tcp_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); static void tcp_error_callback(void *arg, err_t err); static err_t tcp_poll_callback(void *arg, struct tcp_pcb *tpcb); static err_t tcp_sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len); static void tcp_send(struct tcp_pcb *tpcb, struct tcp_struct *es); static void tcp_connection_close(struct tcp_pcb *tpcb, struct tcp_struct *es); //static uint16_t checkTcpMsgToSend( uint8_t *buf ); static void checkTcpBufferPointers( void ); uint8_t getPcbIndex( uint16_t pcbPort ); void app_getTcpPayloadMsg( uint16_t port, uint8_t *buf, uint16_t len ); uint8 emacAddress[6U] = {0x00U, 0x08U, 0xEEU, 0x03U, 0xA6U, 0x6CU}; uint32 emacPhyAddress = 1U; char g_cTCPbuff[25] = "This is herc_tcp test..."; int g_nLenthOfbuff = 25; struct tcp_pcb *TCPServerpcb; void delay(unsigned long mSec) { unsigned long i,j; for(i=0; i<mSec;i++) { for(j=0;j<1000;j++) { ; } } } void main(void) { /* USER CODE BEGIN (3) */ err_t err = 0xFF; uint16_t len = 0; uint8_t buf[1500]; g_nLenthOfbuff = sizeof(g_cTCPbuff); //AutoNegotiate(MDIO_0_BASE,1,DP83640_100BTX | DP83640_100BTX_FD | DP83640_10BT | DP83640_10BT_FD); //EMACDuplexSet(EMAC_0_BASE,EMAC_DUPLEX_HALF); //lwip_init(); tcp_tmr(); sys_check_timeouts(); //Must be called periodically from your main loop gioInit(); EMAC_LwIP_Main(emacAddress); TCPServerpcb = NULL; while(1) { //TCPServerpcb = NULL; if(TCPServerpcb == NULL ) { TCPServerpcb = tcp_new(); if(TCPServerpcb != NULL ) { err = tcp_bind(TCPServerpcb,IP_ADDR_ANY,PORTNUMBER); /// binding if (err == ERR_OK) { TCPServerpcb = tcp_listen(TCPServerpcb); tcp_accept(TCPServerpcb,tcp_accept_callback); } else { // memp_free(MEMP_TCP_PCB, TCPServerpcb); TCPServerpcb = NULL; } } } else { if( TCPServerpcb->state == ESTABLISHED ) { if(( TCPServerpcb->state == ESTABLISHED)&&( g_nLenthOfbuff )) { if( tcp_write( TCPServerpcb, buf , len, 0 ) == ERR_OK ) { tcp_output(TCPServerpcb); } g_nLenthOfbuff = 0; } } } } } static err_t tcp_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err) { err_t ret_err; struct tcp_struct *es; uint8_t pcbIndex; LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(err); /* set priority for the newly accepted tcp connection newpcb */ tcp_setprio(newpcb, TCP_PRIO_MIN); /* allocate structure es to maintain tcp connection informations */ es = (struct tcp_struct *)mem_malloc(sizeof(struct tcp_struct)); if (es != NULL) { es->state = ES_ACCEPTED; es->pcb = newpcb; es->p = NULL; /* pass newly allocated es structure as argument to newpcb */ tcp_arg(newpcb, es); /* initialize lwip tcp_recv callback function for newpcb */ tcp_recv(newpcb, tcp_recv_callback); /* initialize lwip tcp_err callback function for newpcb */ tcp_err(newpcb, tcp_error_callback); /* initialize lwip tcp_poll callback function for newpcb */ tcp_poll(newpcb, tcp_poll_callback, 1); tcp_sent(newpcb, tcp_sent_callback); ret_err = ERR_OK; } else { /* close tcp connection */ tcp_connection_close(newpcb, es); /* return memory error */ ret_err = ERR_MEM; } // ADAPTED pcbIndex = getPcbIndex( newpcb->local_port ); if( pcbIndex != 0xFF ) TCPServerpcb = newpcb; else tcp_connection_close(newpcb, es); return ret_err; } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ static err_t tcp_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { struct tcp_struct *es; err_t ret_err; char *pc = NULL; struct pbuf *ptr; u16_t plen; LWIP_ASSERT("arg != NULL",arg != NULL); es = (struct tcp_struct *)arg; /* if we receive an empty tcp frame from client => close connection */ if (p == NULL) { /* remote host closed connection */ es->state = ES_CLOSING; if(es->p == NULL) { /* we're done sending, close connection */ tcp_connection_close(tpcb, es); } else { /* we're not done yet */ /* acknowledge received packet */ tcp_sent(tpcb, tcp_sent_callback); /* send remaining data*/ tcp_send(tpcb, es); } ret_err = ERR_OK; } /* else : a non empty frame was received from client but for some reason err != ERR_OK */ else if(err != ERR_OK) { /* free received pbuf*/ if (p != NULL) { es->p = NULL; pbuf_free(p); } ret_err = err; } else if(es->state == ES_ACCEPTED) { /* first data chunk in p->payload */ es->state = ES_RECEIVED; /* store reference to incoming pbuf (chain) */ es->p = p; /* initialize LwIP tcp_sent callback function */ tcp_sent(tpcb, tcp_sent_callback); //--------------------------------------------------------------------------- // app get the msg if(es->p != NULL ) { es->p = p; pc = (char *)p->payload; if( es->p->len > 0 ) { app_getTcpPayloadMsg( tpcb->local_port, (uint8_t *)pc, p->len ); } } //-------------------------------------------- // adaptation from tcp_echo_server ptr = es->p; plen = ptr->len; es->p = ptr->next; if(es->p != NULL) pbuf_ref(es->p); pbuf_free(ptr); /* Update tcp window size to be advertized : should be called when received data (with the amount plen) has been processed by the application layer */ tcp_recved(tpcb, plen); ret_err = ERR_OK; } else if (es->state == ES_RECEIVED) { /* more data received from client and previous data has been already sent*/ if(es->p == NULL) { //--------------------------------------------------------------------------- // app get the msg es->p = p; pc = (char *)p->payload; if( es->p->len > 0 ) { app_getTcpPayloadMsg( tpcb->local_port, (uint8_t *)pc, p->len ); } //-------------------------------------------- // adaptation from tcp_echo_server ptr = es->p; plen = ptr->len; es->p = ptr->next; if(es->p != NULL) pbuf_ref(es->p); pbuf_free(ptr); /* Update tcp window size to be advertized : should be called when received data (with the amount plen) has been processed by the application layer */ tcp_recved(tpcb, plen); } else { struct pbuf *ptr; /* chain pbufs to the end of what we recv'ed previously */ ptr = es->p; pbuf_chain(ptr,p); } ret_err = ERR_OK; } /* data received when connection already closed */ else { /* Acknowledge data reception */ tcp_recved(tpcb, p->tot_len); /* free pbuf and do nothing */ es->p = NULL; pbuf_free(p); ret_err = ERR_OK; } return ret_err; } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ static err_t tcp_poll_callback(void *arg, struct tcp_pcb *tpcb) { err_t ret_err; struct tcp_struct *es; es = (struct tcp_struct *)arg; if (es != NULL) { if (es->p != NULL) { /* there is a remaining pbuf (chain) , try to send data */ tcp_send(tpcb, es); } else { /* no remaining pbuf (chain) */ if(es->state == ES_CLOSING) { /* close tcp connection */ tcp_connection_close(tpcb, es); } } ret_err = ERR_OK; } else { /* nothing to be done */ tcp_abort(tpcb); ret_err = ERR_ABRT; } return ret_err; } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ static void tcp_send(struct tcp_pcb *tpcb, struct tcp_struct *es) { struct pbuf *ptr; err_t wr_err = ERR_OK; while ((wr_err == ERR_OK) && (es->p != NULL) && (es->p->len <= tcp_sndbuf(tpcb))) { /* get pointer on pbuf from es structure */ ptr = es->p; /* enqueue data for transmission */ wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1); if (wr_err == ERR_OK) { u16_t plen; plen = ptr->len; /* continue with next pbuf in chain (if any) */ es->p = ptr->next; if(es->p != NULL) { /* increment reference count for es->p */ pbuf_ref(es->p); } /* free pbuf: will free pbufs up to es->p (because es->p has a reference count > 0) */ pbuf_free(ptr); /* Update tcp window size to be advertized : should be called when received data (with the amount plen) has been processed by the application layer */ tcp_recved(tpcb, plen); } else if(wr_err == ERR_MEM) { /* we are low on memory, try later / harder, defer to poll */ es->p = ptr; } else { /* other problem ?? */ } } } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ static void tcp_error_callback(void *arg, err_t err) { struct tcp_struct *es; LWIP_UNUSED_ARG(err); es = (struct tcp_struct *)arg; if (es != NULL) { /* free es structure */ mem_free(es); } } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ static err_t tcp_sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len) { struct tcp_struct *es; LWIP_UNUSED_ARG(len); es = (struct tcp_struct *)arg; if(es->p != NULL) { /* still got pbufs to send */ tcp_send(tpcb, es); } else { /* if no more data to send and client closed connection*/ if(es->state == ES_CLOSING) tcp_connection_close(tpcb, es); } return ERR_OK; } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ static void tcp_connection_close(struct tcp_pcb *tpcb, struct tcp_struct *es) { /* remove all callbacks */ tcp_arg(tpcb, NULL); tcp_sent(tpcb, NULL); tcp_recv(tpcb, NULL); tcp_err(tpcb, NULL); tcp_poll(tpcb, NULL, 0); /* delete es structure */ if (es != NULL) { mem_free(es); } /* close tcp connection */ tcp_close(tpcb); } uint8_t getPcbIndex( uint16_t pcbPort ) { if( pcbPort == 6000 ) return 0; return 0xFF; } void app_getTcpPayloadMsg( uint16_t port, uint8_t *buf, uint16_t len ) { uint16_t i; if(port == 6000 ) { checkTcpBufferPointers(); *(pRxTCP_HEAD++) = buf[i]; checkTcpBufferPointers(); } } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ void checkTcpMsgReceived(void) { uint16_t i,j,len = 0; uint8_t checked = 0; uint8_t buf[1500]; //------------------------------------------------------- // if( pRxTCP_HEAD != pRxTCP_TAIL ) { for(j=0;j<sizeof(bufferTxTCP);j++) { checkTcpBufferPointers(); buf[0] = *(pRxTCP_TAIL++); if( pRxTCP_HEAD == pRxTCP_TAIL ) break; checkTcpBufferPointers(); buf[1] = *(pRxTCP_TAIL++); if( pRxTCP_HEAD == pRxTCP_TAIL ) break; checkTcpBufferPointers(); buf[2] = *(pRxTCP_TAIL++); if( pRxTCP_HEAD == pRxTCP_TAIL ) break; checkTcpBufferPointers(); if( pRxTCP_HEAD == pRxTCP_TAIL ) break; if( ( buf[0] == 'S' )&& ( buf[1] == 'T' )&& ( buf[2] == 'X' ) ) { checkTcpBufferPointers(); buf[3] = *(pRxTCP_TAIL++); if( pRxTCP_HEAD == pRxTCP_TAIL ) break; checkTcpBufferPointers(); buf[4] = *(pRxTCP_TAIL++); if( pRxTCP_HEAD == pRxTCP_TAIL ) break; len = (buf[3]<<8) + buf[4]; if( len > 1500 ) break; for(i=5;i<(len + 8 );i++) { checkTcpBufferPointers(); buf[i] = *(pRxTCP_TAIL++); if( pRxTCP_HEAD == pRxTCP_TAIL ) break; } checked = 1; } if(( pRxTCP_TAIL == pRxTCP_HEAD )||( checked )) { break; // sai do for } } checkTcpBufferPointers(); if( checked ) { #ifdef __COMANDS appCommand( &buf[5], len, TCP_SERVER_PORT ); #endif } } } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ void checkTcpBufferPointers( void ) { if(( pTxTCP_TAIL >= (bufferTxTCP + sizeof(bufferTxTCP)))||( pTxTCP_TAIL < bufferTxTCP ) ) pTxTCP_TAIL = bufferTxTCP; if(( pTxTCP_HEAD >= (bufferTxTCP + sizeof(bufferTxTCP)))||( pTxTCP_HEAD < bufferTxTCP ) ) pTxTCP_HEAD = bufferTxTCP; if(( pRxTCP_TAIL >= (bufferRxTCP + sizeof(bufferRxTCP)))||( pRxTCP_TAIL < bufferRxTCP ) ) pRxTCP_TAIL = bufferRxTCP; if(( pRxTCP_HEAD >= (bufferRxTCP + sizeof(bufferRxTCP)))||( pRxTCP_HEAD < bufferRxTCP ) ) pRxTCP_HEAD = bufferRxTCP; } //------------------------------------------------------------------------------------------------------------------------ // // // // Parametros: // Retorno: //------------------------------------------------------------------------------------------------------------------------ /*uint16_t checkTcpMsgToSend( uint8_t *buf ) { volatile uint16_t len = 0; volatile uint16_t i,j; volatile uint8_t checked; //------------------------------------------------------- // check for msgs to send if( pTxTCP_HEAD != pTxTCP_TAIL ) { i = 0; checked = 0; for(j=0;j<sizeof(bufferTxTCP);j++) { checkTcpBufferPointers(); buf[0] = *(pTxTCP_TAIL++); if( pTxTCP_HEAD == pTxTCP_TAIL ) break; checkTcpBufferPointers(); buf[1] = *(pTxTCP_TAIL++); if( pTxTCP_HEAD == pTxTCP_TAIL ) break; checkTcpBufferPointers(); buf[2] = *(pTxTCP_TAIL++); if( pTxTCP_HEAD == pTxTCP_TAIL ) break; checkTcpBufferPointers(); if( pTxTCP_HEAD == pTxTCP_TAIL ) break; if(( buf[0] == 'S' )&&( buf[1] == 'T' )&&( buf[2] == 'X' )) { checkTcpBufferPointers(); buf[3] = *(pTxTCP_TAIL++); if( pTxTCP_HEAD == pTxTCP_TAIL ) break; checkTcpBufferPointers(); buf[4] = *(pTxTCP_TAIL++); if( pTxTCP_HEAD == pTxTCP_TAIL ) break; len = (buf[3]<<8) + buf[4]; if( len > 1500 ) break; // for(j=0;... for(i=5;i<(len + 8 );i++) { checkTcpBufferPointers(); buf[i] = *(pTxTCP_TAIL++); if( pTxTCP_HEAD == pTxTCP_TAIL ) break; // for(j=0;... } checked = 1; len += 8; } if(( checked )||( pTxTCP_TAIL == pTxTCP_HEAD )) break; // for(j=0;... }// for(j=0;j<sizeof(bufferTxTCP);j++) } checkTcpBufferPointers(); return len; }*/ /* USER CODE BEGIN (4) */ /* USER CODE END */
Please Help me to solve this.
Thank you
Basavanagouda G.