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.

RM57L843: lwIP and RTI interference?

Part Number: RM57L843


Dear TI,

I have a problem with lwIP. I'm using noSys environment and RawAPI and created a listening PCB on the microcontroller. I try to light up status LEDs - it works. After then, I try to periodically (per sec) measure temperature with an NTC - it works, too, but in this case I can no longer connect to the mcu via ethernet (TCP/IP), but I managed to debug it through without ethernet connection and it works. That's why I think that the RTI module causes the problem.

After then, I did some research and tried to create an active connection, where the controller sends back to the computer the temperature data periodically, per sec or ten seconds. Now, after this, I can't even debug it.  I tried to connect to it with NCat, it worked in the first case, but the second and third case (with RTI active the second case, and with active connection, too, the third case), it just sends back a dot (.).

What could be the problem? I guess, it's with the RTI, until I active it, everything works just fine. I attach the codes. My project is based on the Minimal lwIP implementation project 

Thanks for your help in advance.

Regards,

Zsolt

HL_sys_main.c:

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
#include "HL_system.h"
#include "HL_gio.h"
#include "HL_emac.h"
#include "HL_esm.h"
#include "lwiplib.h"
#include "HL_het.h"
#include "HL_reg_het.h"
#include "HL_adc.h"
#include "HL_rti.h"


#include "HL_sci.h"

extern void EMAC_LwIP_Main (uint8_t * emacAddress);

/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

uint8    emacAddress[6U] =     {0x11U, 0x22U, 0x33U, 0x44U, 0x55U, 0x66U};
uint32     emacPhyAddress    =    1U;

int main(void)
{
/* USER CODE BEGIN (3) */
    esmInit();
    gioInit();
    hetInit();

    gioSetDirection(hetPORT1,0xFFFFFFFF);


    EMACHWInit(emacAddress);


    EMAC_LwIP_Main(emacAddress);

    while(1);

/* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */


/* USER CODE END */

lwip_functions.c:

/*
 * lwip_functions.c
 */


/*
** Interrupt Handler for Core 0 Receive interrupt
*/

/*
** lwIP Compile Time Options for HDK.
*/
#include "lwiplib.h"
#include "HL_sci.h"
#include "lwip\inet.h"
#include "locator.h"
#include "lwip\tcp.h"
#include "lwip/tcp_impl.h"
#include "lwip\timers.h"
#include "HL_adc.h"
#include "HL_rti.h"

#include "modules.h"


#define sciREGx  sciREG1

uint8_t    txtCRLF[]      = {'\r', '\n'};
uint8_t    txtErrorInit[]    = {"-------- ERROR INITIALIZING HARDWARE --------"};
uint8_t    txtIPAddrTxt[]    = {"Device IP Address: "};
uint8_t     * txtIPAddrItoA;


uint8_t seconds = 0, tenseconds = 0;
double temperature = 0;
char buffer[30];
struct tcp_pcb *apcb;


err_t recv_callback(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) {

    int i = 0, j = 0, number = 0, multiplier = 1, processedata[4];
    char *data, *step, *begin;

    if (err == ERR_OK && p != NULL) {

        tcp_recved(pcb, p->tot_len);
        data = (char *)(p->payload);



        readata(data, processedata);

        StatusLED1(processedata);
        StatusLED2(processedata);
        StatusLED3(processedata);
        StatusLED4(processedata);


        pbuf_free(p);
    }

     else {

            pbuf_free(p);
        }

    return ERR_OK;
}



/* Accept an incoming call on the registered port */
err_t accept_callback(void *arg, struct tcp_pcb *npcb, err_t err) {
    LWIP_UNUSED_ARG(arg);
    /* Subscribe a receive callback function */
    tcp_recv(npcb, &recv_callback);
    /* Don't panic! Everything is fine. */
    return ERR_OK;
}




err_t connected_callback(void *arg, struct tcp_pcb *npcb, err_t err) {
    LWIP_UNUSED_ARG(arg);

    if (tcp_write(apcb, "Connection Successful", strlen("Connection Successful"), 1) == ERR_OK) {
                tcp_output(apcb);

    return ERR_OK;
}
}











































volatile int countEMACCore0RxIsr = 0;
#pragma INTERRUPT(EMACCore0RxIsr, IRQ)
void EMACCore0RxIsr(void)
{
    countEMACCore0RxIsr++;
    lwIPRxIntHandler(0);
}

/*
** Interrupt Handler for Core 0 Transmit interrupt
*/
volatile int countEMACCore0TxIsr = 0;
#pragma INTERRUPT(EMACCore0TxIsr, IRQ)
void EMACCore0TxIsr(void)
{
  countEMACCore0TxIsr++;
    lwIPTxIntHandler(0);
}

void IntMasterIRQEnable(void)
{
  _enable_IRQ();
  return;
}

void IntMasterIRQDisable(void)
{
  _disable_IRQ();
  return;
}

unsigned int IntMasterStatusGet(void)
{
    return (0xC0 & _get_CPSR());
}

void sciDisplayText(sciBASE_t *sci, uint8_t *text,uint32_t length)
{
    while(length--)
    {
        while ((sci->FLR & 0x4) == 4); /* wait until busy */
        sciSendByte(sci,*text++);      /* send out text   */
    };
}

void EMAC_LwIP_Main (uint8_t * macAddress)
{
    unsigned int   ipAddr;
    struct in_addr   devIPAddress;

    ip_addr_t connIPAddress;
    struct tcp_pcb *pcb;
    err_t err;

  sciInit();

  /* Enable the interrupt generation in CPSR register */
  IntMasterIRQEnable();
  _enable_FIQ();


  /* Initialze the lwIP library, using DHCP.*/

  ipAddr = lwIPInit(0, macAddress, 0xC0A80199, 0xFFFFFF00, 0, IPADDR_USE_STATIC);

  if (0 == ipAddr) {
    sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
        sciDisplayText(sciREGx, txtErrorInit, sizeof(txtErrorInit));
        sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
        sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
  } else {
    /* Convert IP Address to string */
    devIPAddress.s_addr = ipAddr;
    txtIPAddrItoA = (uint8_t *)inet_ntoa(devIPAddress);
    sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    sciDisplayText(sciREGx, txtIPAddrTxt, sizeof(txtIPAddrTxt));
        sciDisplayText(sciREGx, txtIPAddrItoA, 16);
    sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));


    connIPAddress.addr = ipAddr;




    pcb = tcp_new();

    if (tcp_bind(pcb, IP_ADDR_ANY, 21) == ERR_OK) {
            pcb = tcp_listen(pcb);
            tcp_accept(pcb, &accept_callback);
        }

    apcb = tcp_new();
    if(tcp_bind(apcb, IP_ADDR_ANY, 904) == ERR_OK){
            tcp_connect(apcb, 0xC0A80102, 904, &connected_callback);
    }


    rtiInit();
    adcInit();

    _enable_IRQ_interrupt_();

    adcCalibration(adcREG1);
    adcMidPointCalibration(adcREG1);

    rtiEnableNotification(rtiREG1,rtiNOTIFICATION_COMPARE0);
    rtiStartCounter(rtiREG1,rtiCOUNTER_BLOCK0);





       /* Loop forever.  All the work is done in interrupt handlers. */
      while(1)
      {
          sys_check_timeouts();



      }
  }
}



