Other Parts Discussed in Thread: SEGGER, SYSBIOS, UNIFLASH, EK-TM4C1294XL,
Tool/software:
Hello,
I am using the TIRTOS tcpEcho example project. I have a black MCU, which is part of Mikroe's TIVA module (https://www.mikroe.com/mcu-card-3-for-tiva-tm4c129encpdt).
I am using a Segger J-link as an external programmer.
Is there a way to program the MAC in code? I am trying to use EMACAddrSet function. Here is a dump of my tcpEcho.c, and my changes are prefaced by "//NM":
/*
* Copyright (c) 2014-2015, Texas Instruments Incorporated
* All rights reserved.
*
* 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.
*/
/*
* ======== tcpEcho.c ========
* Contains BSD sockets code.
*/
#include <string.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/drivers/GPIO.h>
//NM
#include <driverlib/emac.h>
/* NDK BSD support */
#include <sys/socket.h>
/* Example/Board Header file */
#include "Board.h"
#define TCPPACKETSIZE 256
#define NUMTCPWORKERS 3
/*
* ======== tcpWorker ========
* Task to handle TCP connection. Can be multiple Tasks running
* this function.
*/
Void tcpWorker(UArg arg0, UArg arg1)
{
int clientfd = (int)arg0;
int bytesRcvd;
int bytesSent;
char buffer[TCPPACKETSIZE];
System_printf("tcpWorker: start clientfd = 0x%x\n", clientfd);
while ((bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0)) > 0) {
bytesSent = send(clientfd, buffer, bytesRcvd, 0);
if (bytesSent < 0 || bytesSent != bytesRcvd) {
System_printf("Error: send failed.\n");
break;
}
}
System_printf("tcpWorker stop clientfd = 0x%x\n", clientfd);
close(clientfd);
}
/*
* ======== tcpHandler ========
* Creates new Task to handle new TCP connections.
*/
Void tcpHandler(UArg arg0, UArg arg1)
{
int status;
int clientfd;
int server;
struct sockaddr_in localAddr;
struct sockaddr_in clientAddr;
int optval;
int optlen = sizeof(optval);
socklen_t addrlen = sizeof(clientAddr);
Task_Handle taskHandle;
Task_Params taskParams;
Error_Block eb;
server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (server == -1) {
System_printf("Error: socket not created.\n");
goto shutdown;
}
memset(&localAddr, 0, sizeof(localAddr));
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
localAddr.sin_port = htons(arg0);
status = bind(server, (struct sockaddr *)&localAddr, sizeof(localAddr));
if (status == -1) {
System_printf("Error: bind failed.\n");
goto shutdown;
}
status = listen(server, NUMTCPWORKERS);
if (status == -1) {
System_printf("Error: listen failed.\n");
goto shutdown;
}
optval = 1;
if (setsockopt(server, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) {
System_printf("Error: setsockopt failed\n");
goto shutdown;
}
while ((clientfd =
accept(server, (struct sockaddr *)&clientAddr, &addrlen)) != -1) {
System_printf("tcpHandler: Creating thread clientfd = %d\n", clientfd);
/* Init the Error_Block */
Error_init(&eb);
/* Initialize the defaults and set the parameters. */
Task_Params_init(&taskParams);
taskParams.arg0 = (UArg)clientfd;
taskParams.stackSize = 1280;
taskHandle = Task_create((Task_FuncPtr)tcpWorker, &taskParams, &eb);
if (taskHandle == NULL) {
System_printf("Error: Failed to create new Task\n");
close(clientfd);
}
/* addrlen is a value-result param, must reset for next accept call */
addrlen = sizeof(clientAddr);
}
System_printf("Error: accept failed.\n");
shutdown:
if (server > 0) {
close(server);
}
}
/*
* ======== main ========
*/
int main(void)
{
//NM
static const uint8_t macArray[6] = {0xAC,0xDE,0x48,0x00,0x00,0x80};
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
//NM
EMACAddrSet(0x400EC000,0, macArray);
Board_initEMAC();
System_printf("Starting the TCP Echo example\nSystem provider is set to "
"SysMin. Halt the target to view any SysMin contents in"
" ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* Start BIOS */
BIOS_start();
return (0);
}
These changes result in a compiler error:
"C:/ti/tirtos_tivac_2_16_01_14/products/TivaWare_C_Series-2.1.1.71b/driverlib/emac.h", line 959: error #20: identifier "bool" is undefined
"C:/ti/tirtos_tivac_2_16_01_14/products/TivaWare_C_Series-2.1.1.71b/driverlib/emac.h", line 985: error #20: identifier "bool" is undefined
There must be another way of doing this. Can I change the MAC address through the NDK? Using the XGCONF tool? I notice that TIRTOS has many "wrapper" functions to access TIVAware drivers, and perhaps I need to use one of these instead of accessing this driver function directly.
Thank you!

