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 STM32F107xC
55#include "stm32f1xx_hal.h"
56#include "stm32f1xx_hal_rcc.h"
57#endif
58
81static inline void hw_eth_init(void);
82
86void stm32f1xxEthInitGpio(NetInterface *interface) {
87 hw_eth_init();
88}
89
90static inline void hw_eth_init(void) {
91 GPIO_InitTypeDef GPIO_InitStructure;
92
93 //Enable AFIO clock
94 __HAL_RCC_AFIO_CLK_ENABLE();
95
96 //Enable GPIO clocks
97 __HAL_RCC_GPIOA_CLK_ENABLE();
98 __HAL_RCC_GPIOB_CLK_ENABLE();
99 __HAL_RCC_GPIOC_CLK_ENABLE();
100
101 //Configure MCO (PA8) as an output
102 GPIO_InitStructure.Pin = GPIO_PIN_8;
103 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
104 GPIO_InitStructure.Pull = GPIO_NOPULL;
105 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
106 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
107
108 //Configure MCO pin to output the PLL3 clock
109 HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, 1);
110
111 //Select RMII interface mode
112 __HAL_AFIO_ETH_RMII();
113
114 //Configure MII_MDIO (PA2)
115 GPIO_InitStructure.Pin = GPIO_PIN_2;
116 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
117 GPIO_InitStructure.Pull = GPIO_NOPULL;
118 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
119 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
120
121 //Configure ETH_RMII_TX_EN (PB11), ETH_RMII_TXD0 (PB12) and ETH_RMII_TXD1 (PB13)
122 GPIO_InitStructure.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
123 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
124 GPIO_InitStructure.Pull = GPIO_NOPULL;
125 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
126 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
127
128 //Configure ETH_MDC (PC1)
129 GPIO_InitStructure.Pin = GPIO_PIN_1;
130 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
131 GPIO_InitStructure.Pull = GPIO_NOPULL;
132 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
133 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
134
135 //Configure ETH_RMII_REF_CLK (PA1) and ETH_RMII_CRS_DV (PA7)
136 GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_7;
137 GPIO_InitStructure.Mode = GPIO_MODE_AF_INPUT;
138 GPIO_InitStructure.Pull = GPIO_NOPULL;
139 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
140 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
141
142 //Configure ETH_RMII_RXD0 (PC4) and ETH_RMII_RXD1 (PC5)
143 GPIO_InitStructure.Pin = GPIO_PIN_4 | GPIO_PIN_5;
144 GPIO_InitStructure.Mode = GPIO_MODE_AF_INPUT;
145 GPIO_InitStructure.Pull = GPIO_NOPULL;
146 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
147 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
148
149 //Do not remap Ethernet pins
150 __HAL_AFIO_REMAP_ETH_DISABLE();
151}
152
153 // ethernet
154 // middleware
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif // _HW_ETH_H_
161// ------------------------------------------------------------------------- END
#define GPIOC
Definition MK60D10.h:6918
#define GPIOB
Definition MK60D10.h:6914
#define GPIOA
Definition MK60D10.h:6910
#define GPIO_MODE_AF_INPUT
Definition stm32f1xx_hal_gpio.h:121
#define GPIO_NOPULL
Definition stm32f1xx_hal_gpio.h:153
#define GPIO_SPEED_FREQ_HIGH
Definition stm32f1xx_hal_gpio.h:143
void stm32f1xxEthInitGpio(NetInterface *interface)
Externally linked API for ETH configuration.
Definition hw_eth.h:86
TCP/IP stack core.
This file contains all the functions prototypes for the HAL module driver.
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 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