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.

TMS320F28388D: Ethernet port configuration on CM Core

Part Number: TMS320F28388D
Other Parts Discussed in Thread: TMDSCNCD28388D, C2000WARE

Tool/software:

Hello Sir,

I have TMDSCNCD28388D control card. I am trying to configure ethernet in CM Core but i am getting error.

My final goal is configure ethernet and add uip library support for Modbus stack implementation. 

when Ethernet_sendPacket function is called it will trigger fault ISR and code goes to halted state.

Please check and let me know if you have any findings in my code.

My initialization code is as per below.


#include <CM_Global_Variable.h>

uint32_t Led_Counter3=0;

#define ETHERNET_BUFFER_SIZE 1536
#define NUM_RX_PKTS 1
// Global Ethernet handle
Ethernet_Handle ethHandle;
extern Ethernet_Device Ethernet_device_struct;

//// 4-byte aligned DMA-safe transmit buffer
//#pragma DATA_ALIGN(txBuf, 4)
//uint8_t txBuf[ETHERNET_BUFFER_SIZE];

// DMA-safe buffers
#pragma DATA_ALIGN(txBuf, 4)
uint8_t txBuf[ETHERNET_BUFFER_SIZE];
#pragma DATA_ALIGN(rxBufMem, 4)
uint8_t rxBufMem[ETHERNET_BUFFER_SIZE];
// MAC Address
uint8_t macAddress[6] = {0x00, 0x1A, 0xB6, 0x03, 0x2B, 0x7E};

// Platform-specific interrupt stubs (for baremetal use)
void dummyEnable(uint32_t num) {}
void dummyDisable(uint32_t num) {}
void dummyReset(uint32_t num) {}
void dummyClockEnable(uint32_t num) {}

// Callback: provide TX/RX packet buffer
//Ethernet_Pkt_Desc* Ethernet_getPacketBuffer(void)
//{
// static Ethernet_Pkt_Desc pkt;
// memset(&pkt, 0, sizeof(pkt));
// pkt.dataBuffer = txBuf;
// pkt.bufferLength = ETHERNET_BUFFER_SIZE;
// pkt.validLength = 0;
// pkt.dataOffset = 0;
// pkt.numPktFrags = 1;
// pkt.pktChannel = 0;
// return &pkt;
//}

void ethernet_init(void)
{
Ethernet_InitInterfaceConfig initCfg;
Ethernet_InitConfig *ethCfg;
uint8_t i=0;
uint16_t phyRegContent=0;
Ethernet_Statistics stats;

GPIO_writePin(108,1);
GPIO_writePin(119,1);

// Enable peripheral clock for Ethernet
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_ENET);

// Set MAC address using dedicated function
// uint32_t macHigh = ((uint32_t)macAddress[5] << 8) | macAddress[4];
// uint32_t macLow = ((uint32_t)macAddress[3] << 24) |
// ((uint32_t)macAddress[2] << 16) |
// ((uint32_t)macAddress[1] << 8) |
// macAddress[0];
// Ethernet_setMACAddr(EMAC_BASE, 0, macHigh, macLow, ETHERNET_DMA_CHANNEL_NUM_0);

// Initialize the Ethernet interface using the low-level driver

initCfg.ssbase = EMAC_SS_BASE;
initCfg.enet_base = EMAC_BASE;
initCfg.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;

// initCfg.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
// initCfg.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initCfg.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initCfg.ptrPlatformPeripheralReset = &Platform_resetPeripheral;

initCfg.clockSel = ETHERNET_SS_CLK_SRC_INTERNAL;
// initCfg.localPhyAddress = 0;
// initCfg.remotePhyAddress = 0;

initCfg.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
// initCfg.ptrPlatformPeripheralEnable = dummyClockEnable;
// initCfg.ptrPlatformPeripheralReset = dummyReset;
// initCfg.ptrPlatformInterruptEnable = dummyEnable;
// initCfg.ptrPlatformInterruptDisable = dummyDisable;
// for (i = 0; i < ETHERNET_NUM_INTERRUPTS; i++)
// {
// initCfg.interruptNum[i] = 0;
// }

initCfg.interruptNum[0] = 0;
initCfg.interruptNum[1] = 0;
initCfg.interruptNum[2] = 0;
initCfg.interruptNum[3] = 0;
initCfg.interruptNum[4] = 0;

ethCfg = Ethernet_initInterface(initCfg);

Ethernet_getInitConfig(ethCfg);

ethCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
ethCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
ethCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
ethCfg->rxBuffer = rxBufMem;

