Skip to main content
Visitor II
August 26, 2022
Solved

netconn_connect() for TCP/IP connection is blocking at osSemaphoreAcquire(TxPktSemaphore,...) on my STM32F746ZG-Nucleo

  • August 26, 2022
  • 4 replies
  • 4301 views

I try to implement a TCP/IP client on my STM32F746ZG-Nucleo.

Before the last update it was working. But no more now.

The first pass I always get a ERR_RTE because the ethernet link is not up. So I tried to connect each 5 secondes 5 times.

But the second pass, the link is up and everything seems good except one thing.

The program stay blocked on trying to acquire the semaphore :

 HAL_ETH_Transmit_IT(&heth, &TxConfig);
 while(osSemaphoreAcquire(TxPktSemaphore, TIME_WAITING_FOR_INPUT)!=osOK)
 
 {
 }
 
 HAL_ETH_ReleaseTxPacket(&heth);

Even if I wait 5 sec before trying to connect at the start, it will stay blocked at the exact same line.

I tried to add "netconn_set_nonblocking(conn, true);" but doesn't change anything.

Here is my configuration :

void StartDefaultTask(void *argument)
{
 /* init code for LWIP */
 MX_LWIP_Init();
 /* USER CODE BEGIN 5 */
 allInitCompleted = true;
 
	/* Infinite loop */
	for(;;)
	{
		osDelay(100);
	}
 /* USER CODE END 5 */
}

And the function called my client thread to start the connection :

void ComChanEth::openConnection() {
	err_t err;
	setState(COMCHAN_CONNECTING);
 
	// Create a new connection identifier
	conn = netconn_new(NETCONN_TCP);
 
	netconn_set_nonblocking(conn, true);
 
	if (conn)
	{
		// Bind connection to the port number 7 (port of the Client)
		err = netconn_bind(conn, IP_ADDR_ANY, MY_ETH_PORT);
 
		if (err == ERR_OK)
		{
			for(uint8_t nbTry = 0; nbTry < MAX_TRY_ETH_CONNECT; nbTry++)
			{
				// Start TCP/IP connection
				err = netconn_connect(conn, getServerAddress(), getServerPort());
 
				// If the connection is established, exit the loop
				if (err == ERR_OK)
				{
					setState(COMCHAN_CONNECTED);
					break;
				}
				else
					osDelay(5000); // Retry in 5 seconds
			}
			// If the connection has been established after 5 try, delete the connection
			if (err != ERR_OK)
				closeConnection();
		}
		else
		{
			// If the binding wasn't successful, delete the netconn connection
			closeConnection();
		}
	}
}

Does anyone have an idea ? or need more information to help me ?

    This topic has been closed for replies.
    Best answer by Zuffouille

    Thanks @Piranha​ =)

    To answer my question :

    https://community.st.com/s/question/0D53W00001oImr4SAC/bug-stm32-lwip-ethernet-driver-tx-deadlock?t=1666859452326&searchQuery

    Like you said, in general for Ethernet issue :

    https://community.st.com/s/question/0D50X0000BOtfhnSQB/how-to-make-ethernet-and-lwip-working-on-stm32

    Thanks for your big help

    Zuffouille

    4 replies

    Super User
    August 28, 2022

    > Before the last update it was working

    What are versions of the "HAL" library or ethernet driver before and after the 'last update'?

    Visitor II
    August 29, 2022

    I'm not sure were to look for version number.

    So I searched "version" in my entire project.

    Before update :

    File.Version=6

    LWIP.Version=v2.1.2_Cube

    MxCube.Version=6.5.0

    MxDb.Version=DB.6.0.50

    After update :

    File.Version=6

    LWIP.Version=v2.1.2_Cube

    MxCube.Version=6.6.1

    MxDb.Version=DB.6.0.60

    ZuffouilleAuthorAnswer
    Visitor II
    October 27, 2022