cancel
Showing results for 
Search instead for 
Did you mean: 

The problem with ethernet on STM32F407

kashubadmitry
Associate II
Posted on April 06, 2017 at 23:50

Hi all!

I want to study the ethernet on STM32F407!

I have the working board with lan8720, stm32f407 and LED

I connected this board to PC through Ethernet cable/

First, I want to know,,that frames from PC are written to RX FIFO of the MAC of the STM32F407 and the register MACDBGR is analized

I wrote the following code:

/*******/

#include 'stm32f4xx.h'

// pa1-refclk, pa2-mdio,pa7-crs;

// pb11-txen, pb12-tx0, pb13-tx1,pb14-rxer;

// pc1-mdc,pc4-rx0, pc5-rx1,

// pe12-rst

// pd8-hl3_r

/******/

uint8_t temp,temp1;

uint32_t i, j,temp2,temp3;

//main program

int main()

{

//set PLL 64MHz

RCC->PLLCFGR=0x24000000;

RCC->PLLCFGR|= RCC_PLLCFGR_PLLSRC_HSI;//hsi-pll sourc

RCC->PLLCFGR|=RCC_PLLCFGR_PLLM_4;//M=16

RCC->PLLCFGR|=RCC_PLLCFGR_PLLN_7;//N=128

RCC->PLLCFGR&=~RCC_PLLCFGR_PLLP;//P=2

RCC->CR|=RCC_CR_PLLON;//enab pll

while (!(RCC->CR&RCC_CR_PLLRDY));

RCC->CFGR=RCC_CFGR_PPRE2_2|RCC_CFGR_PPRE1_2;

RCC->CFGR|=RCC_CFGR_SW_PLL;//sys clock-pll

FLASH->ACR|=FLASH_ACR_LATENCY_4WS;

for (i=0;i<500;i++);

//set rcc

RCC->AHB1ENR|=RCC_AHB1ENR_GPIOAEN|RCC_AHB1ENR_GPIOBEN| RCC_AHB1ENR_GPIOCEN|RCC_AHB1ENR_GPIODEN|RCC_AHB1EN R_GPIOEEN;

RCC->AHB1ENR|=RCC_AHB1ENR_ETHMACRXEN|RCC_AHB1ENR_ETHMA CTXEN|RCC_AHB1ENR_ETHMACEN;

RCC->APB2ENR|=RCC_APB2ENR_SYSCFGEN;

SYSCFG->PMC=SYSCFG_PMC_MII_RMII_SEL;

//set gpio

GPIOA->MODER|=GPIO_MODER_MODER7_1|GPIO_MODER_MODER2_1|GP IO_MODER_MODER1_1;

GPIOB->MODER|=GPIO_MODER_MODER13_1|GPIO_MODER_MODER12_1| GPIO_MODER_MODER11_1;

GPIOC->MODER|=GPIO_MODER_MODER5_1|GPIO_MODER_MODER4_1|GP IO_MODER_MODER1_1;

GPIOD->MODER|=GPIO_MODER_MODER8_0;//pin 8-0utput

GPIOE->MODER|=GPIO_MODER_MODER12_0;//pin 12-0utput

GPIOA->OSPEEDR|=GPIO_OSPEEDER_OSPEEDR7|GPIO_OSPEEDER_OSP EEDR2|GPIO_OSPEEDER_OSPEEDR1;

GPIOB->OSPEEDR|=GPIO_OSPEEDER_OSPEEDR14|GPIO_OSPEEDER_OS PEEDR13|GPIO_OSPEEDER_OSPEEDR12|GPIO_OSPEEDER_OSPE EDR11;

GPIOC->OSPEEDR|=GPIO_OSPEEDER_OSPEEDR5|GPIO_OSPEEDER_OSP EEDR4|GPIO_OSPEEDER_OSPEEDR1;

GPIOA->AFR[0]|=0xB0000BB0;//mac

GPIOB->AFR[1]|=0x00BBB000;//mac

GPIOC->AFR[0]|=0x00BB00B0;//mac

//config LAN8720

GPIOE->ODR=GPIO_ODR_ODR_12;//rst=1

while (ETH->MACMIIAR&0x00000001);//busy=1

ETH->MACMIIDR=0x00001000;//auto-negotiation

ETH->MACMIIAR=0x00000803;//adr=1, reg=0,write

while (ETH->MACMIIAR&0x00000001);

for (i=0;i<50000;i++)

{

ETH->MACMIIAR=0x00000fc1;//adr=1, reg=31,read

while (ETH->MACMIIAR&0x00000001);

while (!(ETH->MACMIIDR&0x00001000))//auto-neg done?

{//no

GPIOD->ODR&=~GPIO_ODR_ODR_8;

ETH->MACMIIAR=0x00000fc1;//adr=1, reg=31,read

while (ETH->MACMIIAR&0x00000001);

}

GPIOD->ODR|=GPIO_ODR_ODR_8;

}

for (i=0;i<50000;i++);

GPIOD->ODR&=~GPIO_ODR_ODR_8;

for (i=0;i<5000000;i++);

//config MAC

ETH->MACCR=0x00008000;//

switch(ETH->MACMIIDR)

{

case 0x00001044:ETH->MACCR|=0x00008000;//10,h

break;

case 0x00001054:ETH->MACCR|=0x00008800;//10,f

break;

case 0x00001048:ETH->MACCR|=0x0000c000;//100,h

break;

case 0x00001058:ETH->MACCR|=0x0000c800;//100,f

GPIOD->ODR|=GPIO_ODR_ODR_8;

for (i=0;i<500000;i++);

GPIOD->ODR&=~GPIO_ODR_ODR_8;

for (i=0;i<5000000;i++);

break;

default: GPIOD->ODR|=GPIO_ODR_ODR_8;

while (1);

break;

}

ETH->MACCR|=ETH_MACCR_RE;//enable receive

ETH->MACFFR=ETH_MACFFR_RA;//all frames receive

while (!(ETH->MACDBGR&0x0000ffff))

{

GPIOD->ODR|=GPIO_ODR_ODR_8;

}

while(1)

{

GPIOD->ODR|=GPIO_ODR_ODR_8;

for (i=0;i<500000;i++);

GPIOD->ODR&=~GPIO_ODR_ODR_8;

for (i=0;i<500000;i++);

}

}

