Ethernet on STM32F4DISCOVERY using external PHY
For you who have read about the STM32F4 Cortex-M4 processor you might know that this processor family includes a 10/100 Ethernet MAC with dedicated DMA that supports supports IEEE 1588v2 hardware, MII/RMII.
This means that the only electronics needed to enable the ethernet capability is an external PHY and the Magjack connector.
On the STM3240G-EVAL evaluation board the DP83848 PHY is used and luckily for us we were able to find a simple breakout board for this chip on eBay.
To hook up this Phy to the STM32F4DISCOVERY board a slight change in the pins, compared to the connections on the evaluation board, had to be made. Because the STM32F4DISCOVERY board only contains the 100-pin version some of the full MII pins are missing so we have to use the PHY in RMII mode.
So by taking the example project files for the Webpage example on the evaluation board, changing the GPIO initialization and Ethernet BSP file a bit to match the Discovery board, we were able to get the example running on our board.
The connections between the PHY module and the STM32F4DISCOVERY board can be seen in the image below.
On the PHY Breakout board there is space for a jumper. This jumper is used for external reset and should not be installed to work in this project.
To see the Ethernet functionality in use with the webpage example loaded on the Discovery board have a look at our video below.
The GCC project for the Webpage demonstration on the STM32F4DISCOVERY board, shown in the video, together with a CooCox CoIDE project file can be downloaded from the following link: STM32F4DISCOVERY Ethernet-Phy – Webpage example
Thanks to a comment from @P_K there is a very simple way to generate your own new HTML files using the “makefsdata.exe” file found inside the “STM32F4x7_ETH_LwIP_V1.0.0\Utilities\Third_Party\PC_Software” folder.
Please read more about how to do so at the following page: http://www.aimagin.com/tgr/tgr12/amgf4connect/doc/HTML/index.html?webpage_configuration.htm
You can eventually also see the following forum post on how to get ChibiOS and their Ethernet example to work with the setup described in this post: http://forum.chibios.org/phpbb/viewtopic.php?f=3&t=23&p=8017#p8017
Categories: ARM, Development boards



