Skip to content

Overriding HAL callbacks in stm32xx_emac.cpp #13554

@pgscada

Description

@pgscada

Description of defect

It is not possible to provide a custom (overridden) EMAC on STM32 devices without modifying the mbed source files because:

  1. If we attempt to write our own ETH_IRQHandler or HAL_ETH_RxCpltCallback functions, the source will not compile because these functions are already defined in stm32xx_emac.cpp.
  2. We cannot use the provided implementations of these functions because they ignore any custom EMAC that may have been configured in the program and revert back to the mbed provided EMAC.
  3. No macros or any alternatives are provided by the mbed environment to suppress the HAL callbacks defined by mbed in stm32xx_emac.cpp.

A developer wishing to provide a custom EMAC to the NetworkInterface has to modify the mbed source file stm32xx_emac.cpp. This is not desirable and should be avoided.

Target(s) affected by this defect ?

All devices using connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp

Toolchain(s) (name and version) displaying this defect ?

All toolchains

What version of Mbed-os are you using (tag or sha) ?

mbed-os-6.2.1

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

mbed-cli 1.8.3

How is this defect reproduced ?

  • Create a custom EMAC class and override function MBED_WEAK EMAC &EMAC::get_default_instance() located in stm32xx_emac.cpp
  • Create NewtorkInterface using custom EMAC (ie, NetworkInterface iface(&my_emac);)
  • Run project and observe error
++ MbedOS Error Info ++
Error Status: 0x80010133 Code: 307 Module: 1
Error Message: Mutex: 0x2000E924, Not allowed in ISR context
Location: 0x800279F
Error Value: 0x2000E924
Current Thread: rtx_idle Id: 0x20001124 Entry: 0x80027AD StackSize: 0x380 StackMem: 0x20001468 SP: 0x2004FF34
For more info, visit: https://mbed.com/s/error?error=0x80010133&osver=60201&core=0x410FC271&comp=2&ver=90300&tgt=DISCO_F746NG
-- MbedOS Error Info --
  • Edit stm32xx_emac.cpp, comment out function void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth) and ETH_IRQHandler
  • Run project and observe no error

Suggested solutions

  • Both HAL callbacks provided by mbed reference STM32_EMAC::get_instance() instead of the weak functions MBED_WEAK EMAC &EMAC::get_default_instance()
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
{
    STM32_EMAC &emac = STM32_EMAC::get_instance();
    if (emac.thread) {
        osThreadFlagsSet(emac.thread, FLAG_RX);
    }
}
void ETH_IRQHandler(void)
{
    STM32_EMAC &emac = STM32_EMAC::get_instance();
    HAL_ETH_IRQHandler(&emac.EthHandle);
}
  • Marking the two HAL callbacks as MBED_WEAK solves my issue.
  • Otherwise, wrap the HAL callbacks inside #ifndef macros which can be disabled from mbed_app.json

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions