打印
[其他ST产品]

STM32CubeMX下配置LAN8720A模块不成功

[复制链接]
337|14
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
powerantone|  楼主 | 2022-12-3 16:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大家好!
我使用taobao上买的STM32F407VET,在STM32CubeMX进行配置。STM32CubeMX版本是4.15,HAL驱动是F4 1.12,附加FreeRTOS和LwIP组件。
采用微雪DP83848模块,工作正常。更换微雪LAN8720A模块。没有调试成功。
按照网上查找的说法,LAN8720A修改PHY地址、PHY_SR、PHY_SPEED_STATUS、PHY_DUPLEX_STATUS,即可正常工作。
#define PHY_SR                          ((uint16_t)31U)    /*!< PHY status register Offset                      */
#define PHY_SPEED_STATUS                ((uint16_t)0x0004U)  /*!< PHY Speed mask                                  */
#define PHY_DUPLEX_STATUS               ((uint16_t)0x0010U)  /*!< PHY Duplex mask                                 */
不能工作。下载该模块http://www.waveshare.net/shop/LAN8720-ETH-Board.htm的资料和示例,不能工作。

查看LAN8720A芯片手册,微雪LAN8720A模块对比原子开发板的原理图,有一些区别:
1。PHY地址是1而不是0。
2。LED1(绿色)电路禁能了内部1.2V稳压器。这个没有想明白为什么。
3。采用OSCIN模式,模块提供有50M有源晶振。

另外,检查发现购买的模块MCIO上拉电阻和REST上拉电阻阻值交换。手册上推荐的MCIO上拉电阻是152,错用复位的472。怀疑是悍错了。
改造:1。将LED1电路A接VCC处划断,原331电阻旋转90度改到A,K段就近连到地。符合手册上推荐的使能1.2V稳压器。
2。交换MCIO上拉电阻和REST上拉电阻。
3。检查发现中断引脚330电阻没有焊接,无需断开。
继续实验,读PHY MII寄存器正确。出现的问题是,不能PING通。芯片刚启动时会出现两个超时,然后是无法到达。似乎没有发生输入接收中断。
跟踪后发现,初始化正常通过,没有出现错误。
PS:这里要吐嘈一下,HAL初始化函数中的问题:如果PHY地址设置错误,读出寄存器的值全是1,即65535,掩码操作判断状态全部正常! 应该增加一个判断是否为0xFFFF的条件。
修改了ethernetif_set_link函数,调用1次 netif_set_link_up(link_arg->netif)。
似乎所有的TCP任务都处于阻塞状态。
不知道大家有没有成功调试通过的经验,希望介绍一下。

#define PHY_SR                          ((uint16_t)31U)    /*!< PHY status register Offset                      */
#define PHY_MICR                        ((uint16_t)30U)    /*!< MII Interrupt Control Register                  */
#define PHY_MISR                        ((uint16_t)29U)    /*!< MII Interrupt Status and Misc. Control Register */

#define PHY_LINK_STATUS                 ((uint16_t)0x0004U)  /*!< PHY Link mask                                   */
#define PHY_SPEED_STATUS                ((uint16_t)0x0004U)  /*!< PHY Speed mask                                  */
#define PHY_DUPLEX_STATUS               ((uint16_t)0x0010U)  /*!< PHY Duplex mask                                 */

#define PHY_MICR_INT_EN                 ((uint16_t)0x0000U)  /*!< PHY Enable interrupts                           */
#define PHY_MICR_INT_OE                 ((uint16_t)0x0010U)  /*!< PHY Enable output interrupt events              */

#define PHY_MISR_LINK_INT_EN            ((uint16_t)0x0000U)  /*!< Enable Interrupt on change of link status       */
#define PHY_LINK_INTERRUPT              ((uint16_t)0x0010U)  /*!< PHY link status interrupt mask                  */



使用特权

评论回复
沙发
powerantone|  楼主 | 2022-12-3 16:40 | 只看该作者
1年了。
当时项目开发时间紧,耗不起。最后采用了DP83848方案。
这两天同事又拿出来这个LAN8720A。结果……
不小心升级了软件到最新版:
STM32CubeMX Software V4.20.0 / 28 February 2017
STM32CubeF4 Firmware Package V1.15.0 / 17-February-2017
生成的芯片默认是LAN8720A了!如果选择外部中断,编译会出现提示:

  • HandleTypeDef *heth)
  •                                                 ^
  • ../Src/ethernetif.c: In function 'low_level_output':
  • ../Src/ethernetif.c:346:45: warning: unused parameter 'netif' [-Wunused-parameter]
  • static err_t low_level_output(struct netif *netif, struct pbuf *p)
  •                                              ^
  • ../Src/ethernetif.c: In function 'low_level_input':
  • ../Src/ethernetif.c:430:52: warning: unused parameter 'netif' [-Wunused-parameter]
  • static struct pbuf * low_level_input(struct netif *netif)
  •                                                     ^
  • ../Src/ethernetif.c: In function 'ethernetif_set_link':
  • ../Src/ethernetif.c:665:38: error: 'PHY_MISR' undeclared (first use in this function)
  •        HAL_ETH_ReadPHYRegister(&heth, PHY_MISR, &regvalue);
  •                                       ^
  • ../Src/ethernetif.c:665:38: note: each undeclared identifier is reported only once for each function it appears in
  • ../Src/ethernetif.c:668:22: error: 'PHY_LINK_INTERRUPT' undeclared (first use in this function)
  •        if((regvalue & PHY_LINK_INTERRUPT) != (uint16_t)RESET)
  •                       ^
  • ../Src/ethernetif.c:674:24: error: 'PHY_LINK_STATUS' undeclared (first use in this function)
  •          if((regvalue & PHY_LINK_STATUS)!= (uint16_t)RESET)
  •                         ^
  • ../Src/ethernetif.c: In function 'ethernetif_notify_conn_changed':
  • ../Src/ethernetif.c:788:58: warning: unused parameter 'netif' [-Wunused-parameter]
  • __weak void ethernetif_notify_conn_changed(struct netif *netif)
  •                                                           ^
  • Src/subdir.mk:57: recipe for target 'Src/ethernetif.o' failed
  • make: *** [Src/ethernetif.o] Error 1

