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:CM 内核上的以太网端口配置

Guru**** 2413830 points
Other Parts Discussed in Thread: TMDSCNCD28388D, C2000WARE

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1536497/tms320f28388d-ethernet-port-configuration-on-cm-core

器件型号:TMS320F28388D
主题中讨论的其他器件:TMDSCNCD28388DC2000WARE

工具/软件:

您好、先生、

可以了 TMDSCNCD28388D 控制卡我尝试在 CM Core 中配置以太网、但收到错误消息。

我的最后一个目标是配置以太网并添加 UIP Modbus 堆栈实现的库支持。  

何时  Ethernet_sendPacket 调用函数、它将触发故障 ISR、代码进入暂停状态。

如果您在我的代码中有任何发现、请检查并告知我。

我的初始化代码如下所示。


#include

uint32_t Led_Counter 3=0;

#define ETHERNET_BUFFER_SIZE 1536
#define NUM_RX_Pkts 1
//全局以太网句柄
Ethernet_Handle ethHandle;
extern Ethernet_Device ethernet_device_struct;

//// 4 字节对齐 DMA 安全发送缓冲区
//#pragma DATA_ALIGN (txBuf、4)
//uint8_t txBuf[ethernet_buffer_size];

// DMA 安全缓冲器
pragma DATA_ALIGN (txBuf、4)
uint8_t txBuf[ethernet_buffer_size];
#pragma DATA_ALIGN (rxBufMem、4)
uint8_t rxBufMem[ethernet_buffer_size];
// MAC 地址
Uint8_t macAddress[6]={0x00、0x1A、0xB6、0x03、0x2B、 0x7E};

//特定于平台的中断存根(用于裸机使用)
void dummyEnable (uint32_t num){}
void dummyDisable (uint32_t num){}
void dummyReset (uint32_t num){}
void dummyClockEnable (uint32_t num){}

//回调:提供 TX/RX 数据包缓冲区
// Ethernet_Pkt_Desc * Ethernet_getPacketBuffer (void)
//{
//静态 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;
// pktChannel = 0;
//返回&pkt;
//}

void Ethernet_init (void)

Ethernet_Init 接口配置 initCfg;
Ethernet_Init 配置*ethCfg;
uint8_t i=0;
uint16_t phyRegContent=0;
Ethernet_Statistics 统计数据;

GPIO_writePin (108、1);
GPIO_writePin (119、1);

//为以太网启用外设时钟
SysCtl_enablePeripheral (SYSCTL_PERIPH_CLK_ENET);

//使用专用功能设置 MAC 地址
// 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);

//使用低级驱动程序初始化以太网接口

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;
//用于 (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;

//创建驱动程序句柄
Ethernet_getHandle ((Ethernet_Handle) 1、&ethCfg、&ethHandle);


//***************** 根据样本加法

//(void)Interrupt_enableInProcessor ();
////
////分配默认 ISR
////
// Interrupt_registerHandler (INT_EMAC_TX0、以太网 TransmitISR);
// Interrupt_registerHandler (INT_EMAC_RX0、Ethernet_receiveISR);
////
//启用默认中断处理程序
////
// Interrupt_enable (INT_EMAC_TX0);
// Interrupt_enable (INT_EMAC_RX0);

//
//低频
//值 5、选择尽可能慢的 MDIO 时钟
//第 22 条模式
//
Ethernet_configureMDIO (EMAC_BASE、0、5、0);

//
//控制卡中的 DP83822 外部 PHY
//默认采用的 PHY 地址为 1
//将 MDIO 模块配置为使用 PHY 地址 0x1
//
Ethernet_configurePHYAddress (EMAC_BASE、1);

//
PHY 的//地址 0 对应于基本模式控制寄存器 (BMCR)
//读取寄存器以了解状态
//
phyRegContent= Ethernet_readPHYRegister (EMAC_BASE、0);

//
BMCR 的//位 14 配置 MII 环回
//
phyRegContent || 0x4000;

Ethernet_writePHYRegister (EMAC_BASE、0、phyRegContent);

//
//读回 BMCR 寄存器以确认 MII 环回
//配置正确
//
phyRegContent= Ethernet_readPHYRegister (EMAC_BASE、0);

}

void Ethernet_send(uint8_t *数据、uint16_t 长度)

IF (length > Ethernet_buffer_size)
返回;

//将数据复制到对齐的发送缓冲区
memcpy (txBuf、data、length);

//设置数据包描述符
Ethernet_Pkt_Desc txPktDESC;
memset (&txPktDesc、0、sizeof (txPktDesc));

txPktDESC.bufferLength =长度;
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*/;//使用 TX 通道 0
txPktDESC.pktLength =长度;
txPktDESC.validLength =长度;
txPktDESC.numPktFrags = 1;


Ethernet_sendPacket (ethHandle、&txPktDesc);
// uint32_t result = ethernet_sendPacket (ethHandle、&txPktDesc);
// if (result != ethernet_ret_success)
//{
////处理错误(可选)
//}

// 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)

//创建以太网帧:广播+简单有效载荷
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 *有效载荷=“Hello Ethernet from F28388D!“;
int payload_len = strlen (payload);
memcpy (&frame[idx]、payload、payload_len);
IDX += payload_len;

Ethernet_send(帧,idx);
}
内部 main (void)

cm_init();
GPIO_Init();
Timer_Init ();
// TCPIP_Init();

ethernet_init();
//SysCtl_delay (1000000);//等待 PHY 链路

while (1)

if (cpuTimer0IntCount > 2){
send_sample_packet();
cpuTimer0IntCount = 0;
}
// SysCtl_delay (1000000);// 1 秒延迟 (1,000,000us)
}
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 
     您能分享一下您到底想要实现什么(我是指用例?)吗? 我们已确定此应用中的一些修复、预计将在新版本的 C2000Ware 中推出 (ETA:Augu'25 Mid)。

    此致、
    Pradeep