Part Number: AM3358
Other Parts Discussed in Thread: SYSBIOS
Tool/software: TI-RTOS
Good day,
I have taken the example program "NIMU_BasicExample_bbbAM335x_armExampleproject" and trimmed it down so I send myself a nice "hello" over TCP port 7 and it works great.
I have a separate program running that I am reading sensor data off of the SPI1 bus based on the "MCSPI_SlaveMode_MasterExample_bbbAM335x_armExampleProject" and that works great.
I am running into issues when trying to integrate what is working in my NIMU example into my SPI example.
I actually have the combined project compiling without warning or error and it downloads to by BBB. The issue is that when it tries to run, it says that it can't open the socket and the whole thing crashes. I have actually taken all of my networking code out of the program and the program still crashes.
Here is my working NIMU code for reference and what I tried to put in my SPI code:
/*
* Copyright (C) 2015 Texas Instruments Incorporated - http://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.
*
*/
/* ========================================================================== */
/* Include Files */
/* ========================================================================== */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/family/arm/a8/Mmu.h>
#include <ti/ndk/inc/stkmain.h>
#include <ti/drv/emac/emac_drv.h>
#include <ti/drv/emac/src/v4/emac_drv_v4.h>
#include <ti/starterware/include/types.h>
#include <ti/starterware/include/hw/hw_types.h>
#include <ti/starterware/include/hw/hw_control_am335x.h>
#include <ti/starterware/include/hw/soc_am335x.h>
#include <ti/starterware/include/ethernet.h>
#include <ti/starterware/include/soc_control.h>
#include <ti/board/board.h>
/* UART Header files */
#include <ti/drv/uart/UART.h>
#include <ti/drv/uart/UART_stdio.h>
#include <ti/ndk/inc/nettools/inc/inet.h>
extern char *LocalIPAddr;
/* Enable the below macro to have prints on the IO Console */
//#define IO_CONSOLE
#ifndef IO_CONSOLE
#define NIMU_log UART_printf
#else
#define NIMU_log printf
#endif
/* ========================================================================== */
/* Macros */
/* ========================================================================== */
/**Phy address of the CPSW port 1*/
#define EMAC_CPSW_PORT0_PHY_ADDR_EVM 0
/**Phy address of the CPSW port 1*/
#define EMAC_CPSW_PORT1_PHY_ADDR_EVM 1
#define MAX_TABLE_ENTRIES 3
/* ========================================================================== */
/* Global Variables */
/* ========================================================================== */
/**Task handle for EIP*/
Task_Handle main_task;
static int nimu_device_index = 0U;
NIMU_DEVICE_TABLE_ENTRY NIMUDeviceTable[MAX_TABLE_ENTRIES];
void TaskFxn(UArg a0, UArg a1);
extern int CpswEmacInit (STKEVENT_Handle hEvent);
/**
* \name main
* \brief Main Function
* \param none
* \return none
*
*/
int main()
{
/* Call board init functions */
Board_initCfg boardCfg;
Task_Params taskParams;
EMAC_HwAttrs_V4 cfg;
boardCfg = BOARD_INIT_PINMUX_CONFIG |
BOARD_INIT_MODULE_CLOCK | BOARD_INIT_UART_STDIO;
Board_init(boardCfg);
/* Chip configuration MII/RMII selection */
SOCCtrlCpswPortMacModeSelect(1, ETHERNET_MAC_TYPE_MII);
SOCCtrlCpswPortMacModeSelect(2, ETHERNET_MAC_TYPE_MII);
EMAC_socGetInitCfg(0, &cfg);
cfg.port[0].phy_addr = EMAC_CPSW_PORT0_PHY_ADDR_EVM;
cfg.port[1].phy_addr = EMAC_CPSW_PORT0_PHY_ADDR_EVM;
cfg.macModeFlags = EMAC_CPSW_CONFIG_MODEFLG_FULLDUPLEX;
EMAC_socSetInitCfg(0, &cfg);
Task_Params_init(&taskParams);
taskParams.priority = 1;
taskParams.stackSize = 0x1400;
main_task = Task_create (TaskFxn, &taskParams, NULL);
NIMUDeviceTable[nimu_device_index++].init = &CpswEmacInit ;
NIMUDeviceTable[nimu_device_index].init = NULL ;
BIOS_start();
return -1;
}
/**
* \name TaskFxn
* \brief Task which do EIP initialization
* \param a0
* \param a1
* \return none
*
*/
void TaskFxn(UArg a0, UArg a1)
{
NIMU_log("\n\rSYS/BIOS Ethernet/IP (CPSW) Sample application, EVM IP address: %s\n\r", LocalIPAddr);
SOCKET s = INVALID_SOCKET;
struct sockaddr_in sin1;
char *pBuf = 0;
struct timeval timeout;
// Allocate the file descriptor environment for this Task
fdOpenSession( (HANDLE)Task_self() );
printf("\n== Start TCP Echo Client Test ==\n");
// Create test socket
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if( s == INVALID_SOCKET )
{
printf("failed socket create (%d)\n",fdError());
goto leave;
}
else{
printf("created socket\n");
}
char *IPAddr = "192.168.1.6";
// Prepare address for connect
bzero( &sin1, sizeof(struct sockaddr_in) );
sin1.sin_family = AF_INET;
sin1.sin_addr.s_addr = inet_addr(IPAddr);
sin1.sin_port = htons(7);
// Configure our Tx and Rx timeout to be 5 seconds
timeout.tv_sec = 5;
timeout.tv_usec = 0;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );
// Connect socket
if( connect( s, (PSA) &sin1, sizeof(sin1) ) < 0 )
{
printf("failed connect (%d)\n",fdError());
goto leave;
}
else{
printf("connected\n");
}
// Allocate a working buffer
if( !(pBuf = malloc( 4096 )) )
{
printf("failed temp buffer allocation\n");
goto leave;
}
// Fill buffer with a test pattern
// for(i=0; i<4096; i++)
*(pBuf+0) = (char)'h';
*(pBuf+1) = (char)'e';
*(pBuf+2) = (char)'l';
*(pBuf+3) = (char)'l';
*(pBuf+4) = (char)'o';
// Send the buffer
if( send( s, pBuf, 5, 0 ) < 0 )
{
printf("send failed (%d)\n",fdError());
goto leave;
}
else{
printf("sent\n");
}
leave:
if( pBuf )
free( pBuf );
if( s != INVALID_SOCKET )
fdClose( s );
printf("== End TCP Echo Client Test ==\n\n");
// Free the file descriptor environment for this Task
fdCloseSession( (HANDLE)Task_self() );
#ifdef NIMU_FTP_APP
ftpserver_init();
#endif
}