diff --git a/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt b/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt index c7bd8eb88c7..354c246f016 100644 --- a/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt +++ b/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt @@ -19,4 +19,5 @@ target_include_directories(mbed-emac target_sources(mbed-emac INTERFACE stm32xx_emac.cpp + stm32xx_eth_irq_callback.cpp ) diff --git a/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp b/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp index 827c58f5db1..0230a90665c 100644 --- a/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp +++ b/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp @@ -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() diff --git a/connectivity/drivers/emac/TARGET_STM/stm32xx_eth_irq_callback.cpp b/connectivity/drivers/emac/TARGET_STM/stm32xx_eth_irq_callback.cpp new file mode 100644 index 00000000000..cfe7782a682 --- /dev/null +++ b/connectivity/drivers/emac/TARGET_STM/stm32xx_eth_irq_callback.cpp @@ -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 */ diff --git a/targets/TARGET_STM/README.md b/targets/TARGET_STM/README.md index 4a9e7563e08..d99c87cac0f 100644 --- a/targets/TARGET_STM/README.md +++ b/targets/TARGET_STM/README.md @@ -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.