cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX V6.5.0: bug in generated ethernetif.h file.

Charles Miller
Associate III

CubeMX version 6.5.0 generates the following line in <project>/LWIP/target/ethernetif.h:

static void ethernetif_input(void const * argument);

Previous version 6.4.0 generated this:

void ethernetif_input(void const * argument);

The 'static' storage class specifier causes warnings in any module that includes "ethernetif.h". The function could be declared static, but this would best be done modifying the ethernetif.c file. In this manner, removing the declaration entirely from ethernetif.h would be possible, as it really is completely local to ethernetif.c.

In any case, unnecessary warnings are not desirable.

Follow-up:

Modifying ethernetif_header.ftl (C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\db\templates) fixes the issue. ST--please review why you added "static".

6.4.0 (good):

[#if use_rtos == 1][#-- rtos used --]
[#if cmsis_version = "v1"][#-- cmsis_version v1 --]
void ethernetif_input(void const * argument);

6.5.0 (problem):

[#if use_rtos == 1][#-- rtos used --]
[#if cmsis_version = "v1"][#-- cmsis_version v1 --]
static void ethernetif_input(void const * argument);

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Charles Miller​ ,

The issue is not reproduced from our side: No warning seen during project build. Could you please attach the project in which the warning has occurred or at least precise with which device the misbehavior is reproduced.

Otherwise, I assume that the change in the ethernetif.c file (defining ethernetif_input as a static function) is done to be aligned with the new HAL ETH driver.

In fact, backing to the STM32H7 firmware projects (for example <STM32Cube_FW_H7_V1.10.0_Firmware_Location>\Projects\STM32H743I-EVAL\Applications\LwIP\LwIP_HTTP_Server_Netconn_RTOS\Src\ethernetif.c>:

ethernetif_input is declared as a static function.

Thus, ethernetif.c template generated by CubeMX is updated to integrate the modification done in the FW.

BeST Regards,

Walid

View solution in original post

7 REPLIES 7

hello @Charles Miller​ ,

This issue has been raised internally. I will keep you posted.

Thank you for your contribution.

BeST Regards,

Walid

Internal ticket number: 124091 (This is an internal tracking number and is not accessible or usable by customers).

Hello @Charles Miller​ ,

The issue is not reproduced from our side: No warning seen during project build. Could you please attach the project in which the warning has occurred or at least precise with which device the misbehavior is reproduced.

Otherwise, I assume that the change in the ethernetif.c file (defining ethernetif_input as a static function) is done to be aligned with the new HAL ETH driver.

In fact, backing to the STM32H7 firmware projects (for example <STM32Cube_FW_H7_V1.10.0_Firmware_Location>\Projects\STM32H743I-EVAL\Applications\LwIP\LwIP_HTTP_Server_Netconn_RTOS\Src\ethernetif.c>:

ethernetif_input is declared as a static function.

Thus, ethernetif.c template generated by CubeMX is updated to integrate the modification done in the FW.

BeST Regards,

Walid

Charles Miller
Associate III

@Walid ZRELLI​ , if you include a header file containing a static function declaration, and the translation unit does not USE that function (or reference it), then that translation unit will issue a warning about an unused static function. If the include file was ONLY included by ethernetif.c, then there would be no warning, since ethernetif.c uses/defines the static function. Since I include ethernetif.h in other .c files, I unnecessarily get warnings. The rule about declaring static functions in C is: if you declare it, but don't define or use it, you get a warning. Try adding include "ethernetif.h" in some other .c file, and watch what gcc gives you.

To be clear: I'm glad you make ethernetif_input() static--it should be! This limits its scope, avoiding global namespace pollution. But don't put the static declaration in headers!

If you simply add the line,

    static void ethernetif_input(void const * argument);

at the top of ethernetif.c, and remove the line from the header file, there would be no warnings. And at my shop, we compile clean--no warnings allowed!

OPera
Associate II

There is another error in the ethernetif.c file, in the ethernet_link_thread() function.

at line 806, in the if(linkchanged) test

HAL_ETH_Start_IT(&heth);

has been replaced by

HAL_ETH_Start(&heth);

@OPera​ What is your version of CubeMX/IDE?

In recently installed templates db v 6.0.40, ethernetif_h7.ftl

[#if with_rtos == 1]
[#if cmsis_version = "v2"]
void ethernet_link_thread(void* argument)
[#else] [#-- endif cmsis_version --]
void ethernet_link_thread(void const * argument)
[/#if][#-- endelse cmsis_version --]
[#else][#-- else with_rtos --]  
void ethernet_link_check_state(struct netif *netif)
[/#if][#-- endelse with_rtos --]

That's the function ethernet_link_thread is generated only if with_rtos is true.

​But then it generates HAL_ETH_Start_IT :

[#if with_rtos == 1]
      HAL_ETH_Start_IT(&heth);
[#else][#-- else with_rtos --]
      HAL_ETH_Start(&heth);
[/#if][#-- endif with_rtos --]
      netif_set_up(netif);
      netif_set_link_up(netif);
    }
  }
[/#if][#-- endif bsp --]

Assumed that you have H7 because in other two templates for F4/F7 and F1/F2, function name 'ethernet_link_thread' is not found.

Yes, I am working with the H7 package:

  • STMCubeIDE version 1.9.0
  • STM32CubeMX version 6.5.0
  • STM32CubeH7 Firmware Package V1.10.0 / 11-February-2022