giveup 发表于 2016-5-28 09:56:54

STM32CubeMX下配置LAN8720A模块不成功

大家好!
我使用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                  */


giveup 发表于 2017-3-16 21:31:59

1年了。:lol
当时项目开发时间紧,耗不起。最后采用了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: *** 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

卧栏听雨 发表于 2017-7-17 16:02:57

还在吗哥哥 我的问题和你一样 求救啊

giveup 发表于 2017-7-30 19:05:26

在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。

giveup 发表于 2017-7-30 19:16:28

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

liqing666 发表于 2017-9-20 14:51:35

楼主你好,我最近在用STM32F7加DP83848,现在遇到一个问题就是网经常会连不上,而且复位N次也不行,有时候就能连上,可以麻烦你分享一下工程吗?谢谢!

giveup 发表于 2018-5-1 10:18:28

liqing666 发表于 2017-9-20 14:51
楼主你好,我最近在用STM32F7加DP83848,现在遇到一个问题就是网经常会连不上,而且复位N次也不行,有时候 ...

很久没有看了。估计你的问题解决了。
个人开发中也遇到过连接不稳定情况。多数是硬件布线问题以及元件选择导致的。例如,原型开发中,差分线没有严格等长,尽管没有超过5cm,也出现不稳定情况。在客户现场应用,因为环境低温,网线插头热胀冷缩导致接触不良情况也有,更改水晶头,增加软件心跳包验证等手段最终才解决(即不产生影响生产的故障)。
解决这些问题,我一般会用代换法,用验证过的器件将问题划分为硬件和软件,逐步缩小范围。

rosewoman 发表于 2020-3-20 10:45:52

大哥,你后来调通飞雪的以太网模块了,我现在也是调不通,PHY地址,3个寄存器都改了。Ping不同,也是cubemx生成的工程
页: [1]
查看完整版本: STM32CubeMX下配置LAN8720A模块不成功