first of all, I would like to describe my problem before going into my development environment.
My problem is that with FreeRTOS+TCP during initialisation on my development kit STM32H735G-DK the socket status does not go beyond eCONNECT_SYN. After a timeout of 3* 500ms the IP stack gives up and changes to eCLOSE_WAIT.
In my development environment I use several libraries. An overview is shown in the schema.
I have already checked the clocks and IOs on the DK. It turned out that the clocks are present on the PHY LAN8742, but no data is coming to the RMII.
The PHY initialisation seems to be successful.
The various examples and demo applications I have looked at do not help me. It feels like looking for a needle in a haystack.
My request:
Does anyone have any ideas and suggestions that I can follow up on?
Have you made sure that the Ethernet ISRs are enabled, and are getting triggered? You should see something like this in the HAL_ETH_MspInit() or similar ETH init. code:
yes, I have defined ipconfigUSE_NETWORK_EVENT_HOOK.
The called function is defined with:
#if (ipconfigUSE_NETWORK_EVENT_HOOK == 1)
/// @brief application defined hook (or callback) function
/// that is called by the TCP/IP stack when the network either connects or disconnects. As the
/// function is called by the TCP/IP stack the TCP/IP sets sets the value of the function's
/// parameter.
/// @param eNetworkEvent eNetworkUp if network connected, eNetworkDown if network disconnected
/// @remark
/// https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/vApplicationIPNetworkEventHook.html
void vApplicationIPNetworkEventHook(eIPCallbackEvent_t eNetworkEvent) {
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
char cBuffer[ 16 ];
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if( eNetworkEvent == eNetworkUp )
{
/* Create the tasks that use the IP stack if they have not already been
* created. */
if( xTasksAlreadyCreated == pdFALSE )
{
/* See the comments above the definitions of these pre-processor
* macros at the top of this file for a description of the individual
* demo tasks. */
#if ( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 )
{
vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
}
#endif /* mainCREATE_TCP_ECHO_TASKS_SINGLE */
xTasksAlreadyCreated = pdTRUE;
}
/* Print out the network configuration, which may have come from a DHCP
* server. */
#if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 )
FreeRTOS_GetEndPointConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
#endif
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "IP Address: %s", cBuffer ) );
FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
FreeRTOS_printf( ( "Subnet Mask: %s", cBuffer ) );
FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
FreeRTOS_printf( ( "Gateway Address: %s", cBuffer ) );
FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
FreeRTOS_printf( ( "DNS Server Address: %s", cBuffer ) );
}
else
{
FreeRTOS_printf( ( "Application idle hook network down\n") );
}
}
#endif // ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
With Debug I could see that mainCREATE_TCP_ECHO_TASKS_SINGLE is not defined and the function vStartTCPEchoClientTasks_SingleTasks() is not called.
At the moment I do not know if this is necessary.
The function FreeRTOS_connect() is called but the result of xEventGroupWaitBits() returns the event eSOCKET_CLOSED.
At Wireshark I could see no activity from HW STM32H735G-DK, only standard queries from my PC.
Ok, I will disable all my MQTT stuff and test only TCP/IP stack.
Thanks for your link to your project. Maybe it helps.
Seems like you are not getting any RX packets (assuming the IP address is assigned statically). Can you also share the FreeRTOSIPConfig.h. Also are you using the stm32hxx_hal_eth.c provided in the network interface folder for STM32Hxx in the FreeRTOS+TCP or the default version from the Drivers/STM32H7xx_HAL_Driver/Src?
Haven’t checked how HAL_GPIO_Init() is implemented by ST HAL but please make sure if you need to configure the GPIO_InitStructure with right GPIO alternate function, mode, etc before each call to HAL_GPIO_Init.
Ok, I’m a new user and therefore I can’t share files directly.
My FreeRTOSIPConfig.h is (based on FreeRTOS+TCP V3.1.0):
/*
* FreeRTOS+TCP V3.1.0
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#include <stdlib.h> // rand()
#define _static
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configDEBUGPRINTF( X )
#endif
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define FreeRTOS_htons( usIn ) ( ( uint16_t ) ( ( ( usIn ) << 8U ) | ( ( usIn ) >> 8U ) ) )
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
#define ipconfigRAND32() rand()
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
#define ipconfigUSE_DHCP 0
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigUSE_DHCP_HOOK 1
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD \
( 120000U / portTICK_PERIOD_MS )
#define ipconfigARP_CACHE_ENTRIES 6
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
#define ipconfigMAX_ARP_AGE 150
#define ipconfigINCLUDE_FULL_INET_ADDR 1
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 64
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
#define ipconfigUDP_TIME_TO_LIVE 128
#define ipconfigTCP_TIME_TO_LIVE 128
#define ipconfigUSE_TCP ( 1 )
#define ipconfigUSE_TCP_WIN ( 1 )
#define ipconfigNETWORK_MTU 1200U
#define ipconfigUSE_DNS 1
#define ipconfigREPLY_TO_INCOMING_PINGS 1
#define ipconfigSUPPORT_OUTGOING_PINGS 1
#define ipconfigSUPPORT_SELECT_FUNCTION 1
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS )
#define ipconfigPACKET_FILLER_SIZE 2U
#define ipconfigTCP_WIN_SEG_COUNT 240
#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 )
#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 )
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 0 )
#define ipconfigUSE_NBNS ( 0 )
#define ipconfigUSE_LLMNR ( 0 )
#define ipconfigZERO_COPY_RX_DRIVER ( 1 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 1
#define ipconfigDNS_USE_CALLBACKS 0
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#endif /* FREERTOS_IP_CONFIG_H */
I have removed all comments.
Yes, I’m using stm32hxx_hal_eth.c
Additionally I had added a function HAL_ETH_SetMDIOClockRange() which is called from NetworkInterface.c, fct. xNetworkInterfaceInitialise(). This I used from FreeRTOS+TCP V3.1.0.
The pins for GPIO handling I have checked for my board.
For alternate function I’m using GPIO_AF11_ETH from stm32h7xx_hal_gpio_ex.h:
#if defined(ETH)
#define GPIO_AF11_ETH ((uint8_t)0x0B) /* ETH Alternate Function mapping */
#endif /* ETH */
The HAL driver I took from stm32h7xx_hal_driver v1.11.1
Where is the ETH_TX_BUF_SIZE and ETH_RX_BUF_SIZE defined and to what value? Can you try using the FreeRTOSIPConfig.h used in the project linked by @htibosch.
Together with a colleague, we were able to find the cause of the problem. The article [Ethernet not working on STM32H7x3] in ST community describes which adjustments are necessary. After moving the Ethernet data to the D2 domain of the SRAM with the MPU active, we could achieve data transfer. The previous configuration for AXI-SRAM on the D1 domain was wrong.