The problem is, that no bit with numbers from 0 to 15 in register MACDBGR is set 1.

But the PLL is working, the frerquiency of the CPU clock is 64 MHz. Lan8720 is configured, it indicates that the speed of the ethernet is 100 Mbps and the mode is full-duplex.

Where do I mistake in the code?

Thank You!

6 REPLIES 6
kashubadmitry
Associate II
Posted on April 11, 2017 at 05:15

Hi all!

Maybe I must start study the Ethernet from example!

I heard, that there is a own 

software development environment on st.com site! I need to use this program, STM32cubemx, RTOS and some files from st.com site to create the project with tcp server (Etherner) example. 

Could anybody tell me what must I do step by step to create such example!

Thank You!

Imen.D
ST Employee
Posted on April 11, 2017 at 11:03

Hi,

Regarding the way to start in order to develop your application, you have various choices:

 You'll probably want to review Ethernet examples as you can find under STM32CubeF4:

STM32Cube_FW_F4_V1.15.0\Projects\STM32469I_EVAL\Applications\LwIP

 You can also start your own application using STM32CubeMx tool to initialize peripherals you need with the configuration you want and you may re-use sections available in the examples or get inspired from them.

You can refer to the reference manual RM0090 it provides complete information on how to use the STM32F4xx microcontroller memory and peripherals.

Have a look to these documents:

-

http://www.st.com/content/ccc/resource/technical/document/user_manual/79/6e/5f/d4/5c/25/43/96/DM00103145.pdf/files/DM00103145.pdf/jcr:content/translations/en.DM00103145.pdf

 STM32Cube Ethernet IAP example, it maybe helpful as it provides a full description of how to implement In-Application Programming (IAP) using Ethernet communication.

-

http://www.st.com/content/ccc/resource/technical/document/application_note/fd/5d/64/cf/7c/38/4c/30/DM00036052.pdf/files/DM00036052.pdf/jcr:content/translations/en.DM00036052.pdf

'LwIP TCP/IP stack demonstration for STM32F4x7 microcontrollers� .

-

http://www.st.com/content/ccc/resource/technical/document/user_manual/65/e8/20/db/16/36/45/f7/DM00103685.pdf/files/DM00103685.pdf/jcr:content/translations/en.DM00103685.pdf

is a user manual about “Developing applications on STM32Cube with LwIP TCP/IP stack�.

Hope this help you to go further in your application.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
kashubadmitry
Associate II
Posted on April 14, 2017 at 14:26

Hi!

I did the next:

- I connected PC to LAN8720 throught ethernet cable, LAN8720 connected to stm32f407-discovery board

- Downloaded STSW-STM32070 with STM32F4x7_ETH_LwIP_V1.1.1  from st.com

- opened the project \freertos\httpserver_netconn.... in KEIL

- uncommented '#define RMII_MODE' and commented '//#define MII_MODE' in main.h file

- built the projected and programmed the flash memory of stm32f407

- changed ip address of the PC to 192.168.0.11

- opened the wireshark on the PC

- there were no packets from stm32f407 (ip 192.168.0.10), but the LEDs on ethernet connector of the PC and LAN8720 were blinking!!!!!!!!

What is wrong, tell me please?

Thank You!

kashubadmitry
Associate II
Posted on April 17, 2017 at 09:17

Hi all!

I have some results!!!!

After some correction in the project,  that was described in previous message of this forum, now, when I do 'ping 192.168.0.10' from PC in wireshark I see the next strings:

d4:3d:7e:d7:fe:a8

      

Broadcast ARP

        

Who has 192.168.0.10?  Tell 192.168.0.11

02:00:00:00:00:00

    

d4:3d:7e:d7:fe:a8

       

