Merge pull request #14926 from katherrafi/hal_callback_override

Eth: STM32: Overriding HAL callbacks in stm32xx
pull/15025/head
Martin Kojtal 2021-08-26 09:51:48 +01:00 committed by GitHub
commit 43a060fe7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 11 deletions

View File

@ -19,4 +19,5 @@ target_include_directories(mbed-emac
target_sources(mbed-emac
INTERFACE
stm32xx_emac.cpp
stm32xx_eth_irq_callback.cpp
)

View File

@ -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
}
@ -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);
}
}
/**
@ -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()

View File

@ -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 */

View File

@ -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.