|
| 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 "stm32f4xx_hal.h" |
| 32 | + |
| 33 | +/** |
| 34 | + * Override HAL Eth Init function |
| 35 | + */ |
| 36 | +void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) |
| 37 | +{ |
| 38 | + GPIO_InitTypeDef GPIO_InitStructure; |
| 39 | + if (heth->Instance == ETH) { |
| 40 | + |
| 41 | + /* Enable GPIOs clocks */ |
| 42 | + __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 43 | + __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 44 | + __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 45 | + __HAL_RCC_GPIOG_CLK_ENABLE(); |
| 46 | + |
| 47 | + /** ETH GPIO Configuration |
| 48 | + RMII_REF_CLK ----------------------> PA1 |
| 49 | + RMII_MDIO -------------------------> PA2 |
| 50 | + RMII_MDC --------------------------> PC1 |
| 51 | + RMII_MII_CRS_DV -------------------> PA7 |
| 52 | + RMII_MII_RXD0 ---------------------> PC4 |
| 53 | + RMII_MII_RXD1 ---------------------> PC5 |
| 54 | + RMII_MII_RXER ---------------------> none |
| 55 | + RMII_MII_TX_EN --------------------> PG11 |
| 56 | + RMII_MII_TXD0 ---------------------> PG13 |
| 57 | + RMII_MII_TXD1 ---------------------> PG14 |
| 58 | + */ |
| 59 | + /* Configure PA1, PA2 and PA7 */ |
| 60 | + GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; |
| 61 | + GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; |
| 62 | + GPIO_InitStructure.Pull = GPIO_NOPULL; |
| 63 | + GPIO_InitStructure.Alternate = GPIO_AF11_ETH; |
| 64 | + GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7; |
| 65 | + HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); |
| 66 | + |
| 67 | + /* Configure PC1, PC4 and PC5 */ |
| 68 | + GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5; |
| 69 | + HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); |
| 70 | + |
| 71 | + /* Configure PG2, PG11 and PG13 */ |
| 72 | + GPIO_InitStructure.Pin = GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14; |
| 73 | + HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); |
| 74 | + |
| 75 | + /* Enable the Ethernet global Interrupt */ |
| 76 | + HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0); |
| 77 | + HAL_NVIC_EnableIRQ(ETH_IRQn); |
| 78 | + |
| 79 | + /* Enable ETHERNET clock */ |
| 80 | + __HAL_RCC_ETH_CLK_ENABLE(); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +/** |
| 85 | + * Override HAL Eth DeInit function |
| 86 | + */ |
| 87 | +void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) |
| 88 | +{ |
| 89 | + if (heth->Instance == ETH) { |
| 90 | + /* Peripheral clock disable */ |
| 91 | + __HAL_RCC_ETH_CLK_DISABLE(); |
| 92 | + |
| 93 | + /** ETH GPIO Configuration |
| 94 | + RMII_REF_CLK ----------------------> PA1 |
| 95 | + RMII_MDIO -------------------------> PA2 |
| 96 | + RMII_MDC --------------------------> PC1 |
| 97 | + RMII_MII_CRS_DV -------------------> PA7 |
| 98 | + RMII_MII_RXD0 ---------------------> PC4 |
| 99 | + RMII_MII_RXD1 ---------------------> PC5 |
| 100 | + RMII_MII_RXER ---------------------> none |
| 101 | + RMII_MII_TX_EN --------------------> PG11 |
| 102 | + RMII_MII_TXD0 ---------------------> PG13 |
| 103 | + RMII_MII_TXD1 ---------------------> PG14 |
| 104 | + */ |
| 105 | + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7); |
| 106 | + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5); |
| 107 | + HAL_GPIO_DeInit(GPIOG, GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14); |
| 108 | + |
| 109 | + /* Disable the Ethernet global Interrupt */ |
| 110 | + NVIC_DisableIRQ(ETH_IRQn); |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ |
0 commit comments