// Create driver handle
Ethernet_getHandle((Ethernet_Handle)1, &ethCfg, &ethHandle);


//*****************Addition as per sample

// (void)Interrupt_enableInProcessor();
// //
// //Assign default ISRs
// //
// Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
// Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
// //
// //Enable the default interrupt handlers
// //
// Interrupt_enable(INT_EMAC_TX0);
// Interrupt_enable(INT_EMAC_RX0);

//
//Low Frequency
//value of 5 for selecting the slowest possible MDIO Clock
//Clause 22 mode
//
Ethernet_configureMDIO(EMAC_BASE,0,5,0);

//
//The DP83822 External PHY in Control Card
//takes a PHY address of 1 by default
//Configure the MDIO module to use PHY address of 0x1
//
Ethernet_configurePHYAddress(EMAC_BASE,1);

//
//Address 0 of PHY corresponds to Basic Mode Control Register(BMCR)
//Read the register to know the state
//
phyRegContent= Ethernet_readPHYRegister(EMAC_BASE,0);

//
//Bit 14 of BMCR configures the MII Loopback
//
phyRegContent |= 0x4000;

Ethernet_writePHYRegister(EMAC_BASE,0,phyRegContent);

//
//Read back the BMCR register to confirm that the MII Loopback
//is configured properly
//
phyRegContent= Ethernet_readPHYRegister(EMAC_BASE,0);

}

void ethernet_send(uint8_t *data, uint16_t length)
{
if (length > ETHERNET_BUFFER_SIZE)
return;

// Copy data to aligned transmit buffer
memcpy(txBuf, data, length);

// Setup packet descriptor
Ethernet_Pkt_Desc txPktDesc;
memset(&txPktDesc, 0, sizeof(txPktDesc));

txPktDesc.bufferLength = length;
txPktDesc.dataOffset = 0;
txPktDesc.dataBuffer = txBuf;
txPktDesc.nextPacketDesc = 0;
txPktDesc.flags = (ETHERNET_PKT_FLAG_SOP | ETHERNET_PKT_FLAG_EOP |
ETHERNET_PKT_FLAG_SA_INS/*ETHERNET_PKT_FLAG_CRC_PAD_INS*/);
txPktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0/*0*/; // Use TX channel 0
txPktDesc.pktLength = length;
txPktDesc.validLength = length;
txPktDesc.numPktFrags = 1;


Ethernet_sendPacket(ethHandle, &txPktDesc);
// uint32_t result = Ethernet_sendPacket(ethHandle, &txPktDesc);
// if (result != ETHERNET_RET_SUCCESS)
// {
// // Handle error (optional)
// }

// pktDesc.bufferLength = PACKET_LENGTH;
// pktDesc.dataOffset = 0;
// pktDesc.dataBuffer = pData;
// pktDesc.nextPacketDesc = 0;
// pktDesc.flags = ETHERNET_PKT_FLAG_SOP |ETHERNET_PKT_FLAG_EOP|ETHERNET_PKT_FLAG_SA_INS;
// pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
// pktDesc.pktLength = PACKET_LENGTH;
// pktDesc.validLength = PACKET_LENGTH;
// pktDesc.numPktFrags = 1;
//
//
// Ethernet_sendPacket(emac_handle,&pktDesc);
}

void send_sample_packet(void)
{
// Create Ethernet frame: broadcast + simple payload
uint8_t frame[100];
uint8_t dest_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t src_mac[6] = {0x00, 0x1A, 0xB6, 0x03, 0x2B, 0x7E};
uint16_t ethertype = 0x0800; // IPv4

int idx = 0;
memcpy(&frame[idx], dest_mac, 6); idx += 6;
memcpy(&frame[idx], src_mac, 6); idx += 6;
frame[idx++] = (ethertype >> 8) & 0xFF;
frame[idx++] = ethertype & 0xFF;

const char *payload = "Hello Ethernet from F28388D!";
int payload_len = strlen(payload);
memcpy(&frame[idx], payload, payload_len);
idx += payload_len;

ethernet_send(frame, idx);
}
int main(void)
{
CM_init();
GPIO_Init();
Timer_Init();
// TCPIP_Init();

ethernet_init();
//SysCtl_delay(1000000); // Wait for PHY link

while (1)
{
if(cpuTimer0IntCount > 2){
send_sample_packet();
cpuTimer0IntCount = 0;
}
// SysCtl_delay(1000000); // 1 second delay (1,000,000 us)
}
}