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.

TM4C1294NCPDT: Problems with manual configuration of DHCP or Static IP

Part Number: TM4C1294NCPDT

Hi all,

  I have used TM4C processor and also my project is running using the XGCONF config for DHCP resolution.

  It works fine, the IP is obtained fast and I have no problems with this approach.

  Now I have a request where I need to implement the support to choose the IP resolution type on demand, I mean, the use can access the configuration panel (Usually, I do the config using sockets or via uart).
  But I am having a problem when trying to set dynamically the DHCP or IPaddress. The NC_NetStart is not working and I don't know how to fix it.

  I am using tcpEcho to try to fix it and, after that, put the solution on my project.

  I am using TI-RTOS 2.16.1.14.

  The error I am getting is the following:

Starting the TCP Echo example
System provider is set to SysMin. Halt the target to view any SysMin contents in ROV.
Service Status: DHCPC : Enabled : : 000
Service Status: DHCPC : Enabled : Running : 000

NetworkConfig Configuracion - Initialization
NC_SystemOpen
CONFIGURANDO DHCP
CfgAddEntry ret = 0
NC_NetStart
.000 ExecStart: Already Open
00000.000 DHCPOpen: NIMUIOCTL (NIMU_GET_DEVICE_MAC) Failed with error code: -22

NetStop Callback
FSR = 0x0000
HFSR = 0x40000000
DFSR = 0x0000000b
MMAR = 0xb280bbf4
BFAR = 0xb280bbf4
AFSR = 0x00000000
Terminating execution...

  And in my file tcpEcho.c, the NetworkConfig()

void netStart() {
	System_printf("NetStart Callback\r\n");
	System_flush();
}

void netStop() {
	System_printf("NetStop Callback\r\n");
	System_flush();
}

void serviceReport(uint a, uint b, uint c, HANDLE cfg) {
	//debug("ServiceReport\r\n");
}

int isDhcp = 1;
UINT8 DHCP_OPTIONS[] = { DHCPOPT_SERVER_IDENTIFIER, DHCPOPT_ROUTER };
void netOpenHook(IPN IPAddr, uint IfIdx, uint fAdd);
int NetworkConfig(void)
{
	int ret;
	CI_IPNET NA;
	CI_ROUTE RT;
	CI_SERVICE_DHCPC dhcpc;
	HANDLE hCfg;

	System_printf("\r\nNetworkConfig Configuracion - Initialization\r\nNC_SystemOpen\r\n");
	System_flush();

	ret = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
	if( ret )
	{
		System_printf("NC_SystemOpen Failed (%d)\n",ret);
		System_flush();
		return -1;
	}

	hCfg = CfgNew();
	if( !hCfg )
	{
		System_printf("Unable to create configuration\n");
		System_flush();
		goto main_exit;
	}


	if (isDhcp) {
		System_printf("CONFIGURANDO DHCP\r\n");

		// Specify DHCP Service on interface 1
		bzero( &dhcpc, sizeof(dhcpc) );
		dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID;
		dhcpc.cisargs.IfIdx = 1;
		dhcpc.cisargs.pCbSrv = &serviceReport;
        dhcpc.param.pOptions = DHCP_OPTIONS;
        dhcpc.param.len = 2;
		ret = CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0, sizeof(dhcpc), (UINT8 *)&dhcpc, 0 );

		System_printf("CfgAddEntry ret = %d\r\n", ret);
		System_flush();

		// Add our hostname
		CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,strlen("remotta"), (UINT8 *)"remotta", 0 );
	}
	else {
		System_printf("CONFIGURANDO STATIC IP\r\n");

		System_printf("Configurando IP e Netmask\r\n");
		System_flush();
		// Manually configure our local IP address
		bzero( &NA, sizeof(NA) );
		NA.IPAddr = inet_addr("192.168.0.10");
		NA.IPMask = inet_addr("255.255.255.0");
		strcpy( NA.Domain, "scientts.com" );
		NA.NetType = 0;
		// Add the address to interface 1
		ret = CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 );

		// Add our hostname
		CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,strlen("equip"), (UINT8 *)"equip", 0 );

		bzero( &RT, sizeof(RT) );
		RT.IPDestAddr = 0;
		RT.IPDestMask = 0;
		RT.IPGateAddr = inet_addr("192.168.0.1");

		// Add the route
		ret = CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0 );
	}

    // TCP Transmit buffer size
    int value = 2048;
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );

    // TCP Receive buffer size (copy mode)
    value = 2048;
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,
                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );

    // TCP Receive limit (non-copy mode)
    value = 2048;
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,
                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );

    // UDP Receive limit
    value = 2048;
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,
                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );

	//
	// Boot the system using this configuration
	//
	// We keep booting until the function returns less than 1. This allows
	// us to have a "reboot" command.
	//
	System_printf("NC_NetStart\r\n");
	System_flush();
	do
	{
		ret = NC_NetStart( hCfg, netStart, netStop, netOpenHook );
	} while( ret > 0 );

	System_printf("NC_NetStart retCode = %d\r\n", ret);

	// Delete Configuration
	CfgFree( hCfg );

	System_printf("NetworkConfig Configuracion - Finishing\r\n");
	System_flush();

	// Close the OS
	main_exit:
		NC_SystemClose();

	return(0);
}



