Skip to content

Commit df5725f

Browse files
committed
Eth: STM32: Overriding HAL callbacks in stm32xx
This commit enables the Overriding of HAL callbacks and IRQHandler in stm32xx_emac.cpp. Hence the user can have their own implementations of callbacks and IRQHandler functions. Signed-off-by: Kather Rafi Ibrahim <[email protected]>
1 parent d147abc commit df5725f

File tree

4 files changed

+79
-11
lines changed

4 files changed

+79
-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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021, STMicroelectronics
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#ifndef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK
30+
31+
#include "stm32xx_emac.h"
32+
#define FLAG_RX 1
33+
34+
/**
35+
* Override Ethernet Rx Transfer completed callback
36+
* @param heth: ETH handle
37+
* @retval None
38+
*/
39+
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
40+
{
41+
STM32_EMAC &emac = STM32_EMAC::get_instance();
42+
if (emac.thread) {
43+
osThreadFlagsSet(emac.thread, FLAG_RX);
44+
}
45+
}
46+
47+
/**
48+
* Override the IRQ Handler
49+
* @param None
50+
* @retval None
51+
*/
52+
void STM_HAL_ETH_Handler()
53+
{
54+
STM32_EMAC &emac = STM32_EMAC::get_instance();
55+
HAL_ETH_IRQHandler(&emac.EthHandle);
56+
}
57+
58+
#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)