Arm Mbed OS support forum

F207ZG ethernet PHY KSZ8081MLX using MII

Hey there!

I’m trying to connect the Microchip KSZ8081MLX to an STM32F207ZG using the MII interface. However, I am still getting an error -3004 (not connected to a network ).
I have already made a custom mbed_app.json:

{
    "target_overrides": {
        "*": {
			"stm32-emac.eth-phy-address": 1,
			"stm32-emac.eth-phy-media-interface":  "ETH_MEDIA_INTERFACE_MII",
	        "stm32-emac.eth-phy-DuplexMode": "ETH_MODE_HALFDUPLEX",
			"stm32-emac.eth-phy-Speed": "ETH_SPEED_10M"
        }
    }
}

But unfortunately this did not solve my problem. Now I noticed there are no MII pins declared for the F207ZG in PerihperalPins.c, only RMII pins. I was wondering how I should go about changing this.

Any other tips/tricks would be welcome! Thanks in advance

Edit #1: Actually I don’t see them declared anywhere, I just would like to double-check the pin-out.
Edit #2: I re-soldered the chip, now there is a connection but I am getting error -3010 (DHCP failure). The device is connected to a switch, which is connected to a router with DHCP enabled…
Edit #3: Added the following:

{
    "target_overrides": {
        "*": {
			"stm32-emac.eth-phy-address": 1,
			"stm32-emac.eth-phy-media-interface":  "ETH_MEDIA_INTERFACE_MII",
	        "stm32-emac.eth-phy-DuplexMode": "ETH_MODE_HALFDUPLEX",
			"stm32-emac.eth-phy-Speed": "ETH_SPEED_10M",
			"stm32-emac.eth-phy-status-register": "30",
			"stm32-emac.eth-phy-speed-status": "0x0001",
			"stm32-emac.eth-phy-duplex-status": "0x0004"
        }
    }
}

Still no luck.
Edit #4: added contents from STM32CubeMX pinout export from “STM32CubeProject/Src/stm32f2xx_hal_msp.c” to my MedOS project “MbedOsProject/mbed-os/features/netsocket/emac-drivers/TARGET_STM/TARGET_STM32f2/TARGET_NUCLEO_F207ZG/stm32f2_eth_init.c”. The system is now working correctly. I will post the contents of “stm32f2_eth_init.c”, maybe it will help someone:

#ifndef USE_USER_DEFINED_HAL_ETH_MSPINIT

#include "stm32f2xx_hal.h"

/**
 * Override HAL Eth Init function
 */
void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(heth->Instance==ETH)
  {
        /* Peripheral clock enable */
        __HAL_RCC_ETH_CLK_ENABLE();
    
        __HAL_RCC_GPIOE_CLK_ENABLE();
        __HAL_RCC_GPIOC_CLK_ENABLE();
        __HAL_RCC_GPIOA_CLK_ENABLE();
        __HAL_RCC_GPIOB_CLK_ENABLE();
        /**ETH GPIO Configuration    
        PE2     ------> ETH_TXD3
        PC1     ------> ETH_MDC
        PC2     ------> ETH_TXD2
        PC3     ------> ETH_TX_CLK
        PA0-WKUP     ------> ETH_CRS
        PA1     ------> ETH_RX_CLK
        PA2     ------> ETH_MDIO
        PA3     ------> ETH_COL
        PA7     ------> ETH_RX_DV
        PC4     ------> ETH_RXD0
        PC5     ------> ETH_RXD1
        PB0     ------> ETH_RXD2
        PB1     ------> ETH_RXD3
        PB10     ------> ETH_RX_ER
        PB11     ------> ETH_TX_EN
        PB12     ------> ETH_TXD0
        PB13     ------> ETH_TXD1 
        */
        GPIO_InitStruct.Pin = GPIO_PIN_2;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
        GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
        HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

        GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4 
                            |GPIO_PIN_5;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
        GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

        GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
                            |GPIO_PIN_7;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
        GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

        GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11 
                            |GPIO_PIN_12|GPIO_PIN_13;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
        GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

        /* Enable the Ethernet global Interrupt */
        HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0);
        HAL_NVIC_EnableIRQ(ETH_IRQn);

        /* Enable ETHERNET clock  */
        __HAL_RCC_ETH_CLK_ENABLE();
    }
}

/**
 * Override HAL Eth DeInit function
 */
void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
{
if(heth->Instance==ETH)
  {
    /* USER CODE BEGIN ETH_MspDeInit 0 */

    /* USER CODE END ETH_MspDeInit 0 */
        /* Peripheral clock disable */
        __HAL_RCC_ETH_CLK_DISABLE();
    
        /**ETH GPIO Configuration    
        PE2     ------> ETH_TXD3
        PC1     ------> ETH_MDC
        PC2     ------> ETH_TXD2
        PC3     ------> ETH_TX_CLK
        PA0-WKUP     ------> ETH_CRS
        PA1     ------> ETH_RX_CLK
        PA2     ------> ETH_MDIO
        PA3     ------> ETH_COL
        PA7     ------> ETH_RX_DV
        PC4     ------> ETH_RXD0
        PC5     ------> ETH_RXD1
        PB0     ------> ETH_RXD2
        PB1     ------> ETH_RXD3
        PB10     ------> ETH_RX_ER
        PB11     ------> ETH_TX_EN
        PB12     ------> ETH_TXD0
        PB13     ------> ETH_TXD1 
        */
        HAL_GPIO_DeInit(GPIOE, GPIO_PIN_2);

        HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4 
                            |GPIO_PIN_5);

        HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
                            |GPIO_PIN_7);

        HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11 
                            |GPIO_PIN_12|GPIO_PIN_13);

        /* ETH interrupt DeInit */
        HAL_NVIC_DisableIRQ(ETH_IRQn);
    }
}

#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */

I saw a post mention being able to override these files using a custom build target, any pointers?