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#include "stm32f2xx_hal_rcc.h"
55#include "stm32f2xx_hal_gpio.h"
56
79static inline void hw_eth_init(void);
80
84void stm32f2xxEthInitGpio(NetInterface *interface) {
85 hw_eth_init();
86}
87
88static inline void hw_eth_init(void) {
89 // Note: Added for MikroE implementation.
90 GPIO_InitTypeDef GPIO_InitStructure;
91
92 //Enable SYSCFG clock
93 __HAL_RCC_SYSCFG_CLK_ENABLE();
94
95 //Enable GPIO clocks
96 __HAL_RCC_GPIOA_CLK_ENABLE();
97 __HAL_RCC_GPIOB_CLK_ENABLE();
98 __HAL_RCC_GPIOC_CLK_ENABLE();
99
100 //Select RMII interface mode
101 SYSCFG->PMC |= SYSCFG_PMC_MII_RMII_SEL;
102
103 //Configure RMII pins
104 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
105 GPIO_InitStructure.Pull = GPIO_NOPULL;
106 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
107 GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
108
109 //Configure ETH_RMII_REF_CLK (PA1), ETH_MDIO (PA2) and ETH_RMII_CRS_DV (PA7)
110 GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
111 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
112
113 //Configure ETH_RMII_TX_EN (PB11), ETH_RMII_TXD0 (PB12) and ETH_RMII_TXD1 (PB13)
114 GPIO_InitStructure.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
115 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
116
117 //Configure ETH_MDC (PC1), ETH_RMII_RXD0 (PC4) and ETH_RMII_RXD1 (PC5)
118 GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
119 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
120
121 //Configure MCO1 pin to output the PLL clock divided by 2 (100/2=50MHz)
122 HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_2);
123}
124
125 // ethernet
126 // middleware
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif // _HW_ETH_H_
133// ------------------------------------------------------------------------- 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 SYSCFG_PMC_MII_RMII_SEL
Definition stm32f207xx.h:11111
void stm32f2xxEthInitGpio(NetInterface *interface)
Externally linked API for ETH configuration.
Definition hw_eth.h:84
TCP/IP stack core.
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