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電路

下面這個是根據上面的電路設計出來的實際使用電路,注意PA1是REF_CLK, PA8是MCO,所以這兩個是要短接的。

附錄2:STM32F107時鐘配置圖

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章