复制代码


如果注释掉,仍然有问题:
  • Building file: ../Src/main.c
  • Invoking: Cross ARM GNU C Compiler
  • arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra  -g3 -DDEBUG -DUSE_FULL_ASSERT -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F407xx -DUSE_HAL_DRIVER -DHSE_VALUE=8000000 -I"../Inc" -I"../startup" -I"../system/Inc" -I"../Drivers/CMSIS/Include" -I"../Drivers/CMSIS/Device/ST/STM32F4xx/Include" -I"../Drivers/STM32F4xx_HAL_Driver/Inc" -I"../Middlewares/Third_Party/LwIP/system" -I"../Middlewares/Third_Party/FatFs/src" -I"../Middlewares/Third_Party/LwIP/src/include" -I"../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F" -I"../Middlewares/Third_Party/FreeRTOS/Source/include" -I"../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS" -I"../Middlewares/Third_Party/LwIP/system/arch" -I"../Middlewares/Third_Party/LwIP/src/include/lwip" -I"../Middlewares/Third_Party/LwIP/src/include/netif" -I"../Middlewares/Third_Party/LwIP/src/include/posix" -I"../Middlewares/Third_Party/LwIP/src/include/posix/sys" -I"../Middlewares/Third_Party/LwIP/src/netif/ppp" -std=gnu11 -MMD -MP -MF"Src/main.d" -MT"Src/main.o" -c -o "Src/main.o" "../Src/main.c"
  • ../Src/main.c:204:36: error: unknown type name 'TIM_HandleTypeDef'
  • void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  •                                     ^
  • ../Src/main.c: In function 'assert_failed':

复制代码


看来这个版本的软件系统秉承一贯的粗糙风格,太不稳定了。
无语——
直接选择的CPU 407,SYS选择Tim4




[color=var(--default-a-next-color)][url=][/url]

使用特权

评论回复
板凳
powerantone|  楼主 | 2022-12-3 16:41 | 只看该作者
在ethernetif.c中增加丢失的寄存器声明
/* Within 'USER CODE' section, code will be kept by default at each generation */
/* USER CODE BEGIN 0 */
#define PHY_MICR                        ((uint16_t)0x11)    /*!< MII Interrupt Control Register                  */
#define PHY_MISR                        ((uint16_t)0x12)    /*!< MII Interrupt Status and Misc. Control Register */

#define PHY_LINK_STATUS                 ((uint16_t)0x0001)  /*!< PHY Link mask                                   */

#define PHY_MICR_INT_EN                 ((uint16_t)0x0002)  /*!< PHY Enable interrupts                           */
#define PHY_MICR_INT_OE                 ((uint16_t)0x0001)  /*!< PHY Enable output interrupt events              */
#define PHY_MISR_LINK_INT_EN            ((uint16_t)0x0020U)  /*!< Enable Interrupt on change of link status       */
#define PHY_LINK_INTERRUPT              ((uint16_t)0x2000U)  /*!< PHY link status interrupt mask                  */

#define PHY_ISFR                        ((uint16_t)0x1D)    /*!< PHY Interrupt Source Flag register Offset       */
#define PHY_ISFR_INT4                   ((uint16_t)0x0010)  /*!< PHY Link down inturrupt                         */
/* USER CODE END 0 */
复制代码

应该能编译通过的。
我是Debian 9, 32位环境,eclipse 4.6 + gnu mcu 2.5.1 + JLink OB。

使用特权

评论回复
地板
powerantone|  楼主 | 2022-12-3 16:41 | 只看该作者
需要按照lan8720A的参数更改。上面代码是dp83848的。
个人感觉出现上述问题,是选择了CPU,没有选择板子造成的。修改的地方很多。
简便办法就是到STM32CubeMX 中新建一个工程,选择 NUCLEO-429ZI板子。有相应的资料可以查看。选中ETH,可以参考生成的代码片段。或者到仓库中查找该板子的例程。
我用的模块没有中断,只能用查询方法。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

459

主题

1718

帖子

4

粉丝