MCU_使用STM32CUBEMX配置STM32F107/407 RMII-ETHERNET要注意的细节:PHY Address和MCO时钟

下面这两个是配置时比较容易忽略的问题。这里以STM32F107为例讲解,原理都一样,配置时看参考手册和DATASHEET。

PHY_ADDRESS

PHY Address需要是由PHYAD0引脚决定的,拉高就配置1,拉低/浮空就配置0,与具体的器件有关。

DP83848

DP83848在手册中(5.4.4 PHY Address)有描述到,PHYAD[0]内部有一个默认的上拉电阻,PHYAD[4:1]内部有一个默认的下拉电阻,在悬空的情况下,地址就是0x01;

Because the PHYAD[0] pin has weak internal pullup resistor and PHYAD[4:1] pins have weak internal pulldown resistors, the default setting for the PHY address is 00001 (0x01h).

LAN8720a

对于LAN8720a 则在手册中(3.7.1 PHYAD[0]: PHY ADDRESS CONFIGURATION)描述,默认的地址是0。 The PHYAD0 bit is driven high or low to give each PHY a unique address. This address is latched into an internal register at the end of a hardware reset (default = 0b).

The device’s SMI address may be configured using hardware configuration to either the value 0 or 1. The user can configure the PHY address using Software Configuration if an address greater than 1 is required.

 

RMII时钟问题 -- STM32F107 PLL3的时钟配置

如果DP83848/LAN8720使用独立的时钟源,那当然就不存在配置问题。如果使用PLL的时钟源,就要注意,STM32f107 手册RM0008,8.2.0中有说明,PLL3 clock selected (for Ethernet),即PLL3是ETHERNET的时钟源,这里,DP83484或LAN8720都要求50M。

还有一点,25M的配置在DATASHEET中也有,配置方法稍有不同但很简单,可以不用配置PLL3,参考DATASHEET 附录部分(A.2 Ethernet interface solutions)即可。因为很少看到有人用,这里不多说,原理都一样,配置时注意。

手册部分内容摘录如下,

8.2.10 Clock-out capability The microcontroller clock output (MCO) capability allows the clock to be output onto the external MCO pin. The configuration registers of the corresponding GPIO port must be programmed in alternate function mode.
One of 8 clock signals can be selected as the MCO clock.
• SYSCLK
• HSI
• HSE
• PLL clock divided by 2 selected
• PLL2 clock selected
• PLL3 clock divided by 2 selected
• XT1 external 3-25 MHz oscillator clock selected (for Ethernet)
• PLL3 clock selected (for Ethernet)
The selected clock to output onto MCO must not exceed 50 MHz (the maximum I/O speed).
The selection is controlled by the MCO[3:0] bits of the Clock configuration register (RCC_CFGR).

 

要注意的问题

PA8-MCO的速度

这里要特别注意:MCO引脚 PA8的速度一定要调成HIGH,默认的STM32CUBEMX是LOW。

如果速度是LOW的话,大抵上你的程序在HAL_ETH_Init中会得到一个超时的报错(HAL_ETH_STATE_TIMEOUT):

while (((heth->Instance)->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)
  {
    /* Check for the Timeout */
    if ((HAL_GetTick() - tickstart) > ETH_TIMEOUT_SWRESET)
    {
      heth->State = HAL_ETH_STATE_TIMEOUT;

      /* Process Unlocked */
      __HAL_UNLOCK(heth);

      /* Note: The SWR is not performed if the ETH_RX_CLK or the ETH_TX_CLK are
         not available, please check your external PHY or the IO configuration */
      return HAL_TIMEOUT;
    }
  }

附录1:STM32F107VCT6和DP83848电路

下面这个是手册中推荐的DP83848电路

MCU_使用STM32CUBEMX配置STM32F107/407 RMII-ETHERNET要注意的细节:PHY Address和MCO时钟_第1张图片

下面这个是根据上面的电路设计出来的实际使用电路,注意PA1是REF_CLK, PA8是MCO,所以这两个是要短接的。

MCU_使用STM32CUBEMX配置STM32F107/407 RMII-ETHERNET要注意的细节:PHY Address和MCO时钟_第2张图片

附录2:STM32F107时钟配置图

我使用的是25M外部晶振,当然,如果你使用8M外部晶振,配置大同小异,注意左下角那个MCO-PLL3的配置。

MCU_使用STM32CUBEMX配置STM32F107/407 RMII-ETHERNET要注意的细节:PHY Address和MCO时钟_第3张图片

 

你可能感兴趣的:(MCU,net,MCU,ethernet,net)