Loading...
 

System Workbench for STM32


STM32CubeMX LWIP not working

I have just started experimenting with ST products. I have a STM32F4 Discovery board. I bought a DP83848 PHY on Ebay and connected it to the Discovery board. I downloaded a hex file from here:http://blog.tkjelectronics.dk/2012/08/ethernet-on-stm32f4discovery-using-external-phy/Question

I am able to ping the board and access the web page with no issues.

I then used CubeMX to create a project with nothing but LWIP and two GPIO pins. I figured I would start out simple. The goal was to see if I could get LWIP working. I generated the code and imported it into System Workbench and used STLink to program the board.

I cannot ping the board (I enabled ICMP in CubeMX) and it does not make a DHCP request. I know the request is not being made because Wireshark never sees it.

Do I have to put anything in the main() while loop for lwip to work? Do I need to make any modifications to use the DP83848? I noticed in CubeMX that in the Ethernet Settings, it states LAN8742A for the PHY. Maybe this is my issue? If so, what modifications need to be made to tell CubeMX to use the DP83848?

I have been working on this for two days and making zero progress. I am using Windows XP and the latest versions of CubeMX and System Workbench

Hi rcbuck,

Check if the configuration of GPIO clocks are suitable.
The following 3 functions must be called for enabling ethernet clock:
__HAL_RCC_ETHMAC_CLK_ENABLE();
__HAL_RCC_ETHMACTX_CLK_ENABLE();
__HAL_RCC_ETHMACRX_CLK_ENABLE();

Furthermore, you may verify if the following GPIO pin are configured in Input mode
ETH_CRS, ETH_RX_CLK, ETH_COL, ETH_TX_CLK, ETH_RX_DV, ETH_RX_D0, ETH_RX_D1, ETH_RX_D2, ETH_RX_D3

Souleymane
AC6

Souleymane,

I confirmed all of the clocks are enabled and the GPIO pins are in Input mode. So ST32CubeMX generated that code properly.

If I modify the code to put in the MAC address that is used by the Hex code(that works) that I downloaded from the other website, Wireshark sees the board when it is started:
2 12.739183 0.0.0.0 255.255.255.255 DHCP 350 DHCP Discover - Transaction ID 0x5851f42d
3 12.740327 44:8a:5b:d3:4c:8b Broadcast ARP 60 Who has 172.16.1.109? Tell 172.16.1.1__

But the board doesn’t respond when the DHCP server asks “who has 172.16.1.109”. That is the IP address that the server assigns to the Hex file that does work. The DHCP entry is still in the lease table of the server, so the server knows that MAC address is supposed to be 172.16.1.109.

I’m sure the problem is related to me using the DP83848 instead of the LAN8742A PHY. But I don’t know what to modify to correct the problem.

Ray

Hello,
I am also facing similar issue, its been an year since your last post,. I hope you might have got it working. If so, can you pls post the solution that you had found. That would be useful for newbies of STM32F4-Discovery like myself.

Thanks in advance
Srinivasan


Srinivasan,

Yes, I got it working. I zipped up my code and you can download it from this link:

https://we.tl/t-6nBJYiIcJbQuestion

The name of the file is STM_Ethernet.zip. The link will remain valid for 7 days.

I presently do not have any STM development tools installed on my computer so I cannot be of further assistance. Hopefully my source code will help you to solve your problem.

Ray

Thanks a bunch.

I know its been a year after your initial post. However, do you remember what was the solution that you found? If so, i request you to post it here, so that it might be beneficial for others as well.

I am having the same issue.
Do you mind sharing the code once again?

-thanks


Srinivasan,

Unfortunately I do not remember what the solution was. After I got it working I put everything away and haven’t worked with the STM32 parts since then. I may do some work with STM parts in the future, but at this point I have moved onto other projects.

You can compare my code to your code and possibly find what makes your project work. As a first test, you could load my hex file that is in the Release folder into your board and see if it works.

Ray

Ray,
I could finally solve the issue with my TCP IP connection.

In the new version of STM32F4-Discovery which is now known as STM32F407G-DISC1, it looks like PHY chip seems to be LAN_8742A instead of LAN_8720 as it was in earlier version.

STMCube selection of LAN_8742A “did not” set the right set of External PHY configuration parameters. For example, when we select ETH in STMCUBE for STM32F4-discovery board selection, the default selection of PHY was LAN_8742A_PHY and with PHY address as 1 and other values set accordingly.

With those values, the issue found was the HAL_ETH_GetReceivedFrame function always failed to pass through the following statement if(((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET)) returning HAL_ERROR everytime.

When I had changed this PHY_ADDRESS to 0 and few other PHY parameters in accordance with 8742A registers, we could get the TCP communication working..

Thanks for your support and taking your time in digging and sharing out your old code :-)

- Srinivasan

Srinivasan,
I’m also have the same problem as you did.
I have tried with PHY_ADDRESS 0, but no luck.
Can you please share what other PHY parameters you changed.

Thanks in advance
Mats

Thank you Srinivasan.

I got the same problem .
I use a STMF429ZI Nucleo and the CubeMx default configuration was setting the PHY address to 1 .
I just change the PHY Address to 0 and now it works


