Skip to content

Eth: STM32: Overriding HAL callbacks in stm32xx #14926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions connectivity/drivers/emac/TARGET_STM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ target_include_directories(mbed-emac
target_sources(mbed-emac
INTERFACE
stm32xx_emac.cpp
stm32xx_eth_irq_callback.cpp
)
15 changes: 4 additions & 11 deletions connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ extern "C" {
#endif

void _eth_config_mac(ETH_HandleTypeDef *heth);
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth);
void ETH_IRQHandler(void);
MBED_WEAK void STM_HAL_ETH_Handler(ETH_HandleTypeDef *heth);

#ifdef __cplusplus
}
Expand Down Expand Up @@ -242,20 +242,14 @@ static void MPU_Config(void)

#endif



/**
* Ethernet Rx Transfer completed callback
* IRQ Handler
*
* @param heth: ETH handle
* @retval None
*/
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
MBED_WEAK void STM_HAL_ETH_Handler()
{
STM32_EMAC &emac = STM32_EMAC::get_instance();
if (emac.thread) {
osThreadFlagsSet(emac.thread, FLAG_RX);
}
}

/**
Expand All @@ -266,8 +260,7 @@ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
*/
void ETH_IRQHandler(void)
{
STM32_EMAC &emac = STM32_EMAC::get_instance();
HAL_ETH_IRQHandler(&emac.EthHandle);
STM_HAL_ETH_Handler();
}

STM32_EMAC::STM32_EMAC()
Expand Down
51 changes: 51 additions & 0 deletions connectivity/drivers/emac/TARGET_STM/stm32xx_eth_irq_callback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright (c) 2017-2019 ARM Limited
* Copyright (c) 2017-2019 STMicroelectronics
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK

#if DEVICE_EMAC

#include "stm32xx_emac.h"
#define FLAG_RX 1

/**
* Override Ethernet Rx Transfer completed callback
* @param heth: ETH handle
* @retval None
*/
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
{
STM32_EMAC &emac = STM32_EMAC::get_instance();
if (emac.thread) {
osThreadFlagsSet(emac.thread, FLAG_RX);
}
}

/**
* Override the IRQ Handler
* @param None
* @retval None
*/
void STM_HAL_ETH_Handler()
{
STM32_EMAC &emac = STM32_EMAC::get_instance();
HAL_ETH_IRQHandler(&emac.EthHandle);
}

#endif /* DEVICE_EMAC */

#endif /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */
16 changes: 16 additions & 0 deletions targets/TARGET_STM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,22 @@ https://github.com/ARMmbed/mbed-os/blob/master/connectivity/drivers/emac/TARGET_
Option is also to define your own `HAL_ETH_MspInit` function,
you then have to add **USE_USER_DEFINED_HAL_ETH_MSPINIT** macro.

#### Custom IRQ Handler and Callback from user application
To use the custom IRQ Handler and the callbacks, you need to add
**USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK** macro
inside any of the JASON file in either targets.json or in mbed_app.json file.

For example in the targets.json,
you need to add this line in your target:
```"macros_add": ["USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK"],```
or for example in the mbed_app.json, you need to add:
``` "macros": ["USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK"]```

By doing the any of the above json files, the corresponding user defined custom apis like
HAL_ETH_RxCpltCallback() and STM_HAL_ETH_Handler() can be called from
the user application.

#### Changing default MAC address in STM32
To change the default MAC address in STM32,
If we have the function mbed_otp_mac_address() in the user application,the default ethernet address
can be changed.
Expand Down