Skip to content

Commit 11e39fe

Browse files
committed
STM EMAC : NUCLEO_H743ZI2 add
1 parent b705a98 commit 11e39fe

File tree

1 file changed

+162
-0
lines changed
  • features/netsocket/emac-drivers/TARGET_STM_EMAC/TARGET_STM32H7/TARGET_NUCLEO_H743ZI2

1 file changed

+162
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018, 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_MSPINIT
30+
31+
#include "stm32h7xx_hal.h"
32+
33+
#define MCO_Pin GPIO_PIN_0
34+
#define MCO_GPIO_Port GPIOH
35+
#define RMII_MDC_Pin GPIO_PIN_1
36+
#define RMII_MDC_GPIO_Port GPIOC
37+
#define RMII_REF_CLK_Pin GPIO_PIN_1
38+
#define RMII_REF_CLK_GPIO_Port GPIOA
39+
#define RMII_MDIO_Pin GPIO_PIN_2
40+
#define RMII_MDIO_GPIO_Port GPIOA
41+
#define RMII_CRS_DV_Pin GPIO_PIN_7
42+
#define RMII_CRS_DV_GPIO_Port GPIOA
43+
#define RMII_RXD0_Pin GPIO_PIN_4
44+
#define RMII_RXD0_GPIO_Port GPIOC
45+
#define RMII_RXD1_Pin GPIO_PIN_5
46+
#define RMII_RXD1_GPIO_Port GPIOC
47+
#define RMII_TXD1_Pin GPIO_PIN_13
48+
#define RMII_TXD1_GPIO_Port GPIOB
49+
#define TMS_Pin GPIO_PIN_13
50+
#define TMS_GPIO_Port GPIOA
51+
#define TCK_Pin GPIO_PIN_14
52+
#define TCK_GPIO_Port GPIOA
53+
#define RMII_TX_EN_Pin GPIO_PIN_11
54+
#define RMII_TX_EN_GPIO_Port GPIOG
55+
#define RMII_TXD0_Pin GPIO_PIN_13
56+
#define RMII_TXD0_GPIO_Port GPIOG
57+
58+
/**
59+
* Override HAL Eth Init function
60+
*/
61+
void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
62+
{
63+
GPIO_InitTypeDef GPIO_InitStruct;
64+
if(heth->Instance == ETH)
65+
{
66+
/* Disable DCache for STM32H7 family */
67+
SCB_DisableDCache();
68+
69+
/* GPIO Ports Clock Enable */
70+
__HAL_RCC_GPIOH_CLK_ENABLE();
71+
__HAL_RCC_GPIOC_CLK_ENABLE();
72+
__HAL_RCC_GPIOA_CLK_ENABLE();
73+
__HAL_RCC_GPIOB_CLK_ENABLE();
74+
__HAL_RCC_GPIOG_CLK_ENABLE();
75+
76+
/* Enable Peripheral clock */
77+
__HAL_RCC_ETH1MAC_CLK_ENABLE();
78+
__HAL_RCC_ETH1TX_CLK_ENABLE();
79+
__HAL_RCC_ETH1RX_CLK_ENABLE();
80+
81+
/**ETH GPIO Configuration
82+
PC1 ------> ETH_MDC
83+
PA1 ------> ETH_REF_CLK
84+
PA2 ------> ETH_MDIO
85+
PA7 ------> ETH_CRS_DV
86+
PC4 ------> ETH_RXD0
87+
PC5 ------> ETH_RXD1
88+
PB13 ------> ETH_TXD1
89+
PG11 ------> ETH_TX_EN
90+
PG13 ------> ETH_TXD0
91+
*/
92+
GPIO_InitStruct.Pin = RMII_MDC_Pin;
93+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
94+
GPIO_InitStruct.Pull = GPIO_NOPULL;
95+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
96+
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
97+
HAL_GPIO_Init(RMII_MDC_GPIO_Port, &GPIO_InitStruct);
98+
99+
GPIO_InitStruct.Pin = RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin;
100+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
101+
GPIO_InitStruct.Pull = GPIO_NOPULL;
102+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
103+
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
104+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
105+
106+
GPIO_InitStruct.Pin = RMII_RXD0_Pin|RMII_RXD1_Pin;
107+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
108+
GPIO_InitStruct.Pull = GPIO_NOPULL;
109+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
110+
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
111+
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
112+
113+
GPIO_InitStruct.Pin = RMII_TXD1_Pin;
114+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
115+
GPIO_InitStruct.Pull = GPIO_NOPULL;
116+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
117+
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
118+
HAL_GPIO_Init(RMII_TXD1_GPIO_Port, &GPIO_InitStruct);
119+
120+
GPIO_InitStruct.Pin = RMII_TX_EN_Pin|RMII_TXD0_Pin;
121+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
122+
GPIO_InitStruct.Pull = GPIO_NOPULL;
123+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
124+
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
125+
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
126+
}
127+
}
128+
129+
/**
130+
* Override HAL Eth DeInit function
131+
*/
132+
void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
133+
{
134+
if(heth->Instance == ETH)
135+
{
136+
/* Disable Peripheral clock */
137+
__HAL_RCC_ETH1MAC_CLK_DISABLE();
138+
__HAL_RCC_ETH1TX_CLK_DISABLE();
139+
__HAL_RCC_ETH1RX_CLK_DISABLE();
140+
141+
/**ETH GPIO Configuration
142+
PC1 ------> ETH_MDC
143+
PA1 ------> ETH_REF_CLK
144+
PA2 ------> ETH_MDIO
145+
PA7 ------> ETH_CRS_DV
146+
PC4 ------> ETH_RXD0
147+
PC5 ------> ETH_RXD1
148+
PB13 ------> ETH_TXD1
149+
PG11 ------> ETH_TX_EN
150+
PG13 ------> ETH_TXD0
151+
*/
152+
HAL_GPIO_DeInit(GPIOC, RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin);
153+
154+
HAL_GPIO_DeInit(GPIOA, RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin);
155+
156+
HAL_GPIO_DeInit(RMII_TXD1_GPIO_Port, RMII_TXD1_Pin);
157+
158+
HAL_GPIO_DeInit(GPIOG, RMII_TX_EN_Pin|RMII_TXD0_Pin);
159+
}
160+
}
161+
162+
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */

0 commit comments

Comments
 (0)