stm32f107+dm9161的phy芯片报错eth硬件初始化失败

发布于 2020-08-12 15:36:18

硬件软件配置:

主控芯片:stm32f107VCT6
phy芯片:DM9161AEP
系统版本:4.0.2
LwIP版本:2.0.2

操作的步骤:

①新建 RT-Thread 完整版项目
②board.h中定义 BSP_USING_ETH 和 PHY 相关的宏
③board.c中初始化 ETH 相关的引脚和时钟
④stm32xxxx_hal_config.h中打开 HAL 库函数对 ETH 的支持
⑤board.c 中实现自己的 PHY 复位函数(复位函数为空)
⑥配置 lwIP 协议栈

运行产生错误:
[E/drv.emac] eth hardware init failed

麻烦大佬指定下,感谢感谢!

主要是操作的第③步骤,用stm32cubeMX配置eth的硬件关键生成的HAL_ETH_MspInit如下。

void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(heth->Instance==ETH)
  {
  /* USER CODE BEGIN ETH_MspInit 0 */

  /* USER CODE END ETH_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_ETH_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();
    __HAL_RCC_GPIOD_CLK_ENABLE();
    /**ETH GPIO Configuration
    PC1     ------> ETH_MDC
    PA1     ------> ETH_REF_CLK
    PA2     ------> ETH_MDIO
    PB11     ------> ETH_TX_EN
    PB12     ------> ETH_TXD0
    PB13     ------> ETH_TXD1
    PD8     ------> ETH_CRS_DV
    PD9     ------> ETH_RXD0
    PD10     ------> ETH_RXD1
    */
    GPIO_InitStruct.Pin = GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_2;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
    
    __HAL_AFIO_REMAP_ETH_ENABLE();
  /* USER CODE BEGIN ETH_MspInit 1 */
  /* USER CODE END ETH_MspInit 1 */
  }
}


用stm32cubeMX配置成如下
7c65df3b9bf01be17c143686f3d9fb66.jpg



stm32f107的接线图


stm32.png


DM9161AEP的接线图


DM9161AEp.png

详细的运行log

 \ | /
- RT -     Thread Operating System
 / | \     4.0.2 build Aug 12 2020
 2006 - 2019 Copyright by rt-thread team
lwIP-2.0.2 initialized!
[E/drv.emac] eth hardware init failed
[D/drv.emac] emac hardware start
00000000: FF FF FF FF FF FF 00 80 E1 34 DA 32 08 00 45 00  .........4.2..E.
00000010: 01 50 00 00 00 00 FF 11 BA 9D 00 00 00 00 FF FF  .P..............
00000020: FF FF 00 44 00 43 01 3C A3 FE 01 01 06 00 00 00  ...D.C.<........
00000030: BC 8F 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000040: 00 00 00 00 00 00 00 80 E1 34 DA 32 00 00 00 00  .........4.2....
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: DC 37 04 01 03 1C 06 FF 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............
[D/drv.emac] transmit frame length :350
[D/drv.emac] emac device init success
[I/sal.skt] Socket Abstraction Layer initialize success.
[D/drv.emac] Found a phy, address:0x00
[D/drv.emac] RESET PHY!
00000000: FF FF FF FF FF FF 00 80 E1 34 DA 32 08 00 45 00  .........4.2..E.
00000010: 01 50 00 01 00 00 FF 11 BA 9C 00 00 00 00 FF FF  .P..............
00000020: FF FF 00 44 00 43 01 3C A3 FE 01 01 06 00 00 00  ...D.C.<........
00000030: BC 8F 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000040: 00 00 00 00 00 00 00 80 E1 34 DA 32 00 00 00 00  .........4.2....
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: DC 37 04 01 03 1C 06 FF 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............
[D/drv.emac] transmit frame length :350
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
00000000: FF FF FF FF FF FF 00 80 E1 34 DA 32 08 00 45 00  .........4.2..E.
00000010: 01 50 00 02 00 00 FF 11 BA 9B 00 00 00 00 FF FF  .P..............
00000020: FF FF 00 44 00 43 01 3C A3 FE 01 01 06 00 00 00  ...D.C.<........
00000030: BC 8F 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000040: 00 00 00 00 00 00 00 80 E1 34 DA 32 00 00 00 00  .........4.2....
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: DC 37 04 01 03 1C 06 FF 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............
[D/drv.emac] transmit frame length :350
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
00000000: FF FF FF FF FF FF 00 80 E1 34 DA 32 08 00 45 00  .........4.2..E.
00000010: 01 50 00 03 00 00 FF 11 BA 9A 00 00 00 00 FF FF  .P..............
00000020: FF FF 00 44 00 43 01 3C A3 FE 01 01 06 00 00 00  ...D.C.<........
00000030: BC 8F 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000040: 00 00 00 00 00 00 00 80 E1 34 DA 32 00 00 00 00  .........4.2....
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000110: 00 00 00 00 00 00 63 82 53 63 35 01 01 39 02 05  ......c.Sc5..9..
00000120: DC 37 04 01 03 1C 06 FF 00 00 00 00 00 00 00 00  .7..............
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00        ..............
[D/drv.emac] transmit frame length :350
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] buffer not valid
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849
[D/drv.emac] phy basic status reg is 0x7849

查看更多

关注者
1
被浏览
329
1 个回答
cxhxy12345
cxhxy12345 2021-05-05

你这个很难判断,可以用断点方式进行调试,先找到fail的位置

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览