cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure KSZ8081 in MII mode with CubeMX?

Noname1937
Associate III

Hello, I made a customboard using STM32f217VET microcontroller and KSZ8081 PHY (builtin pull-up resistors for TXP TXM and RXP RXM). I Configured my board to use MII mode, anda I used a 25MHz oscillator to do so.

As you can see it is missing a 1k pull-up resistor for the INTRP pin, but I have already fixed this by wiring up a resistor in pin 32. Now it works accordingly.

As of this moment I have tried 3 approaches to make this work (it is connected to a point that supports DHCP and is always assigned the same IP).

I initially tried to configure freeRTOS + lwIP with a custom PHY, since DP83843 was the only one on the list in cubeMX. With this I was never even able to get a link is up when reading the registers and auto-negotiation never completed. Not to mention that I was unable to receive any data from pins RXD0..RXD3 , even though I can see the differential input data in the RJ45 pins when I ping my board and I can see a 25MHz clock in RX_CLK pin. I just don't get any data. (I didn't try to see if it was sending data, yet)

Then tried using freeRTOS + lwIP using the default and only PHY available in cubeMX (DP83843). This apparently gave me a better result, it at least detects that the link is up, but still DHCP doesn't get any IP, but strangely I can see the same data in RX_Buff and TX_Buff (default DMA buffers created by cubeMX). Apparently It is seing the data and receiving it automatically? I doubt it, since it is not configured to be in loopback mode. I even followed some russian guide in youtube, which basically stated that I can ping my device without doing any modifictions to the source or at least I didn't see him do any modifications. https://www.youtube.com/watch?v=jGYQBLauvQo

Afterwards I tried the most used method in tutorials online. lwIP baremetal. After the generated code I had to insert MX_LWIP_Process in the main loop, but still nothing.

OBS: I tried both enabling DHCP and forcing static IP.

The difference between tries 1 and 2 is the following modified code:

/* USER CODE END PHY_PRE_CONFIG */
#if 0 // Remove code to configure interrupt and change according to datasheet
 
  /**** Configure PHY to generate an interrupt when Eth Link state changes ****/
  /* Read Register Configuration */
  HAL_ETH_ReadPHYRegister(&heth, PHY_MICR, &regvalue);
  
  regvalue |= (PHY_MICR_INT_EN | PHY_MICR_INT_OE);
 
  /* Enable Interrupts */
  HAL_ETH_WritePHYRegister(&heth, PHY_MICR, regvalue );
 
  /* Read Register Configuration */
  HAL_ETH_ReadPHYRegister(&heth, PHY_MISR, &regvalue);
  
  regvalue |= PHY_MISR_LINK_INT_EN;
#endif    
 
  HAL_ETH_ReadPHYRegister(&heth, PHY_BCR, &regvalue);
 
   /* Read Register Configuration */
  HAL_ETH_ReadPHYRegister(&heth, 0x1BU, &regvalue);
  
  regvalue |= 0xFF00U; // Enable all interrupts
 
  /* Enable Interrupts */
  HAL_ETH_WritePHYRegister(&heth, 0x1BU, regvalue );
 
  /* Read Register Configuration */
  HAL_ETH_ReadPHYRegister(&heth, 0x1FU, &regvalue);
  
  regvalue |= (1U << 13U);
  /* Configure interrupt so that whenever an interrupt occurs a high level occurs. */
  HAL_ETH_WritePHYRegister(&heth, 0x1FU, regvalue);

The code inside the "#if 0" is the coded provided by cubeMX and the rest is my code that I added to configure my PHY in my first try. This can be found in ethernetif.c near line 333

I have added projects 2 and 3 as attached files so everyone can see what I was doing, even if it was wrong. Attempt 1 differs from 2 just by the code snippet I added above.

I know that using my own board makes it harder to debug and for you to help me, but I have searched for projects that use MII instead of RMII and my connections are identical, even though the uC differs (from STM32f217 to STM32f439). Also I have an Olimex E407 board fi you have any suggestions for me to try (I know someone that has made freeRTOS and lwIP to work in the Olimex board, but I am unable to contactg this person at the moment)

Any suggestions? Help?

EDIT:

I just need to get this board to ping right now. If it pings I know that it is getting an IP and the stack is working ... after that I can do anything else, but I can't even ping it at the moment .. much less get an IP

If necessary I can post the register values from the PHY or even probe something on my board

EDIT2:

Just saw something i the datasheet that the guy that made the hardware didn't see. He used a J0026D RJ45 jack, which has integrated magnetics. Seeing KSZ8081's datasheet for the 20th time I noticed that since the differential TX and RX lines are alread terminated inside the PHY, the center tap pins should be connected to ground with individual 0.1u. In the board the center tap pins are connected to 3v3. I'll try to cut the connections to 3v3 and insert the caps. 

3 REPLIES 3
Amel NASRI
ST Employee

"Here's my original schematic:"

If it is an image, You need to use the "Image" icon (Mountain + moon).

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Noname1937
Associate III

Ok. Just edited the image

Noname1937
Associate III

@Amel NASRI​ Ok. Just added the image and 2 2 more pieces of information.