mikroSDK Reference Manual
hw_eth.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2024 MikroElektronika d.o.o.
4** Contact: https://www.mikroe.com/contact
5**
6** This file is part of the mikroSDK package
7**
8** Commercial License Usage
9**
10** Licensees holding valid commercial NECTO compilers AI licenses may use this
11** file in accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The MikroElektronika Company.
14** For licensing terms and conditions see
15** https://www.mikroe.com/legal/software-license-agreement.
16** For further information use the contact form at
17** https://www.mikroe.com/contact.
18**
19**
20** GNU Lesser General Public License Usage
21**
22** Alternatively, this file may be used for
23** non-commercial projects under the terms of the GNU Lesser
24** General Public License version 3 as published by the Free Software
25** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26**
27** The above copyright notice and this permission notice shall be
28** included in all copies or substantial portions of the Software.
29**
30** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37**
38****************************************************************************/
45#ifndef _HW_ETH_H_
46#define _HW_ETH_H_
47
48#ifdef __cplusplus
49extern "C"{
50#endif
51
52#include "mcu.h"
53#include "net.h"
54#ifdef STM32F4
55#include "stm32f4xx_hal_rcc.h"
56#include "stm32f4xx_hal_gpio.h"
57#elif defined STM32F7
58#include "stm32f7xx_hal_rcc.h"
59#include "stm32f7xx_hal_gpio.h"
60#endif
61
84static inline void hw_eth_init(void);
85
89void stm32f4xxEthInitGpio(NetInterface *interface) {
90 hw_eth_init();
91}
92
96void stm32f7xxEthInitGpio(NetInterface *interface) {
97 hw_eth_init();
98}
99
100static inline void hw_eth_init(void) {
101 GPIO_InitTypeDef GPIO_InitStructure;
102
103 //Enable SYSCFG clock
104 __HAL_RCC_SYSCFG_CLK_ENABLE();
105
106 //Enable GPIO clocks
107 __HAL_RCC_GPIOA_CLK_ENABLE();
108 __HAL_RCC_GPIOC_CLK_ENABLE();
109 __HAL_RCC_GPIOG_CLK_ENABLE();
110
111 //Configure MCO (PA8) as an output
112 GPIO_InitStructure.Pin = GPIO_PIN_8;
113 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
114 GPIO_InitStructure.Pull = GPIO_NOPULL;
115 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
116 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
117
118 //Select RMII interface mode
119 SYSCFG->PMC |= SYSCFG_PMC_MII_RMII_SEL;
120
121 //Configure RMII pins
122 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
123 GPIO_InitStructure.Pull = GPIO_NOPULL;
124 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
125 GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
126
127 //Configure ETH_RMII_REF_CLK (PA1), ETH_MDIO (PA2) and ETH_RMII_CRS_DV (PA7)
128 GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
129 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
130
131 //Configure ETH_RMII_TX_EN (PG11), ETH_RMII_TXD0 (PG13) and ETH_RMII_TXD1 (PG14)
132 GPIO_InitStructure.Pin = GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14;
133 HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
134
135 //Configure ETH_MDC (PC1), ETH_RMII_RXD0 (PC4) and ETH_RMII_RXD1 (PC5)
136 GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
137 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
138
139 #ifdef STM32F4
140 //Configure MCO1 pin to output the PLL clock divided by 3 (150/3=50MHz)
141 HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_3);
142 #elif defined STM32F7
143 //Configure MCO1 pin to output the PLL clock divided by 4 (200/4=50MHz)
144 HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_4);
145 #endif
146}
147
148 // ethernet
149 // middleware
150
151#ifdef __cplusplus
152}
153#endif
154
155#endif // _HW_ETH_H_
156// ------------------------------------------------------------------------- END
#define GPIOC
Definition MK60D10.h:6918
#define GPIOA
Definition MK60D10.h:6910
#define GPIO_NOPULL
Definition stm32f1xx_hal_gpio.h:153
#define GPIO_SPEED_FREQ_VERY_HIGH
Definition stm32f2xx_hal_gpio.h:144
#define GPIO_SPEED_FREQ_HIGH
Definition stm32f1xx_hal_gpio.h:143
#define SYSCFG_PMC_MII_RMII_SEL
Definition stm32f207xx.h:11111
void stm32f7xxEthInitGpio(NetInterface *interface)
Externally linked API for ETH configuration.
Definition hw_eth.h:101
void stm32f4xxEthInitGpio(NetInterface *interface)
Externally linked API for ETH configuration.
Definition hw_eth.h:94
TCP/IP stack core.
Header file of GPIO HAL module.
Header file of RCC HAL module.
Header file of GPIO HAL module.
Header file of RCC HAL module.
GPIO Init structure definition.
Definition stm32f1xx_hal_gpio.h:48
uint32_t Mode
Definition stm32f1xx_hal_gpio.h:52
uint32_t Alternate
Definition stm32f2xx_hal_gpio.h:61
uint32_t Pull
Definition stm32f1xx_hal_gpio.h:55
uint32_t Pin
Definition stm32f1xx_hal_gpio.h:49
uint32_t Speed
Definition stm32f1xx_hal_gpio.h:58