AnsweredAssumed Answered

Help with Ethernet configuration

Question asked by B3rsui on Jul 18, 2013
Latest reply on Jul 19, 2013 by B3rsui
Hello guys, I need some help. Im trying to interface a stm32f407 with a lan8720 via RMII interface using an external clock source from the PHY.

I was able to measure the 50MHz sine wave generated by the PHY, but I can't see any comunication between chips. I mean, MDC is always low and MDIO is always high (because there's a pull up resistor).

Below is the code. I'm pretty sure that there's a problem related with the external reference clock. It seems like the MAC it's not running. I think there's something wrong configured.

The code is based on [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/MDC%20MDIO%20stay%20low%20forever%20after%20configuring%20RMII%20%20Ethernet%20on%20STM32F4&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=520]this post.

Best regards!

void ETH_GPIO_Config(void)
{
    uint16_t    i = 0;
    // Data structure to represent GPIO configuration information
    GPIO_InitTypeDef GPIO_InitStructure;
 
    // Enable the peripheral clocks
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
                           RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD,
                           ENABLE);
 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); // Early
 
    // Configure PD8 (RMII_nRST)
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
 
    // Hold the Ethernet PHY in reset
    GPIOD->BSRRH = 0x100;
 
    // Set RMII mode while in reset
    SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);
 
    //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
    // Configure PA1, PA2 and PA7 (RMII_REFCLK, RMII_MDIO, RMII_CRS_DV
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH);
 
    // Configure PB11 (RMII_TXEN), PB12 (RMII_TXD0), PB13 (RMII_TXD1)
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_ETH);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_ETH);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_ETH);
 
    // Configure PC1, PC4 and PC5 (RMII_MDC, RMII_RXD0, RMII_RXD1)
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH);
 
    for(i = 0; i < 20000; i++); // PHY Out of reset
        GPIOD->BSRRL = 0x100;
}

IO_InitTypeDef GPIO_InitStructure;
 
// Enable the peripheral clocks
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
                       RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD,
                       ENABLE);
 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); // Early
 
// Configure PD8 (RMII_nRST)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOD, &GPIO_InitStructure);
 
// Hold the Ethernet PHY in reset
GPIOD->BSRRH = 0x100;
 
// Set RMII mode while in reset
SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);
 
//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
// Configure PA1, PA2 and PA7 (RMII_REFCLK, RMII_MDIO, RMII_CRS_DV
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH);
 
// Configure PB11 (RMII_TXEN), PB12 (RMII_TXD0), PB13 (RMII_TXD1)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_ETH);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_ETH);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_ETH);
 
// Configure PC1, PC4 and PC5 (RMII_MDC, RMII_RXD0, RMII_RXD1)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH);
 
for(i = 0; i < 20000; i++); // PHY Out of reset
    GPIOD->BSRRL = 0x100;

Outcomes