CH579芯片,因为只是使用简单的网络传输,不想用官方的LIB库,只需要抓取ETH贞数据,自己写网络协议。
但初始化网络一直不成功,进不了中断,望提供协助。
如果有官方例子,麻烦发一份: 个人信息保护,已隐藏
以下是我的测试代码
#include "CH57x_common.h"
__align(4) UINT8 eth_dma_tx_buf[1500];
__align(4) UINT8 eth_dma_rx_buf[1500];
void ch579_eth_init(uint8_t *mac_addr)
{
printf("init eth\n");
//进入安全访问模式
R8_SAFE_ACCESS_SIG = 0x57;
R8_SAFE_ACCESS_SIG = 0xA8;
//打开以太网时钟
R8_SLP_CLK_OFF1 &= (~RB_SLP_CLK_ETH);
//打开以太网电源
R8_SLP_POWER_CTRL &= (~RB_SLP_ETH_PWR_DN);
//退出安全访问模式
R8_SAFE_ACCESS_SIG = 0x00;
//使能ETH管脚
R16_PIN_ANALOG_IE |= RB_PIN_ETH_IE;
//中断使能寄存器,该开的都开吧
R8_ETH_EIE = RB_ETH_EIE_INTIE | RB_ETH_EIE_RXIE | RB_ETH_EIE_LINKIE \
| RB_ETH_EIE_TXIE | RB_ETH_EIE_R_EN50 | RB_ETH_EIE_TXERIE | RB_ETH_EIE_RXERIE;
R8_ETH_EIR = 0xFF; //清除中断标志
R8_ETH_ESTAT = RB_ETH_ESTAT_INT | RB_ETH_ESTAT_BUFER;//清除状态
//收发模块复位
R8_ETH_ECON1 |= RB_ETH_ECON1_TXRST | RB_ETH_ECON1_RXRST;
R8_ETH_ECON1 &= ~(RB_ETH_ECON1_TXRST | RB_ETH_ECON1_RXRST);
R32_ETH_MACON = 0;
R8_ETH_MACON1 |= RB_ETH_MACON1_MARXEN;//MAC接收使能
R8_ETH_MACON2 &= 0x1F;
R8_ETH_MACON2 |= 0x20;
R8_ETH_MACON2 |= RB_ETH_MACON2_TXCRCEN;//硬件填充CRC
R8_ETH_MACON2 &= ~RB_ETH_MACON2_HFRMEN;//不接收巨型帧
R8_ETH_MACON2 |= RB_ETH_MACON2_FULDPX;//全双工
R16_ETH_MAMXFL = 1500; //MTU=1500=0x05DC 最大包长
//MAC 注意字节顺序
R16_ETH_MAADRH = macaddr[0] << 8 | macaddr[1];
R32_ETH_MAADRL = macaddr[2] << 24 | macaddr[3] << 16 | macaddr[4] << 8 | macaddr[5];
//DMA buffers
R16_ETH_ETXST = (uint32_t)eth_dma_tx_buf;
R16_ETH_ERXST = (uint32_t)eth_dma_rx_buf;
//使能接收
R8_ETH_ECON1 |= RB_ETH_ECON1_RXEN;//接收使能
//开启中断
NVIC_EnableIRQ(ETH_IRQn);
printf("init eth end!\n");
}
//------------------------------------------------------------
void ETH_IRQHandler(void) // 以太网中断
{
printf("I");
//接收到数据包
if ((R8_ETH_EIR & RB_ETH_EIR_RXIF) != 0)
{
printf("Get data\n");
R8_ETH_EIR |= RB_ETH_EIR_RXIF; //写1 清除中断
}
//接收错误
if ((R8_ETH_EIR & RB_ETH_EIE_RXERIE) != 0)
{
printf("Get error\n");
R8_ETH_EIR |= RB_ETH_EIE_RXERIE; //清除中断
}
//发送完成
if ((R8_ETH_EIR & RB_ETH_EIR_TXIF) != 0)
{
printf("send\n");
R8_ETH_EIR |= RB_ETH_EIR_TXIF; //清除中断
}
//发送错误
if ((R8_ETH_EIR & RB_ETH_EIE_TXERIE) != 0)
{
printf("send error\n");
R8_ETH_EIR |= RB_ETH_EIE_TXERIE; //清除中断
}
//Link 变化标志
if ((R8_ETH_EIR & RB_ETH_EIR_LINKIF) != 0)
{
printf("link..\n");
R8_ETH_EIR |= RB_ETH_EIR_LINKIF; //清除中断
}
}
//-----------------------------------------------------------
int main()
{
//--LAN LED灯使用-------
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA); //LAN_CONN_LED
GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA); //LAN_DATA_LED
GPIOB_ResetBits(GPIO_Pin_4);
GPIOB_ResetBits(GPIO_Pin_7);
//-----------------------------------------
//--UART1:printf -------------------------
GPIOA_SetBits(GPIO_Pin_9); //PA9=TX1 = printf
GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU); //PA8=RX1, RXD-配置上拉输入
GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
UART1_DefInit();
//-----------------------------------------
UINT8 mac_addr[] = { 0x00, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
ch579_eth_init(mac_addr);
while(1)
{
mDelaymS( 100 ); //100ms
GPIOB_InverseBits(GPIO_Pin_0); //LED翻转 测试
};
}