void rtiNotification(rtiBASE_t *rtiREG, uint32 notification)
{

temperature = ntcs();
seconds++;

if (seconds == 10) {
    if (tcp_write(apcb, &temperature, sizeof(temperature), 1) == ERR_OK) tcp_output(apcb);
    seconds = 0;
}




}



  • Hello Zsoft,

    lwip_init() calls the emac init function, so you don't need to call the similar function to init EMAC/MDIO one more time:

    EMACHWInit(emacAddress);
  • I took it out, but the problem persists; I debugged it and it seems that the tcp_connect() connect_callback() function isn't get called, but the debug works, the RTI works, and I can connect to the controller when it is in listening state from the computer. When I try to connect to the computer from the controller occurs the problem, the computer is in listening state at the 904 port but receives nothing. The apcb shows that it's in SYN_SENT state, but inspecting the dataflow with Wireshark, there is nothing that gets sent to the computer.
    I've read about it in the lwIP forums and the problem occured sometimes, but it's connected to the controller and not the lwIP (unless it's an lwIP bug or I did something wrong).

    Any ideas?

    Thanks in advance.

    Best regards,

    Zsolt Nagy
  • Hello Zsoft,

    The pcb might not be created correctly. If memory is not available for creating the new pcb, NULL is returned. You can check the pcb to make sure the pcb is created without any error:
    if (pcb != NULL) {
    error = tcp_bind(pcb, IP_ADDR_ANY, PORT1);
    }

    If another connection is bound to the same port, the function will return ERR_USE, otherwise ERR_OK is returned. In this case, you need to free the socket first by calling tcp_close().