Srinivasan,
I’m also have the same problem as you did.
I have tried with PHY_ADDRESS 0, but no luck.
Can you please share what other PHY parameters you changed.

Thanks in advance
Mats

Mats,
Sorry for the delayed response.

Other parameters that we have changed are in the section, ETH configuration -> Advanced Parameters -> Extended: External PHY configuration
and the values are as below
PHY Special Control/Status register Offset - 0x1F
PHY Speed Mask - 0x0004
PHY Duplex Mask - 0x0010
PHY Interrupt Source Flag Register Offset - 0x001D
PHY Link Down Interrupt - 0x0010

Its been a long time, I dont remember the basis for the above change. Good luck.

No worries,

I got it working.

Thank’s for the reply.
Mats


I have uploaded 2 files to uploadfiles.io.

There is a file named STM_Ethernet.zip that is at http://ufile.io/57k7jQuestion and a file named LWIP-Ethernet.hex that is at https:/ufile.io/s8kfq.

The zip file contains the source files that I used to make my board work. I haven’t worked with STM32 parts in a couple of years so I won’t be able to offer any help if your board does not work.

If you unzip the file and look in the STMNew/Eth-Test/Src folder, you will see a file named lwip.c. Within that file there is a function named MX_LWIP_Init where the IP address and Netmask are assigned statically. I have them set to 172.16.1.177/255.255.255.0. You can chage the IP address to match your subnet, recompile the code, and program your board.

If you happen to be using a subnet of 172.16.1, you can program you board with the hex file that I built for my board. That file is named Eth-test.hex and is located in the STMNew/Eth-Test/Release folder. You should then be able to ping the board at 172.16.1.177.

The LWIP-Ethernet.hex can be used to verify if your hardware is working. It uses dhcp to obtain an IP address from your network DNS server. If you program your board with the hex file, you will be able to open a webpage by using a web browser to connect to the IP address that the board obtains from your DNS server.

Both hex files assume you are using a STM32F407 processor and a DP83848 Ethernet Phy device.

Good luck with your project.



hi Srinivasan ,
you link was useful and am facing same issue on STM32F417.
I used STM32 Cube Mx to generate the code for LAN8720A.
I have followed your setting here :
i have set PHY_Address = 0
PHY Special Control/Status register Offset - 0x1F
PHY Speed Mask - 0x0004
PHY Duplex Mask - 0x0010
PHY Interrupt Source Flag Register Offset - 0x001D
PHY Link Down Interrupt - 0x0010

i have attached the screenshot of cubemx settings
With this current setting i am not able to get reply for ping request.
(hardware is tested with ping by other hex code).
Can you help me to fix up this issue ?
Prabu.A



hi all ,
i have verified the offset of LAN8720 in the datasheet and its fine.
PHY Special Control/Status register Offset - 0x1F
PHY Interrupt Source Flag Register Offset - 0x001D
other values i couldn’t verify with datasheet.

When i set PHY_address is set 0 , the tow LED’s on the Ethernet connector is OFF.
So i had to set to 1 .anyway for both case i didn’t get ping reply from STM32F417.
As i said hardware has been verified already with hex file and ping was working fine.
So its clear that the configuration issue in my code .

This is my code :

int main(void)
{


/* MCU Configuration----------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();



/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
// MX_CRC_Init();
// MX_I2C1_Init();
// MX_I2C2_Init();
// MX_IWDG_Init();
// MX_RNG_Init();
// MX_SPI1_Init();
// MX_TIM3_Init();
// MX_TIM5_Init();
// MX_TIM8_Init();
// MX_TIM11_Init();
// MX_USART1_UART_Init();
// MX_USART3_UART_Init();
// MX_USB_OTG_HS_HCD_Init();
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
MX_LWIP_Init();
/* USER CODE BEGIN 2 */

// HAL_UART_Receive_IT(&huart1, rx_ser_buffer1, sizeof(rx_ser_buffer1));
// // Disable DE -> Enable /RE
// HAL_GPIO_WritePin(TSI_DE_GPIO_Port, TSI_DE_Pin, GPIO_PIN_RESET);
// dma_restart(&huart1, rx_ser_buffer3, sizeof(rx_ser_buffer3));
// HAL_UART_Receive_IT(&huart3, rx_ser_buffer3, sizeof(rx_ser_buffer3));
/* USER CODE END 2 */

static int state = 0;
while (1)
{

state = ~state;
MX_LWIP_Process();
HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, (state != 0 ? GPIO_PIN_SET : GPIO_PIN_RESET));
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, (state != 0 ? GPIO_PIN_SET : GPIO_PIN_RESET));
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, (state != 0 ? GPIO_PIN_SET : GPIO_PIN_RESET));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, (state != 0 ? GPIO_PIN_SET : GPIO_PIN_RESET));
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, (state != 0 ? GPIO_PIN_SET : GPIO_PIN_RESET));
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, (state != 0 ? GPIO_PIN_SET : GPIO_PIN_RESET));
HAL_GPIO_WritePin(LED6_GPIO_Port, LED6_Pin, (state != 0 ? GPIO_PIN_SET : GPIO_PIN_RESET));
HAL_Delay(200);
//HAL_IWDG_Refresh(&hiwdg);
/* Handle LwIP timeouts */

}
}

Is there any other setting to be done ? appreciate for your great help