Part Number: AM4379
Other Parts Discussed in Thread: SYSBIOS
Tool/software: TI-RTOS
I'm trying to get BSD sockets running on the AM437x IDK eval board. Using the Standard EMAC, not the PRUs. I have implemented initialization routines in the same way as the PDK examples. I am able to create a socket, but a call to Connect() hangs and never returns. I have verified my listening socket application is working using both WinSock and BSD sockets on linux. I will post my simple code and my .cfg file below. Any suggestions would be much appreciated.
I'm using the following toolsets
GCC BNU v4.9.3 (linaro)
XDC 3.32.2.25_core
NDK 2.25.1.11
Sys/BIOS 6.46.5.55
am437x PDK 1.0.7
// Here is the C code
int TCPTest()
{
fdOpenSession(TaskSelf());
// Create listener
SOCKET sockTest = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockTest == INVALID_SOCKET)
return -1;
struct sockaddr_in sin1;
memset(&sin1, 0, sizeof(struct sockaddr_in) );
sin1.sin_family = AF_INET;
sin1.sin_port = htons(2222);
sin1.sin_addr.s_addr = inet_addr("192.168.2.113");
// int trueFlag = 1;
// if (setsockopt(sockTest, SOL_SOCKET, SO_REUSEADDR, &trueFlag, sizeof(int)) == -1)
// {
// System_printf("SetSockOpt Failure %d \n\n", errno);
// }
int result = connect(sockTest, (struct sockaddr *) &sin1, sizeof(sin1));
if (result < 0)
{
int errCode = fdError();
System_printf("Unable to connect (%d)\n", errCode);
fdCloseSession(TaskSelf());
return -1;
}
// Receive some data
unsigned char buffer[256+1];
int numBytes = recv(sockTest, buffer, 256, 0);
if (numBytes > 0)
{
buffer[numBytes] = 0; // null terminator
System_printf((const char*) buffer);
}
fdCloseSession(TaskSelf());
return 0;
}
/*
* ======== taskFxn ========
*/
Void taskFxn(UArg a0, UArg a1)
{
// Test the NDK
TCPTest();
}
/*
* ======== main ========
*/
Int main()
{
Task_Handle task;
Task_Params taskParams;
Error_Block eb;
/* Memory module */
SDKMMUInit();
// Init the IDK board
//Board_initCfg cfg = BOARD_INIT_UART_STDIO | BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_MODULE_CLOCK | BOARD_INIT_ETH_PHY ;
Board_initCfg cfg = BOARD_INIT_UART_STDIO | BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_MODULE_CLOCK;
Board_STATUS boardInitStatus = Board_init(cfg);
if (boardInitStatus !=0)
{
System_printf("Board_init failure\n");
return(-1);
}
/* Chip configuration MII/RMII selection */
CpswPortMacModeSelect(1, ETHERNET_MAC_TYPE_RGMII);
CpswPortMacModeSelect(2, ETHERNET_MAC_TYPE_RGMII);
Error_init(&eb);
Task_Params_init(&taskParams);
taskParams.priority = OS_TASKPRINORM;
taskParams.stackSize = 0x2000;
task = Task_create(taskFxn, &taskParams, &eb);
if (task == NULL) {
System_printf("Task_create() failed!\n");
BIOS_exit(0);
}
// NIMU Device table - attach CPSW Emac
NIMUDeviceTable[nimu_device_index++].init = &CpswEmacInit;
NIMUDeviceTable[nimu_device_index].init = NULL;
BIOS_start(); /* does not return */
return(0);
}
///////////////////////////////////////////////////
// The .cfg is as follows
/* use modules */
var Defaults = xdc.useModule('xdc.runtime.Defaults');
var Diags = xdc.useModule('xdc.runtime.Diags');
var Error = xdc.useModule('xdc.runtime.Error');
var Log = xdc.useModule('xdc.runtime.Log');
var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
var Main = xdc.useModule('xdc.runtime.Main');
var Memory = xdc.useModule('xdc.runtime.Memory')
var SysMin = xdc.useModule('xdc.runtime.SysMin');
var System = xdc.useModule('xdc.runtime.System');
var Text = xdc.useModule('xdc.runtime.Text');
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
var Swi = xdc.useModule('ti.sysbios.knl.Swi');
var Task = xdc.useModule('ti.sysbios.knl.Task');
var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
var ti_sysbios_hal_Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
var SysMin = xdc.useModule('xdc.runtime.SysMin');
// NDK
var Global = xdc.useModule('ti.ndk.config.Global');
var Ip = xdc.useModule('ti.ndk.config.Ip');
var Tcp = xdc.useModule('ti.ndk.config.Tcp');
var Udp = xdc.useModule('ti.ndk.config.Udp');
var Route = xdc.useModule('ti.ndk.config.Route');
//var ti_ndk_config_Emac = xdc.useModule('ti.ndk.config.Emac');
/*
* Uncomment this line to globally disable Asserts.
* All modules inherit the default from the 'Defaults' module. You
* can override these defaults on a per-module basis using Module.common$.
* Disabling Asserts will save code space and improve runtime performance.
Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
*/
/*
* Uncomment this line to keep module names from being loaded on the target.
* The module name strings are placed in the .const section. Setting this
* parameter to false will save space in the .const section. Error and
* Assert messages will contain an "unknown module" prefix instead
* of the actual module name.
Defaults.common$.namedModule = false;
*/
/*
* Minimize exit handler array in System. The System module includes
* an array of functions that are registered with System_atexit() to be
* called by System_exit().
*/
System.maxAtexitHandlers = 4;
/* System stack size (used by ISRs and Swis) */
Program.stack = 0x10000;
/* Circular buffer size for System_printf() */
SysMin.bufSize = 0x200;
/*
* Create and install logger for the whole system
*/
var loggerBufParams = new LoggerBuf.Params();
loggerBufParams.numEntries = 16;
var logger0 = LoggerBuf.create(loggerBufParams);
Defaults.common$.logger = logger0;
Main.common$.diags_INFO = Diags.ALWAYS_ON;
System.SupportProxy = SysMin;
/* ================ BIOS configuration ================ */
var BIOS = xdc.useModule('ti.sysbios.BIOS');
BIOS.libType = BIOS.LibType_Custom;
/*
* The BIOS module will create the default heap for the system.
* Specify the size of this default heap.
*/
BIOS.heapSize = 0xA0000;
Task.defaultStackSize = 4096;
Task.idleTaskStackSize = 4096;
System.SupportProxy = SysMin;
/* Circular buffer size for System_printf() */
SysMin.bufSize = 0x200;
/* NDK Config */
Ip.ResolveIP = false;
Ip.CallByIP = false;
Ip.autoIp = false;
Ip.address = "192.168.2.7";
Ip.mask = "255.255.255.0";
Ip.gatewayIpAddr = "192.168.2.1";
Ip.domainName = "mydomain.net";
//Ip.socketConnectTimeout = 10000;
//Ip.socketConnectTimeout = 1;
Global.ndkTickPeriod = 100;
Global.kernTaskPriLevel = 11;
Global.serviceReportHook = null;
Global.IPv6 = false;
Global.pktNumFrameBufs=384;
Tcp.transmitBufSize = 16384;
Tcp.receiveBufSize = 65536;
Tcp.receiveBufLimit = 65536;
var socType = "am437x";
/* Load the CSL package */
/*use CSL package*/
var Csl = xdc.loadPackage('ti.csl');
Csl.Settings.deviceType = socType;
/* Load the OSAL package */
var osType = "tirtos";
var Osal = xdc.useModule('ti.osal.Settings');
Osal.osType = osType;
/* Load the UART package */
var UART = xdc.loadPackage('ti.drv.uart');
/* Load the I2C package */
var I2C = xdc.loadPackage('ti.drv.i2c');
/* Load the Board package and set the board name */
var Board = xdc.loadPackage('ti.board');
Board.Settings.boardName = "idkAM437x";
/* GPIO */
var Gpio = xdc.loadPackage('ti.drv.gpio');
//var Gpio = xdc.loadPackage('ti.drv.gpio');
//Gpio.Settings.socType = socType;
/* Load the EMAC packages */
var Emac = xdc.loadPackage('ti.drv.emac');
Emac.Settings.socType = socType;
/* Load the NIMU packages */
var Nimu = xdc.loadPackage('ti.transport.ndk.nimu');
Nimu.Settings.socType = socType;
/* Cache & MMU */
var Cache = xdc.useModule('ti.sysbios.family.arm.a9.Cache');
Cache.enableCache = true;
var Mmu = xdc.useModule('ti.sysbios.family.arm.a8.Mmu');
Mmu.enableMMU = true;