大家好,最近一直在搞以太网通信,移植了Lwip,物理连接成功了,读写PHY寄存器也是对的,但就是ping不同,后来发现是发不出数据导致的,想来咨询下大家,硬件如下连接如下(PHY是KSZ8041NLI,MII连接):
(物理连接:ETH_MDIO:PA2 ETH_MDC : PC1 ETH_MII_RXD2 : PB0 ETH_MII_RXD3: PB1 ETH_MII_TX_CLK: PC3 ETH_MII_TXD2: PC2 ETH_MII_TXD3 : PB8 ETH_MII_RX_CLK: PA1 ETH_MII_RX_DV : PA7 ETH_MII_RXD0 : PC4 ETH_MII_RXD1 : PC5 ETH_MII_TX_EN :PB11 ETH_MII_TXD0 :PB12 ETH_MII_TXD1 : PB13 )
PHY的地址映射如下(其中0x00和0x01控制和状态寄存器的定义和STM32Cube_FW_F7_V1.4.0例程中的PHY地址相同,其他的中断地址不一样,我在软件中删除掉了中断的配置部分。):
主要软件代码如下:
以太网配置:
void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOs clocks */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
/* Ethernet pins configuration ************************************************/
/*
ETH_MDIO -------------------------> PA2
ETH_MDC --------------------------> PC1
ETH_MII_RXD2 ---------------------> PB0
ETH_MII_RXD3 ---------------------> PB1
ETH_MII_TX_CLK -------------------> PC3
ETH_MII_TXD2 ---------------------> PC2
ETH_MII_TXD3 ---------------------> PB8
ETH_MII_RX_CLK -------------------> PA1
ETH_MII_RX_DV --------------------> PA7
ETH_MII_RXD0 ---------------------> PC4
ETH_MII_RXD1 ---------------------> PC5
ETH_MII_TX_EN --------------------> PB11
ETH_MII_TXD0 ---------------------> PB12
ETH_MII_TXD1 ---------------------> PB13
*/
/* Configure PA1, PA2 and PA7 */
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
GPIO_InitStructure.Pin = (GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7);
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Note : ETH_MDIO is connected to PA2 which is shared with other signals like SAI2_SCKB.
By default on STM32756G-EVAL board, PA2 is connected to SAI2_SCKB, so to connect PA2 to ETH_MDIO :
- unsolder bridge SB24 (SAI2_CKB)
- solder bridge SB5 (ETH_MDIO) */
/* Configure PB0, PB1, PB8, PB11, PB12, PB13 */
GPIO_InitStructure.Pin = (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13);//GPIO_PIN_5;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Enable ETHERNET clock */
__HAL_RCC_ETH_CLK_ENABLE();
}
main函数配置如下:
void main()
{
MPU_Config();
Cache_Enable();
HAL_Init();
SystemClock_Config();
delay_init(200);
lwip_init();
Netif_Config();
udp_echoclient_connect();
User_notification(&gnetif);
while(1)
{
ethernetif_input(&gnetif);
sys_check_timeouts();
}
}
目前是能接收到电脑发过来的ARP数据的,在low_level_input()函数中能打印出接收到的完整APR数据,证明ETH接收完全没有问题,但就是发送不出去,而在low_level_output()中打印出了lwip组的报文,报文也没有错误,但是调用HAL_ETH_TransmitFrame()之后,就发送不出去了,示波器测量外围TX【0-4】只能收到类似于MAC帧报头,还不确定是什么导致以太网发送不出数据的,希望遇到类似情况的朋友,能指点一二
【In MII mode, if a collision occurs at any time from the beginning of the frame to the end of
the CRC field, the MAC sends a 32-bit jam pattern of 0x5555 5555 on the MII to inform all
other stations that a collision has occurred. If the collision is seen during the preamble
transmission phase, the MAC completes the transmission of the preamble and SFD and
then sends the jam pattern.】
解决方法:暂时我们软件关掉了自动协商功能,使用100M,全双工配置,下一步在考虑更改硬件设计。
一周热门 更多>