stm32F107+DM9161AEP的PHY芯片 运行出现错误

发布于 2020-08-11 11:19:05

问题:
rrt-4.0.2+lwIP1.4.1+stm32F107VCT6+DM9161AEP的PHY芯片出现错误eth hardware init failed错误

系统:rt-thread 4.0.2
LwIP版本:1.4.1
主控芯片:stm32F107VCT6
phy芯片:DM9161AEP
IDE:rt-thread studio 基于芯片建立的工程,串口1为log打印串口

①新建 RT-Thread 完整版项目
②board.h中定义 BSP_USING_ETH 和 PHY 相关的宏(使用这个#define PHY_USING_DM9161CEP,#define BSP_USING_ETH)
③board.c中初始化 ETH 相关的引脚和时钟(下面有介绍)
④stm32xxxx_hal_config.h中打开 HAL 库函数对 ETH 的支持(#define HAL_ETH_MODULE_ENABLED)
⑤board.c 中实现自己的 PHY 复位函数(接stm32的NRST)
⑥配置 lwIP 协议栈



关于用stm32CubeMX生成的eth和时钟硬件如下图,就做了引脚对应的位置而已,其他没做,也不知道需不需要做
stm32cubemX.jpg

复制stm32CubeMX生成的stm32f1xx_hal_msp.c的HAL_ETH_MspInit函数定义到board.c,

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 */
  }

}


以下是烧录固件串口打印出来的错误


 \ | /
- RT -     Thread Operating System
 / | \     4.0.2 build Aug 11 2020
 2006 - 2019 Copyright by rt-thread team
lwIP-1.4.1 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 14 0F 01 01 06 00 58 51  ...D.C.<......XQ
00000030: F4 2D 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
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 93 0D 01 01 06 00 40 B1  ...D.C.<......@.
00000030: 8C CF 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.
no memory for shell
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 93 0D 01 01 06 00 40 B1  ...D.C.<......@.
00000030: 8C CF 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
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 93 0D 01 01 06 00 40 B1  ...D.C.<......@.
00000030: 8C CF 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
[E/drv.emac] No PHY device was detected, please check hardware!
[E/drv.emac] No PHY device was detected, please check hardware!
[E/drv.emac] No PHY device was detected, please check hardware!
[D/drv.emac] buffer not valid
[E/drv.emac] No PHY device was detected, please check hardware!

以下是stm32F107的图
stm32.png
以下是DM9161AEP的图
DM9161AEp.png

麻烦大佬们指点下。感谢感谢!

查看更多

关注者
0
被浏览
573
1 个回答
james_s
james_s 3 days ago

drv.emac对应的接口函数是不是没有实现, 可以用gdb单步一下看执行到哪儿了.

撰写答案

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

发布
问题

分享
好友

手机
浏览

扫码手机浏览