ARP 192.168.0.10 is at 02:00:00:00:00:00 (looks good)

192.168.0.11

             

192.168.0.10

             

ICMP Echo (ping) request  (id=0x0001, seq(be/le)=26/6656, ttl=128)

-in wireshark there is no Echo reply packets from 

192.168.0.10. What is wrong?

I did the next:

- example project is the same as in previous message:

\freertos\httpserver_netconn//MDK-ARM/Project.uvproj

 ;

- in file 'main.h' I commented '#define USE_DHCP' and '

#define MII_MODE', uncommented '//

#define RMII_MODE'

;

- in file 'stm32f4x7_eth_bsp.c' in function 'ETH_MACDMA_Config()' the next strings:

     ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;

     // ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Disable;

     // ETH_InitStructure.ETH_Speed = ETH_Speed_10M;

     // ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex;

   I changed to the next strings:

//ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;

ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Disable;

ETH_InitStructure.ETH_Speed = ETH_Speed_100M;

ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex;

- in file '

stm32f4x7_eth_bsp.c' in function 'ETH_GPIO_Config

()' the next strings:

/* Configure PB5 and PB8 */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_8;

GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_ETH);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_ETH);

/* Configure PG11, PG14 and PG13 */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_13 | GPIO_Pin_14;

GPIO_Init(GPIOG, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOG, GPIO_PinSource11, GPIO_AF_ETH);

GPIO_PinAFConfig(GPIOG, GPIO_PinSource13, GPIO_AF_ETH);

GPIO_PinAFConfig(GPIOG, GPIO_PinSource14, GPIO_AF_ETH);

 I changed to the next strings:

   

/* Configure PB11, PB12 and PB8 */

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_PinSource

13

, GPIO_AF_ETH);

/* Configure PG11, PG14 and PG13 */

//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_13 | GPIO_Pin_14;

//GPIO_Init(GPIOG, &GPIO_InitStructure);

//GPIO_PinAFConfig(GPIOG, GPIO_PinSource11, GPIO_AF_ETH);

//GPIO_PinAFConfig(GPIOG, GPIO_PinSource13, GPIO_AF_ETH);

//GPIO_PinAFConfig(GPIOG, GPIO_PinSource14, GPIO_AF_ETH);

Thank You!

Posted on April 19, 2017 at 08:30

 ,

 ,

Hi everybody!

As I said:

- ,I connected PC to LAN8720 throught ethernet cable, LAN8720 connected to stm32f407-discovery board

- Downloaded ,STSW-STM32070 with STM32F4x7_ETH_LwIP_V1.1.1  ,from st.com

- ,built now

 ,the project \standalone\httpserver\mdk-arm\project in KEIL

when I do 'ping 192.168.0.10' from PC in wireshark I see the next strings:

 ,

 ,

d4:3d:7e:d7:fe:a8

 ,  ,  , ,

Broadcast ARP

 ,  ,  ,  , ,

Who has 192.168.0.10?  ,Tell 192.168.0.11

 ,

02:00:00:00:00:00

 ,  , ,

d4:3d:7e:d7:fe:a8

 ,  ,  ,  ,

ARP 192.168.0.10 is at 02:00:00:00:00:00 (looks good)

192.168.0.11

 ,  ,  ,  ,  ,  ,  ,

192.168.0.10

 ,  ,  ,  ,  ,  ,  ,

ICMP Echo (ping) request  ,(id=0x0001, seq(be/le)=26/6656, ttl=128)

 ,

-in wireshark there are ,no Echo reply packets from ,

192.168.0.10.

I have 2 questions:

1 why does program go to this structure in function

'err_t ip_input(struct pbuf *p, struct netif *inp)' in ,

file ip.c and not goes away for ICMP check?

here the structure:

/* packet not for us? */

 ,

if (netif == NULL)

 ,

{

 ,

/* packet not for us, route or discard */

 ,

LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ('ip_input: packet not for us.\n')),

 ,

♯ if IP_FORWARD

 ,

/* non-broadcast packet? */

 ,

if (!ip_addr_isbroadcast(¤t_iphdr_dest, inp))

 ,

{

 ,

/* try to forward IP packet on (other) interfaces */

 ,

ip_forward(p, iphdr, inp),

 ,

} else

 ,

♯ endif /* IP_FORWARD */

 ,

{

 ,

snmp_inc_ipinaddrerrors(),

 ,

snmp_inc_ipindiscards(),

 ,

}

 ,

pbuf_free(p),

 ,

return ERR_OK,

 ,

}

2 ,In file main.c in structure ,

if (ETH_CheckFrameReceived())

 ,

{

 ,

/* process received ethernet packet */

 ,

LwIP_Pkt_Handle(),

 ,

}

I set the check of the MAC receiver's flags in MACDBGR register and they all are 0, but some must be 1. Why it can be?

Thank You!

Posted on April 19, 2017 at 14:46

Why it can be, that 

(netif)->flags not equal NETIF_FLAG_UP, while there is the echo request from PC with ip address of STM32f407 192.168.0.10?

Thank You!