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// TODO Ethernet support for STM32H7 MCUs will be added in a future release.
61#elif defined STM32H7
62#include "stm32h7xx_hal.h"
63#include "stm32h7xx_hal_rcc.h"
64#include "stm32h7xx_hal_gpio.h"
65#endif
66
89static inline void hw_eth_init(void);
90
94void stm32f4xxEthInitGpio(NetInterface *interface) {
95 hw_eth_init();
96}
97
101void stm32f7xxEthInitGpio(NetInterface *interface) {
102 hw_eth_init();
103}
104
105static inline void hw_eth_init(void) {
106 GPIO_InitTypeDef GPIO_InitStructure;
107
108 //Enable SYSCFG clock
109 __HAL_RCC_SYSCFG_CLK_ENABLE();
110
111 //Enable GPIO clocks
112 __HAL_RCC_GPIOA_CLK_ENABLE();
113 __HAL_RCC_GPIOB_CLK_ENABLE();
114 __HAL_RCC_GPIOC_CLK_ENABLE();
115
116 //Configure MCO (PA8) as an output
117 GPIO_InitStructure.Pin = GPIO_PIN_8;
118 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
119 GPIO_InitStructure.Pull = GPIO_NOPULL;
120 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
121 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
122
123 //Select RMII interface mode
124 #ifndef STM32H7
125 SYSCFG->PMC |= SYSCFG_PMC_MII_RMII_SEL;
126 #else
127 // TODO Ethernet support for STM32H7 MCUs will be added in a future release.
128 HAL_SYSCFG_ETHInterfaceSelect(SYSCFG_ETH_RMII);
129 #endif
130
131 //Configure RMII pins
132 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
133 GPIO_InitStructure.Pull = GPIO_NOPULL;
134 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
135 GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
136
137 //Configure ETH_RMII_REF_CLK (PA1), ETH_MDIO (PA2) and ETH_RMII_CRS_DV (PA7)
138 GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
139 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
140
141 //Configure ETH_RMII_TX_EN (PB11), ETH_RMII_TXD0 (PB12) and ETH_RMII_TXD1 (PB13)
142 GPIO_InitStructure.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
143 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
144
145 //Configure ETH_MDC (PC1), ETH_RMII_RXD0 (PC4) and ETH_RMII_RXD1 (PC5)
146 GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
147 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
148
149 #ifdef STM32F4
150 //Configure MCO1 pin to output the PLL clock divided by 3 (150/3=50MHz)
151 HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_3);
152 #elif defined STM32F7
153 //Configure MCO1 pin to output the PLL clock divided by 4 (200/4=50MHz)
154 HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_4);
155 // #elif defined STM32H7
156 // TODO Ethernet support for STM32H7 MCUs will be added in a future release.
157 // //Configure MCO1 pin to output the PLL clock divided by 4 (200/4=50MHz)
158 // HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLL1QCLK, RCC_MCODIV_4);
159 #endif
160}
161
162 // ethernet
163 // middleware
164
165#ifdef __cplusplus
166}
167#endif
168
169#endif // _HW_ETH_H_
170// ------------------------------------------------------------------------- END
#define GPIOC
Definition MK60D10.h:6918
#define GPIOB
Definition MK60D10.h:6914
#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
#define SYSCFG_ETH_RMII
Definition stm32h7xx_hal.h:153
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.
This file contains all the functions prototypes for the HAL module driver.
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