Hi,
I try to compile the projekt with CoIDE 1.7.0. But there is no option to “Exclude from Build” the fsdata.c
Is there a otherway to compile the projekt?
Thanks for your help.
125 39.520406000 0.0.0.0 255.255.255.255 DHCP 350 DHCP Discover -- Transaction ID 0xabcd0001
72 14.522511000 192.168.2.20 239.255.255.250 UDP 1035 Source port: 52609 Destination port: ws-discovery
hi everyone,
im using stm32f4 discovery board and dp83848 as phy module. The changes i have made on the lwip example of st(standalone->httpserver example)
1) gpio alternative function definitions and initializations for PA1,PA2,PA7,PC4,PC5,PC1,PB11,PB12,PB13
2) Definition of HSE value as 8000000hz and pll_m value as 8
3) Moving the MCO pin (PA8) initialization inside the MII_MODE selection.
#ifdef MII_MODE /* Mode MII with STM324xG-EVAL */
#ifdef PHY_CLOCK_MCO
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Output HSE clock (25MHz) on MCO pin (PA8) to clock the PHY */
RCC_MCO1Config(RCC_MCO1Source_HSE, RCC_MCO1Div_1);
#endif /* PHY_CLOCK_MCO */
(Other GPIO configurations (pin,speed,mode,OType,PuPd) are outside this condition.)
4) Ethernet clocks is started after the software reset of ethernet.
/* Reset ETHERNET on AHB Bus */
ETH_DeInit();
/* Software reset */
ETH_SoftwareReset();
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC | RCC_AHB1Periph_ETH_MAC_Tx |
RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
5)#define USE_DHCP and commented out version (//#define USE_DHCP) are both tried.
6)”#define RMII_MODE” and “//#define MII_MODE”
7)My Airties modems(also gateway) ip is 192.168.2.1
My PC’s ip is 192.168.2.20(no automatic ip , this is static on ipv4 settings)
The static ip defined on the code for the board is 192.168.2.27
The subnet of the network is 255.255.255.0
DHCP settings of the router start adress 192.168.2.20- end adress 192.168.2.30 and three computers are using the LAN(the last one’s ip 192.168.2.22)
CASES that i have tried;
When i powered the module and the board i get the link led(orange one) always on and the data led(green one) blinking.
1)When i use “dhcp on” mode for the discovery board i couldn’t even ping or get the webpage on browser. In the wireshark screen i get “dhcp discover” lines for 4 times but no response from the router and discovery cannot get and ip.
“125 39.520406000 0.0.0.0 255.255.255.255 DHCP 350 DHCP Discover -- Transaction ID 0xabcd0001″
2)When i use “dhcp off” mode no ping response and no webpage again.On the wireshark screen i get
02:00:00:00:00:00 Broadcast ARP 60 Gratuitous ARP for 192.168.2.27 (Request)
but no response from the router.
3)When i dismiss the router and get connected the discovery and the computer with a straight ethernet cable(dhcp off mode for the board) i cannot ping the module and cannot reach the webpage.
In all cases i cannot see the board in the list for “arp -a” command. I checked the cabling 3-4 times so i dont think there is a mistake with it. I need some help and advice thanks in advance..
Kadir
sorry for twice entries..
Kadir
Hi,
I am using a phy from Micrel(KSZ8041NL) ,I have downloaded your code and made changes to the phy register values in the stm32f4x7_eth_conf_template.h file but the project is not working.I am using MII mode in this project.Help needed….
Thanks in advance….
hi everyone,
im using stm32f4 discovery board and dpxxxx as phy module. The changes i have made on the lwip example of st(standalone->httpserver example)
1) gpio alternative function definitions and initializations for PA1,PA2,PA7,PC4,PC5,PC1,PB11,PB12,PB13
2) Definition of HSE value as 8000000hz and pll_m value as 8
3) Moving the MCO pin (PA8) initialization inside the MII_MODE selection.
#ifdef MII_MODE /* Mode MII with STM324xG-EVAL */
#ifdef PHY_CLOCK_MCO
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Output HSE clock (25MHz) on MCO pin (PA8) to clock the PHY */
RCC_MCO1Config(RCC_MCO1Source_HSE, RCC_MCO1Div_1);
#endif /* PHY_CLOCK_MCO */
(Other GPIO configurations (pin,speed,mode,OType,PuPd) are outside this condition.)
4) Ethernet clocks is started after the software reset of ethernet.
/* Reset ETHERNET on AHB Bus */
ETH_DeInit();
/* Software reset */
ETH_SoftwareReset();
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC | RCC_AHB1Periph_ETH_MAC_Tx |
RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
5)#define USE_DHCP and commented out version (//#define USE_DHCP) are both tried.
6)”#define RMII_MODE” and “//#define MII_MODE”
7)My Airties modems(also gateway) ip is 192.168.2.1
My PC’s ip is 192.168.2.20(no automatic ip , this is static on ipv4 settings)
The static ip defined on the code for the board is 192.168.2.27
The subnet of the network is 255.255.255.0
DHCP settings of the router start adress 192.168.2.20- end adress 192.168.2.30 and three computers are using the LAN(the last one’s ip 192.168.2.22)
CASES that i have tried;
When i powered the module and the board i get the link led(orange one) always on and the data led(green one) blinking.
1)When i use “dhcp on” mode for the discovery board i couldn’t even ping or get the webpage on browser. In the wireshark screen i get “dhcp discover” lines for 4 times but no response from the router and discovery cannot get and ip.
“125 39.520406000 0.0.0.0 255.255.255.255 DHCP 350 DHCP Discover — Transaction ID 0xabcd0001″
2)When i use “dhcp off” mode no ping response and no webpage again.On the wireshark screen i get
02:00:00:00:00:00 Broadcast ARP 60 Gratuitous ARP for 192.168.2.27 (Request)
but no response from the router.
3)When i dismiss the router and get connected the discovery and the computer with a straight ethernet cable(dhcp off mode for the board) i cannot ping the module and cannot reach the webpage.
In all cases i cannot see the board in the list for “arp -a” command. I checked the cabling 3-4 times so i dont think there is a mistake with it.I have tried all of the configurations with cross and straight ethernet cables. I need some help and advice thanks in advance..
Kadir
@kadir4172
plug your board straight to PC, check pinout one more time and put long delay after your ethernet chip in main(20-100ms), disable DHCP and make sure, that you are in the same subnet as your board is(maby you ar checking wireless card’s IP, not cable ethernet card?) my pin configuration looks like this:
void ETH_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOs clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
RCC_AHB1Periph_GPIOC, ENABLE);
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Configure MCO (PA8) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
/* MII/RMII Media interface selection ————————————--*/
#ifdef MII_MODE /* Mode MII with STM324xG-EVAL */
#ifdef PHY_CLOCK_MCO
//cia perkeliau ir virsaus, kad butu salygine kompiliacija A portui. Vaidas
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Output HSE clock (25MHz) on MCO pin (PA8) to clock the PHY */
RCC_MCO1Config(RCC_MCO1Source_HSE, RCC_MCO1Div_1);
#endif /* PHY_CLOCK_MCO */
SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_MII);
#elif defined RMII_MODE /* Mode RMII with STM324xG-EVAL */
SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);
#endif
/* Configure PA1(RMII_REF_CLK), PA2(ETH_MDIO), PA3(MII_INT) and PA7(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_TX_EN), PB12(RMII_TXD0) and 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(ETH_MDC), PC4(RMII_RXD0) and PC5(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);
}
it works just fine for me. Btw, I’m using KEIL.
[cc] C:\Users\ustronic\Downloads\STM32F4DISCOVERY_Ethernet-Phy\STM32F4x7_ETH_Driver\src\core\raw.c:238:5: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘u32_t’ [-Wformat]
[cc] C:\Users\ustronic\Downloads\STM32F4DISCOVERY_Ethernet-Phy\STM32F4x7_ETH_Driver\src\core\raw.c:238:5: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘u32_t’ [-Wformat]
[cc] Starting link
[cc] arm-none-eabi-gcc -O0 -nostartfiles -Wl,-Map=STM32F4DISCOVERY_Ethernet-Phy.map -mcpu=cortex-m4 -mthumb -LC:\Users\ustronic\Downloads\STM32F4DISCOVERY_Ethernet-Phy -Wl,--gc-sections -Wl,-TC:\Users\ustronic\Downloads\STM32F4DISCOVERY_Ethernet-Phy\arm-gcc-link.ld -g -o STM32F4DISCOVERY_Ethernet-Phy.elf ..\obj\stm32f4xx_syscfg.o ..\obj\mem.o ..\obj\tcp.o ..\obj\err.o ..\obj\randm.o ..\obj\mib_structs.o ..\obj\tcp_in.o ..\obj\stm32f4xx_usart.o ..\obj\slipif.o ..\obj\memp.o ..\obj\autoip.o ..\obj\ip_frag.o ..\obj\msg_out.o ..\obj\netbuf.o ..\obj\tcpip.o ..\obj\stm32f4xx_dac.o ..\obj\asn1_dec.o ..\obj\lcp.o ..\obj\fsdata.o ..\obj\vj.o ..\obj\fs.o ..\obj\startup_stm32f4xx.o ..\obj\stm32f4_discovery.o ..\obj\stm32f4x7_eth.o ..\obj\sys.o ..\obj\ip_addr.o ..\obj\inet_chksum.o ..\obj\main.o ..\obj\stm32f4xx_rcc.o ..\obj\netconf.o ..\obj\mib2.o ..\obj\stm32f4xx_it.o ..\obj\netdb.o ..\obj\init.o ..\obj\stm32f4xx_adc.o ..\obj\stm32f4x7_eth_bsp.o ..\obj\printf.o ..\obj\ethernetif.o ..\obj\chpms.o ..\obj\etharp.o ..\obj\httpd.o ..\obj\magic.o ..\obj\httpd_cgi_ssi.o ..\obj\pbuf.o ..\obj\stats.o ..\obj\inet.o ..\obj\msg_in.o ..\obj\netif.o ..\obj\asn1_enc.o ..\obj\fsm.o ..\obj\api_msg.o ..\obj\chap.o ..\obj\stm32f4xx_gpio.o ..\obj\md5.o ..\obj\system_stm32f4xx.o ..\obj\syscalls.o ..\obj\sockets.o ..\obj\igmp.o ..\obj\pap.o ..\obj\udp.o ..\obj\ip.o ..\obj\auth.o ..\obj\stm32f4xx_exti.o ..\obj\ppp_oe.o ..\obj\icmp.o ..\obj\dns.o ..\obj\netifapi.o ..\obj\misc.o ..\obj\api_lib.o ..\obj\dhcp.o ..\obj\ppp.o ..\obj\serial_debug.o ..\obj\ipcp.o ..\obj\tcp_out.o ..\obj\loopif.o ..\obj\raw.o
[cc] ..\obj\fs.o:(.rodata+0x0): multiple definition of `file__STM32F4x7_files_ST_gif’
[cc] ..\obj\fsdata.o:(.rodata+0x0): first defined here
[cc] ..\obj\fs.o:(.rodata+0xcc14): multiple definition of `file__STM32F4x7_files_logo_jpg’
[cc] ..\obj\fsdata.o:(.rodata+0xcc14): first defined here
[cc] ..\obj\fs.o:(.rodata+0xcc28): multiple definition of `file__STM32F4x7_files_stm32_jpg’
[cc] ..\obj\fsdata.o:(.rodata+0xcc28): first defined here
[cc] ..\obj\fs.o:(.rodata+0xcc3c): multiple definition of `file__STM32F4x7LED_html’
[cc] ..\obj\fsdata.o:(.rodata+0xcc3c): first defined here
[cc] ..\obj\fs.o:(.rodata+0xcc50): multiple definition of `file__404_html’
[cc] ..\obj\fsdata.o:(.rodata+0xcc50): first defined here
[cc] ..\obj\fs.o:(.rodata+0xcc64): multiple definition of `file__index_html’
[cc] ..\obj\fsdata.o:(.rodata+0xcc64): first defined here
[cc] ..\obj\fs.o:(.rodata+0xcc78): multiple definition of `file__STM32F4x7ADC_shtml’
[cc] ..\obj\fsdata.o:(.rodata+0xcc78): first defined here
[cc] collect2: ld returned 1 exit status
BUILD FAILED
Total time: 1 minute 7 seconds
i have this error please help me
@gabriel
This specific problem has been discussed in a previous comment and I have written a solution to it.
Please read this solution from me: comment-55246
Kind regards Thomas
thank you for your help it works
[cc] 0 files to be recompiled from dependency analysis.
[cc] 0 total files to be compiled.
[cc] Starting link
[cc] arm-none-eabi-gcc -O0 -nostartfiles “-Wl,-Map=proyecto ethernet.map” -mcpu=cortex-m4 -mthumb “-LC:\proyecto ethernet” -Wl,--gc-sections “-Wl,-TC:\proyecto ethernet\arm-gcc-link.ld” -g -o ‘”proyecto ethernet.elf”‘ ..\obj\stm32f4xx_syscfg.o ..\obj\mem.o ..\obj\tcp.o ..\obj\err.o ..\obj\randm.o ..\obj\mib_structs.o ..\obj\tcp_in.o ..\obj\stm32f4xx_usart.o ..\obj\slipif.o ..\obj\memp.o ..\obj\autoip.o ..\obj\ip_frag.o ..\obj\msg_out.o ..\obj\netbuf.o ..\obj\tcpip.o ..\obj\stm32f4xx_dac.o ..\obj\asn1_dec.o ..\obj\lcp.o ..\obj\vj.o ..\obj\fs.o ..\obj\startup_stm32f4xx.o ..\obj\stm32f4_discovery.o ..\obj\stm32f4x7_eth.o ..\obj\sys.o ..\obj\ip_addr.o ..\obj\inet_chksum.o ..\obj\main.o ..\obj\stm32f4xx_rcc.o ..\obj\netconf.o ..\obj\mib2.o ..\obj\stm32f4xx_it.o ..\obj\netdb.o ..\obj\init.o ..\obj\stm32f4xx_adc.o ..\obj\stm32f4x7_eth_bsp.o ..\obj\printf.o ..\obj\ethernetif.o ..\obj\chpms.o ..\obj\etharp.o ..\obj\httpd.o ..\obj\magic.o ..\obj\httpd_cgi_ssi.o ..\obj\pbuf.o ..\obj\stats.o ..\obj\inet.o ..\obj\msg_in.o ..\obj\netif.o ..\obj\asn1_enc.o ..\obj\fsm.o ..\obj\api_msg.o ..\obj\chap.o ..\obj\stm32f4xx_gpio.o ..\obj\md5.o ..\obj\system_stm32f4xx.o ..\obj\syscalls.o ..\obj\sockets.o ..\obj\igmp.o ..\obj\pap.o ..\obj\udp.o ..\obj\ip.o ..\obj\auth.o ..\obj\stm32f4xx_exti.o ..\obj\ppp_oe.o ..\obj\icmp.o ..\obj\dns.o ..\obj\netifapi.o ..\obj\misc.o ..\obj\api_lib.o ..\obj\dhcp.o ..\obj\ppp.o ..\obj\serial_debug.o ..\obj\ipcp.o ..\obj\tcp_out.o ..\obj\loopif.o ..\obj\raw.o
Program Size:
text data bss dec hex filename
151532 2284 34260 188076 2deac proyecto ethernet.elf
BUILD SUCCESSFUL
Total time: 16 seconds
@Kadir Cimenci
I have found a similar problem. I am working on STM32F407 + DP83848 + LwIP.
However I have looking in the data packet with wireshark.. and comparing with another DHCP packet (the valid, and working.
I have Looked on BOOTSTRAP Protocal . and saw that the “Bootp flags” was 0x000 which is unicast.
from my understanding , I should be “BROADCAST” , 0x8000.
then I checked line 845 in “dhcp.c” in the driver ,
dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
it said “BROADCAST” with
#define DHCP_OPTION_BROADCAST 28
in dhcp.h.
Dose it a bug? or something? Is my understanding correct?
Furthermore the packet size is larger than another computer’s packet.
STM32F4+LwIP generates 350Bytes Packet, But another working computer generates 350 Bytes DHCP Discovery Packet.
//——————————————————
I have Fix other problems such as ,
MCO init in MII mode
PLL Clock and divider
ETH-Pher Clock initial after ETH reset. Fixing Forever Loop in ETH_Init();
Reinit system clk after system init in ther starting of main();
Configs Port.
Will this code compile on keil uvision?
build failed because of “collect2.exe: error: ld returned 1 exit status”
what might be the problem?
thomas u are awesome man!!
Can you explain your words : “Because the STM32F4DISCOVERY board only contains the 100-pin version some of the full MII pins are missing so we have to use the PHY in RMII mode.”. Which of the pins are missing? In my opinion every pins are available in 100pins STM32F4 version on STM F4 Discovery.
The webpage opens a cgi code. its action is to open the page to control 4 LEDS. But i need a LED per page. How do i program to do it.. Please reply..
Hi guys, im trying to compile it in IAR but I’m getting one error that I can’t figure it out.
Error[Pe067]: expected a “}” D:\Microcontroladores\ST\STM32F4-Discovery\ethernet\Ethernet\source\httpd_cgi_ssi.c 40
That line is like this:
char const** TAGS= { &TAGCHAR, &TAGCHAR2 };
Any suggestions?
Thank you!!
Maybe i’m blind, but i can’t see an option to exclude “fsdata.c” from build…
I’m working with CoIDE version 1.7.0
Any suggestions
How to refresh HTML page with use user button on the board?
@P_K
You would have to elaborate on what you mean by “refresh”.
Do you want to change the content of a page when pressing the button, or would you like the page to be refreshed inside of the external browser when the button is pressed?
@Thomas Kaiser
I am currently still running CoIDE 1.5.1 due to some project structure changes in 1.6.0.
In my version I am able to right click on the file in the left file-structure panel and select “Exclude from Build…”
@Thomas Jespersen
Hi, can you tell me how to revise the code to adjust to the STM32F407DISCOVERY board, bcz the code the ST supply is for the board named STM3240G-EVAL evaluation board.
@Thomas Jespersen
If I press one a button I want change the content of a page, but if another page to be refreshed inside of the external browser