# FreeRTOS-Plus-TCP - Support for new STM32Fxx Ethernet HAL

**URL:** <https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630>\
**Category:** Libraries\
**Created:** [June 13, 2023, 5:54am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630 "2023-06-13T05:54:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![heering](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/heering/32/3610_2.png) [@heering](https://forums.freertos.org/u/heering)\
**Post date:** [June 13, 2023, 5:54am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/1 "2023-06-13T05:54:00Z")

</div>

Is there a plan to support the new STM32Fxx Ethernet HAL implementation?  
The current ST CubeMX version has no option to auto-generate the legacy Ethernet HAL implementation. This behavior breaks the FreeRTOS-Plus-TCP port for STM32Fxx.

I’m not allowed to put a link here, so pls search for:  
_Ethernet HAL Driver reworked by ST and available in 22Q1_

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [June 15, 2023, 10:52pm UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/2 "2023-06-15T22:52:01Z")

</div>

When we created the ST32Fx driver, we used a copy of the HAL files. This would decrease the dependency on “the current HAL release”. It has been compiled and used with many versions of the HAL release.

Please have a look at this [stm32fxx\_hal\_eth.c](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/source/portable/NetworkInterface/STM32Fxx/stm32fxx_hal_eth.c). When compiling, it is recommended to hide similar files in your HAL library.

What you can also try is using this [experimental driver](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/pull/804). It makes full use of the HAL drivers that you provide.

> The current ST CubeMX version has no option to auto-generate the legacy Ethernet HAL implementation

The FreeRTOS+TCP library doesn’t make use of those possibilities.

---

<div class="post-metadata">

**Author:** ![ashvajit](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@ashvajit](https://forums.freertos.org/u/ashvajit)\
**Post date:** [February 19, 2024, 12:03pm UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/3 "2024-02-19T12:03:36Z")

</div>

Hello,  
I am trying to port FreeRTOSplus TCP to my STM32F746 FreeRTOS project (v. 202212.01). I have successfully ported FreeRTOS and have few task running. When I tried to port plusTCP using provided steps for FreeRTOSplus TCP.  
I am getting a lot of build errors, and I don’t know where I am going wrong.  
Most of the build errors are of HAL Ethernet APIs of STM32 drivers in Network interface.c .

Others are for FreeRTOSplus TCP library files.

- xApplicationDNSQueryHook (dns parser)
- vApplicationIPNetworkEventHook
- xApplicationGetRandomNumber
- ulApplicationGetNextSequenceNumber (tcp state handling)
- FreeRTOS\_debug\_printf (these i can comment out, right?)

My end goal is to make HTTP Client over ethernet on STM32.  
Are there any other steps that I can follow specifically for STM32?

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 19, 2024, 3:09pm UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/4 "2024-02-19T15:09:24Z")

</div>

Have you had a look at this [readme.md](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/source/portable/NetworkInterface/STM32Fxx/readme.md)?

Basicallay it says that you must remove or rename all existing versions of `*_hal_eth.[ch]`. Some are similar but too different to be useful.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 19, 2024, 3:14pm UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/5 "2024-02-19T15:14:00Z")

</div>

> Others are for FreeRTOSplus TCP library files.
> 
> - xApplicationDNSQueryHook (dns parser)
> - vApplicationIPNetworkEventHook
> - xApplicationGetRandomNumber
> - ulApplicationGetNextSequenceNumber (tcp state \> handling)
> - FreeRTOS\_debug\_printf (these i can comment out, right?)

Please check the documentation on each of the missing application hooks.

---

<div class="post-metadata">

