cancel
Showing results for 
Search instead for 
Did you mean: 

MDC MDIO stay low forever after configuring RMII / Ethernet on STM32F4

szbrozek9
Associate II
Posted on August 31, 2012 at 01:02

I'm trying to use RMII between an STM32F407VE and an SMSC LAN8720 PHY. So far I've followed along with the STM32F4 Ethernet example but am having less than stellar success.

As far as I can tell, MDC and MDIO go low after the Ethernet clocks are turned on, but then never rise again. No data appears to be crossing the bus, even though the Ethernet configuration routines (supplied by ST) should be trying to communicate with the PHY.

I've found only one seemingly relevant forum post

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/RMII with external oscillator&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=130

. Sadly, its contents did not help me.

Relevant code snippets

http://pastie.org/4619205

and

http://pastie.org/4619195

.

Suggestions for why the lines may be stuck low would be most appreciated. Thank you!

-Sasha

null
3 REPLIES 3
Posted on August 31, 2012 at 01:19

// Configure GPIOs to connect to the Ethernet MAC AF
void GPIO_EnableEthernet()
{
// 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 PD9 (RMII_nRST)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
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_UP ;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Hold the Ethernet PHY in reset
GPIOD->BSRRH = 0x200;
// Set RMII mode while in reset
SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);

GPIO_InitStructure.GPIO_OType = GPIO_OType_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);
}

Need to make sure the GPIO Init structure does what you want.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
szbrozek9
Associate II
Posted on August 31, 2012 at 20:37

Thank you so much! I had just assumed that by connecting the GPIO to the AF peripheral would override any output settings. That's clearly faulty thinking and setting them to push-pull worked perfectly.

Once again, thank you!

Palacios.Bruno
Associate III
Posted on July 18, 2013 at 22:15

Hi zbrozek,

Would you mind sharing your configuration? I am having a similar problem and this code doesn't work for me =/. 

Thank you very much.

Best regards!