Void startupTask(UArg arg0, UArg arg1) {
	NetworkConfig();
}

The startupTask is called by BIOS, as a Task.

Any clue? I already take a look at several posts but didn't find a way to fix it.

Does anyone has a project tcpEcho with manual configuration to share?

Tks in advance

Leandro

void netStart() { System_printf("NetStart Callback\r\n"); System_flush();}
void netStop() { System_printf("NetStop Callback\r\n"); System_flush();}
void serviceReport(uint a, uint b, uint c, HANDLE cfg) { //debug("ServiceReport\r\n");}
int isDhcp = 1;UINT8 DHCP_OPTIONS[] = { DHCPOPT_SERVER_IDENTIFIER, DHCPOPT_ROUTER };void netOpenHook(IPN IPAddr, uint IfIdx, uint fAdd);int NetworkConfig(void){ int ret; CI_IPNET NA; CI_ROUTE RT; CI_SERVICE_DHCPC dhcpc; HANDLE hCfg;
System_printf("\r\nNetworkConfig Configuracion - Initialization\r\nNC_SystemOpen\r\n"); System_flush();
ret = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT ); if( ret ) { System_printf("NC_SystemOpen Failed (%d)\n",ret); System_flush(); return -1; }
hCfg = CfgNew(); if( !hCfg ) { System_printf("Unable to create configuration\n"); System_flush(); goto main_exit; }

if (isDhcp) { System_printf("CONFIGURANDO DHCP\r\n");
// Specify DHCP Service on interface 1 bzero( &dhcpc, sizeof(dhcpc) ); dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID; dhcpc.cisargs.IfIdx = 1; dhcpc.cisargs.pCbSrv = &serviceReport;        dhcpc.param.pOptions = DHCP_OPTIONS;        dhcpc.param.len = 2; ret = CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0, sizeof(dhcpc), (UINT8 *)&dhcpc, 0 );
System_printf("CfgAddEntry ret = %d\r\n", ret); System_flush();
// Add our hostname CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,strlen("remotta"), (UINT8 *)"remotta", 0 ); } else { System_printf("CONFIGURANDO STATIC IP\r\n");
System_printf("Configurando IP e Netmask\r\n"); System_flush(); // Manually configure our local IP address bzero( &NA, sizeof(NA) ); NA.IPAddr = inet_addr("192.168.0.10"); NA.IPMask = inet_addr("255.255.255.0"); strcpy( NA.Domain, "scientts.com" ); NA.NetType = 0; // Add the address to interface 1 ret = CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 );
// Add our hostname CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,strlen("equip"), (UINT8 *)"equip", 0 );
bzero( &RT, sizeof(RT) ); RT.IPDestAddr = 0; RT.IPDestMask = 0; RT.IPGateAddr = inet_addr("192.168.0.1");
// Add the route ret = CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0 ); }
    // TCP Transmit buffer size    int value = 2048;    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );
    // TCP Receive buffer size (copy mode)    value = 2048;    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );
    // TCP Receive limit (non-copy mode)    value = 2048;    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );
    // UDP Receive limit    value = 2048;    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&value, 0 );
#if 0    // TCP Keep Idle (10 seconds)    rc = 100;    //   This is the time a connection is idle before TCP will probe    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_TCPKEEPIDLE,                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
    // TCP Keep Interval (1 second)    //   This is the time between TCP KEEP probes    rc = 10;    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_TCPKEEPINTVL,                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
    // TCP Max Keep Idle (5 seconds)    //   This is the TCP KEEP will probe before dropping the connection    rc = 50;    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_TCPKEEPMAXIDLE,                 CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );#endif

    CfgSetDefault(hCfg); // // Boot the system using this configuration // // We keep booting until the function returns less than 1. This allows // us to have a "reboot" command. // System_printf("NC_NetStart\r\n"); System_flush(); do { ret = NC_NetStart( hCfg, netStart, netStop, netOpenHook ); } while( ret > 0 );
System_printf("NC_NetStart retCode = %d\r\n", ret);
// Delete Configuration CfgFree( hCfg );
System_printf("NetworkConfig Configuracion - Finishing\r\n"); System_flush();
// Close the OS main_exit: NC_SystemClose();
return(0);}


Void startupTask(UArg arg0, UArg arg1) { NetworkConfig();}

  • Hi Leandro,

    You are missing some items (e.g. creating a Clock Object) in you configuration. I'd use XGCONF to generate the networking stack thread code and then copy it out of the generated source file in Debug\configPkg\package\cfg (e.g tcpEcho_pem4f.c). Search for the ti_ndk_config_Global_stackThread and copy it (and any functions it calls). Note: you might do the same trick for the static IP to see the difference. You should be able to easily add in the isDHCP check.

    Todd
  • Hi Todd,

    As fas as I understand, the tcpEcho_pem4f.c is the generated code based on XGConf parameters, so, the idea is to use this code as a base to my own config.
    Is that right?
    Maybe what I need is just the clock.
    I will take a look and let you know.
    Tks for help

    Leandro
  • Yes, tcpEcho_pem4f.c is the generated code based on XGConf parameters. So you use XGCONF as you have in the past. Copy the code that configures the stack out of tcpEcho_pem4f.c and place it in your own source file. Then remove the XGCONF configuration for the stack (so the code is not generated).