**Author:** ![ashvajit](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@ashvajit](https://forums.freertos.org/u/ashvajit)\
**Post date:** [February 20, 2024, 5:48am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/6 "2024-02-20T05:48:35Z")

</div>

> [@htibosch](#):
>
> Basicallay it says that you must remove or rename all existing versions of `*_hal_eth.[ch]`. Some are similar but too different to be useful.

Yes, HAL related errors are fixed now after enabling `#define HAL_ETH_MODULE_ENABLED`  
But for the mentioned below function :

> [@htibosch](#):
>
> - xApplicationDNSQueryHook (dns parser)
> - vApplicationIPNetworkEventHook
> - xApplicationGetRandomNumber
> - ulApplicationGetNextSequenceNumber (tcp state \> handling)

After looking for these functions in documentation I found out that

> Callback functions are implemented by the application writer, but called by the TCP/IP stack

But in which file do I need to provide these definitions and where the prototypes should be placed?  
Also , looking at this [repo](https://github.com/koooge/coreHTTP-sample/tree/main), is it really important to include all of the files ?  
Are there any sample for stm32 that’s what I am looking for…

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 20, 2024, 8:22am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/7 "2024-02-20T08:22:45Z")

</div>

@ashvajit wrote:

> Also , looking at this repo, is it really important to include all of the files ?

FreeRTOS+TCP has 42 basic files, plus a few extra from `source/portable`.

I normally do not make a selection but add a use a wildcard in a makefile:

```make
    # add all library files
    C_SRCS += /
        $(wildcard $(PLUS_TCP_PATH)/source/*.c)

    # add files from portable
    C_SRCS += /
	    $(PLUS_TCP_PATH)/source/portable/BufferManagement/BufferAllocation_1.c \
		$(PLUS_TCP_PATH)/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c \
		$(PLUS_TCP_PATH)/source/portable/NetworkInterface/STM32Fxx/stm32fxx_hal_eth.c

```

Library files that are not needed will not be compiled, depending on macros like `ipconfigUSE_IPv6` and `ipconfigUSE_DNS`.

I wrote earlier:

> Please check the documentation on each of the missing application hooks.

An easy way to find the proper documentation is to open a search machine and look for “FreeRTOS xApplicationDNSQueryHook”.

This is how I just found the following pages:

[vApplicationIPNetworkEventHook\_Multi](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/vApplicationIPNetworkEventHook_Multi.html)  
[vApplicationIPNetworkEventHook](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/vApplicationIPNetworkEventHook.html)  
[xApplicationDNSQueryHook\_Multi](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/xApplicationDNSQueryHook_Multi.html)  
[xApplicationDNSQueryHook](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/xApplicationDNSQueryHook.html)  
[xApplicationGetRandomNumber](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/xApplicationGetRandomNumber.html)  
[ulApplicationGetNextSequenceNumber](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/ulApplicationGetNextSequenceNumber.html)

The functions ending with `_Multi` are used when you use multiple endpoints, that is when `ipconfigIPv4_BACKWARD_COMPATIBLE` is **not** defined.

Indeed these functions are “application hooks”, also called “callbacks”. Take care when using them because the hook is called from the IP-task. It may have a higher task priority, and it may have less stack space. Also it is **not allowed** to call the +TCP API’s, because the code is running in the IP-task.

> But in which file do I need to provide these definitions and where the prototypes should be placed?

I normally put them in a module where it is used. Your are free to choose.

> Are there any sample for stm32 that’s what I am looking for…

I made a few Makefile projects to test the IP-stack and other software. You can find it [here on github here](https://github.com/htibosch/freertos_plus_projects).  
Today I upgraded the [stm32F40 project](https://github.com/htibosch/freertos_plus_projects/tree/master/plus/stm32F40). I will also upgrade the [stm32F7 project](https://github.com/htibosch/freertos_plus_projects/tree/master/plus/stm32F7). I will report here when it is ready.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 20, 2024, 10:08am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/8 "2024-02-20T10:08:28Z")

</div>

@ashvajit wrote:

> Are there any sample for stm32 that’s what I am looking for…

I upgraded my [stm32F7 project](https://github.com/htibosch/freertos_plus_projects/tree/master/plus/stm32F7).  
I tested it on an evaluation board 746G disco.

Both STM32F projects are now using the latest kernel (V10.5.1) and FreeRTOS+TCP (V4.0.10).

Please tell us if it helps for you.

---

<div class="post-metadata">

**Author:** ![ashvajit](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@ashvajit](https://forums.freertos.org/u/ashvajit)\
**Post date:** [February 20, 2024, 11:17am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/10 "2024-02-20T11:17:29Z")

</div>

I am able to build the project now. I will try to use components from this project to resolve my build errors.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 21, 2024, 9:35am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/11 "2024-02-21T09:35:40Z")

</div>

If you want to try to make and run the whole project, you can clone the repo:

```auto
    git clone https://github.com/htibosch/freertos_plus_projects.git c:/temp/plus_projects

```

and the run make from the `stm32F7` directory:

```auto
c:\temp\plus_projects\plus\stm32F7

```

You can find `.project` and `.cproject` [here](https://github.com/htibosch/freertos_plus_projects/tree/master/plus/stm32F7). They can be used to import a project into Eclipse.

---

<div class="post-metadata">

**Author:** ![ashvajit](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@ashvajit](https://forums.freertos.org/u/ashvajit)\
**Post date:** [February 21, 2024, 11:17am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/12 "2024-02-21T11:17:31Z")

</div>

Yes, I did build the project from this and also used the requierd hooks from this project and added to my project and it is now not giving any build errors. But I am not able to ping to my board using my PC.  
I suspect that ethernet or PHY handling drivers are not initialized properly.

I have initialized as shown below in main() .

```auto
static const uint8_t ucIPAddress[4] = { 10, 25, 10, 72 };
static const uint8_t ucNetMask[4] = { 255, 255, 255, 0 };
static const uint8_t ucGatewayAddress[4] = { 10, 25, 10, 1 };
static const uint8_t ucDNSServerAddress[4] = { 8, 8, 8, 8 };

```

```auto
 status = FreeRTOS_IPInit(ucIPAddress,ucNetMask,ucGatewayAddress,ucDNSServerAddress,ucMACAddress);
  configASSERT(status == pdPASS);

  vTaskStartScheduler();

```

> #define HAL\_ETH\_MODULE\_ENABLED

is enabled in stm32fxx\_hal\_conf.h file and also added ethernet MSP\_INIT and DeInit functions in

```auto
void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(heth->Instance==ETH)
  {
  /* USER CODE BEGIN ETH_MspInit 0 */

  /* USER CODE END ETH_MspInit 0 */
    /* Enable Peripheral clock */
    __HAL_RCC_ETH_CLK_ENABLE();

    __HAL_RCC_GPIOG_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**ETH GPIO Configuration
    PG14 ------> ETH_TXD1
    PG13 ------> ETH_TXD0
    PG11 ------> ETH_TX_EN
    PC1 ------> ETH_MDC
    PA1 ------> ETH_REF_CLK
    PC4 ------> ETH_RXD0
    PA2 ------> ETH_MDIO
    PC5 ------> ETH_RXD1
    PA7 ------> ETH_CRS_DV
    */
    GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_13|GPIO_PIN_11;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    /* Peripheral interrupt init */
    HAL_NVIC_SetPriority(ETH_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(ETH_IRQn);
  /* USER CODE BEGIN ETH_MspInit 1 */

  /* USER CODE END ETH_MspInit 1 */
  }
}

```

Also, I want to mention that I am using LAN8742 IC which is present on the discovery board and not enabling ethernet from CubeMX which I was doing when not working with RTOS.  
I am not sure where I am going wrong as this MSP function is being called when I was debugging.

---

<div class="post-metadata">

**Author:** ![HTRamsey](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htramsey/32/4136_2.png) [@HTRamsey](https://forums.freertos.org/u/HTRamsey)\
**Post date:** [February 22, 2024, 12:51am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/13 "2024-02-22T00:51:02Z")

</div>

The autogenerated pins are usually wrong, double check those with the datasheet for your board.

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [February 22, 2024, 7:15am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/14 "2024-02-22T07:15:52Z")

</div>

Also make sure that the PHY configuration - MII vs. RMII and PHY address match your board design.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 22, 2024, 8:54am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/15 "2024-02-22T08:54:30Z")

</div>

And beside that, also please check if your version of `HAL_ETH_MspInit()` is really called from [this stm32fxx\_hal\_eth.c](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/source/portable/NetworkInterface/STM32Fxx/stm32fxx_hal_eth.c).  
Sometimes there is a weak function that is called in stead.

@ashvajit wrote:

> Also, I want to mention that I am using LAN8742

You may want to step go through [`xPhyDiscover()`](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/source/portable/NetworkInterface/Common/phyHandling.c#L204) and see if the LAN8742 gets detected.

---

<div class="post-metadata">

**Author:** ![ashvajit](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@ashvajit](https://forums.freertos.org/u/ashvajit)\
**Post date:** [February 22, 2024, 9:15am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/16 "2024-02-22T09:15:19Z")

</div>

I have verified the connection from my BareMetal working project.  
Thanks 🙂 ,

---

<div class="post-metadata">

**Author:** ![ashvajit](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@ashvajit](https://forums.freertos.org/u/ashvajit)\
**Post date:** [February 22, 2024, 10:03am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/17 "2024-02-22T10:03:35Z")

</div>

> [@htibosch](#):
>
> `HAL_ETH_MspInit`

Yes the function is called  
 ![MSP_Init](https://d2v6vdsk2p900z.cloudfront.net/original/2X/3/312852208353c7692b207fa170e1b9a85547cbe6.png)

> [@htibosch](#):
>
> You may want to step go through [`xPhyDiscover()`](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/source/portable/NetworkInterface/Common/phyHandling.c#L204) and see if the LAN8742 gets detected.

Yes, I am detecting a device here and ID matches what is defined in header, phyIDs instance values are shown in snap. But this function is being called repeatedly.

 ![PhyConfigure](https://d2v6vdsk2p900z.cloudfront.net/original/2X/2/233a0c1ac7e17ff200976aa921c68eceb52ae904.png)

 ![phy_params](https://d2v6vdsk2p900z.cloudfront.net/original/2X/f/fb5e1637bb33e5a502f57a3b310aab97e3185829.png)

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 26, 2024, 7:08am UTC](https://forums.freertos.org/t/freertos-plus-tcp-support-for-new-stm32fxx-ethernet-hal/17630/18 "2024-02-26T07:08:53Z")

</div>

> [@ashvajit](#):
>
> ```auto
> /* Peripheral interrupt init */
> HAL_NVIC_SetPriority(ETH_IRQn, 0, 0);
> HAL_NVIC_EnableIRQ(ETH_IRQn);
> 
> ```

Does the ISR for ETH\_IRQ call any FreeRTOS API? Also, can you share your FreeRTOSConfig.h?
