Skip to content

Commit 43a060f

Browse files
authored
Merge pull request #14926 from katherrafi/hal_callback_override
Eth: STM32: Overriding HAL callbacks in stm32xx
2 parents 1ac928e + a9f51e3 commit 43a060f

File tree

4 files changed

+72
-11
lines changed

4 files changed

+72
-11
lines changed

connectivity/drivers/emac/TARGET_STM/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ target_include_directories(mbed-emac
1919
target_sources(mbed-emac
2020
INTERFACE
2121
stm32xx_emac.cpp
22+
stm32xx_eth_irq_callback.cpp
2223
)

connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ extern "C" {
144144
#endif
145145

146146
void _eth_config_mac(ETH_HandleTypeDef *heth);
147-
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth);
148147
void ETH_IRQHandler(void);
148+
MBED_WEAK void STM_HAL_ETH_Handler(ETH_HandleTypeDef *heth);
149149

150150
#ifdef __cplusplus
151151
}
@@ -242,20 +242,14 @@ static void MPU_Config(void)
242242

243243
#endif
244244

245-
246-
247245
/**
248-
* Ethernet Rx Transfer completed callback
246+
* IRQ Handler
249247
*
250248
* @param heth: ETH handle
251249
* @retval None
252250
*/
253-
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
251+
MBED_WEAK void STM_HAL_ETH_Handler()
254252
{
255-
STM32_EMAC &emac = STM32_EMAC::get_instance();
256-
if (emac.thread) {
257-
osThreadFlagsSet(emac.thread, FLAG_RX);
258-
}
259253
}
260254

261255
/**
@@ -266,8 +260,7 @@ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
266260
*/
267261
void ETH_IRQHandler(void)
268262
{
269-
STM32_EMAC &emac = STM32_EMAC::get_instance();
270-
HAL_ETH_IRQHandler(&emac.EthHandle);
263+
STM_HAL_ETH_Handler();
271264
}
272265

273266
STM32_EMAC::STM32_EMAC()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright (c) 2017-2019 ARM Limited
2+
* Copyright (c) 2017-2019 STMicroelectronics
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK
19+
20+
#if DEVICE_EMAC
21+
22+
#include "stm32xx_emac.h"
23+
#define FLAG_RX 1
24+
25+
/**
26+
* Override Ethernet Rx Transfer completed callback
27+
* @param heth: ETH handle
28+
* @retval None
29+
*/
30+
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
31+
{
32+
STM32_EMAC &emac = STM32_EMAC::get_instance();
33+
if (emac.thread) {
34+
osThreadFlagsSet(emac.thread, FLAG_RX);
35+
}
36+
}
37+
38+
/**
39+
* Override the IRQ Handler
40+
* @param None
41+
* @retval None
42+
*/
43+
void STM_HAL_ETH_Handler()
44+
{
45+
STM32_EMAC &emac = STM32_EMAC::get_instance();
46+
HAL_ETH_IRQHandler(&emac.EthHandle);
47+
}
48+
49+
#endif /* DEVICE_EMAC */
50+
51+
#endif /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */

targets/TARGET_STM/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,22 @@ https://github.com/ARMmbed/mbed-os/blob/master/connectivity/drivers/emac/TARGET_
503503
Option is also to define your own `HAL_ETH_MspInit` function,
504504
you then have to add **USE_USER_DEFINED_HAL_ETH_MSPINIT** macro.
505505

506+
#### Custom IRQ Handler and Callback from user application
507+
To use the custom IRQ Handler and the callbacks, you need to add
508+
**USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK** macro
509+
inside any of the JASON file in either targets.json or in mbed_app.json file.
510+
511+
For example in the targets.json,
512+
you need to add this line in your target:
513+
```"macros_add": ["USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK"],```
514+
or for example in the mbed_app.json, you need to add:
515+
``` "macros": ["USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK"]```
516+
517+
By doing the any of the above json files, the corresponding user defined custom apis like
518+
HAL_ETH_RxCpltCallback() and STM_HAL_ETH_Handler() can be called from
519+
the user application.
520+
521+
#### Changing default MAC address in STM32
506522
To change the default MAC address in STM32,
507523
If we have the function mbed_otp_mac_address() in the user application,the default ethernet address
508524
can be changed.

0 commit comments

Comments
 (0)