annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_eth.c @ 75:2b3f8ed4a0b8

Update version info
author Ideenmodellierer
date Thu, 04 Oct 2018 20:41:21 +0200
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_eth.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief ETH HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Ethernet (ETH) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral State and Errors functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 (#)Declare a ETH_HandleTypeDef handle structure, for example:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 ETH_HandleTypeDef heth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 (#)Fill parameters of Init structure in heth handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (#)Call HAL_ETH_Init() API to initialize the Ethernet peripheral (MAC, DMA, ...)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 (#)Initialize the ETH low level resources through the HAL_ETH_MspInit() API:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 (##) Enable the Ethernet interface clock using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (+++) __HAL_RCC_ETHMAC_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 (+++) __HAL_RCC_ETHMACTX_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+++) __HAL_RCC_ETHMACRX_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 (##) Initialize the related GPIO clocks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (##) Configure Ethernet pin-out
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 (##) Configure Ethernet NVIC interrupt (IT mode)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (#)Initialize Ethernet DMA Descriptors in chain mode and point to allocated buffers:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 (##) HAL_ETH_DMATxDescListInit(); for Transmission process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 (##) HAL_ETH_DMARxDescListInit(); for Reception process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 (#)Enable MAC and DMA transmission and reception:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 (##) HAL_ETH_Start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 (#)Prepare ETH DMA TX Descriptors and give the hand to ETH DMA to transfer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 the frame to MAC TX FIFO:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 (##) HAL_ETH_TransmitFrame();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 (#)Poll for a received frame in ETH RX DMA Descriptors and get received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 frame parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 (##) HAL_ETH_GetReceivedFrame(); (should be called into an infinite loop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 (#) Get a received frame when an ETH RX interrupt occurs:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 (##) HAL_ETH_GetReceivedFrame_IT(); (called in IT mode only)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 (#) Communicate with external PHY device:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 (##) Read a specific register from the PHY
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 HAL_ETH_ReadPHYRegister();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 (##) Write data to a specific RHY register:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 HAL_ETH_WritePHYRegister();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 (#) Configure the Ethernet MAC after ETH peripheral initialization
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 HAL_ETH_ConfigMAC(); all MAC parameters should be filled.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 (#) Configure the Ethernet DMA after ETH peripheral initialization
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 HAL_ETH_ConfigDMA(); all DMA parameters should be filled.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 -@- The PTP protocol and the DMA descriptors ring mode are not supported
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 in this driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 /** @defgroup ETH ETH
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 * @brief ETH HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 #ifdef HAL_ETH_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 /** @defgroup ETH_Private_Constants ETH Private Constants
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 #define LINKED_STATE_TIMEOUT_VALUE ((uint32_t)2000) /* 2000 ms */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 #define AUTONEGO_COMPLETED_TIMEOUT_VALUE ((uint32_t)1000) /* 1000 ms */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 /** @defgroup ETH_Private_Functions ETH Private Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 /** @defgroup ETH_Exported_Functions ETH Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 /** @defgroup ETH_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 (+) Initialize and configure the Ethernet peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 (+) De-initialize the Ethernet peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 * @brief Initializes the Ethernet MAC and DMA according to default
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 * parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 uint32_t tmpreg = 0, phyreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 uint32_t hclk = 60000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 uint32_t err = ETH_SUCCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 /* Check the ETH peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 if(heth == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 /* Check parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 assert_param(IS_ETH_AUTONEGOTIATION(heth->Init.AutoNegotiation));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 assert_param(IS_ETH_RX_MODE(heth->Init.RxMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 assert_param(IS_ETH_CHECKSUM_MODE(heth->Init.ChecksumMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 assert_param(IS_ETH_MEDIA_INTERFACE(heth->Init.MediaInterface));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 if(heth->State == HAL_ETH_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 /* Init the low level hardware : GPIO, CLOCK, NVIC. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 HAL_ETH_MspInit(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 /* Enable SYSCFG Clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 __HAL_RCC_SYSCFG_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 /* Select MII or RMII Mode*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 SYSCFG->PMC &= ~(SYSCFG_PMC_MII_RMII_SEL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 SYSCFG->PMC |= (uint32_t)heth->Init.MediaInterface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 /* Ethernet Software reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 /* Set the SWR bit: resets all MAC subsystem internal registers and logic */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 /* After reset all the registers holds their respective reset values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 (heth->Instance)->DMABMR |= ETH_DMABMR_SR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 /* Wait for software reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 while (((heth->Instance)->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 /*-------------------------------- MAC Initialization ----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 /* Get the ETHERNET MACMIIAR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 tmpreg = (heth->Instance)->MACMIIAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 /* Clear CSR Clock Range CR[2:0] bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 tmpreg &= ETH_MACMIIAR_CR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 /* Get hclk frequency value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 hclk = HAL_RCC_GetHCLKFreq();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 /* Set CR bits depending on hclk value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 if((hclk >= 20000000)&&(hclk < 35000000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 /* CSR Clock Range between 20-35 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 else if((hclk >= 35000000)&&(hclk < 60000000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 /* CSR Clock Range between 35-60 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div26;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 else if((hclk >= 60000000)&&(hclk < 100000000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 /* CSR Clock Range between 60-100 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 else if((hclk >= 100000000)&&(hclk < 150000000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 /* CSR Clock Range between 100-150 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div62;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 else /* ((hclk >= 150000000)&&(hclk <= 168000000)) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 /* CSR Clock Range between 150-168 MHz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div102;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 (heth->Instance)->MACMIIAR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 /*-------------------- PHY initialization and configuration ----------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 /* Put the PHY in reset mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 if((HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_RESET)) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 /* In case of write timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 err = ETH_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 /* Config MAC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 ETH_MACDMAConfig(heth, err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 /* Set the ETH peripheral state to READY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 /* Return HAL_ERROR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 /* Delay to assure PHY reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 HAL_Delay(PHY_RESET_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 if((heth->Init).AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 /* We wait for linked status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 if((HAL_GetTick() - tickstart ) > LINKED_STATE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 /* In case of write timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 err = ETH_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 /* Config MAC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 ETH_MACDMAConfig(heth, err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 } while (((phyreg & PHY_LINKED_STATUS) != PHY_LINKED_STATUS));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 /* Enable Auto-Negotiation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 if((HAL_ETH_WritePHYRegister(heth, PHY_BCR, PHY_AUTONEGOTIATION)) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 /* In case of write timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 err = ETH_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 /* Config MAC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 ETH_MACDMAConfig(heth, err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 /* Set the ETH peripheral state to READY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 /* Return HAL_ERROR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 /* Wait until the auto-negotiation will be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 if((HAL_GetTick() - tickstart ) > AUTONEGO_COMPLETED_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 /* In case of write timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 err = ETH_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 /* Config MAC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 ETH_MACDMAConfig(heth, err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 } while (((phyreg & PHY_AUTONEGO_COMPLETE) != PHY_AUTONEGO_COMPLETE));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 /* Read the result of the auto-negotiation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 if((HAL_ETH_ReadPHYRegister(heth, PHY_SR, &phyreg)) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 /* In case of write timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 err = ETH_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 /* Config MAC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 ETH_MACDMAConfig(heth, err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 /* Set the ETH peripheral state to READY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 /* Return HAL_ERROR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 /* Configure the MAC with the Duplex Mode fixed by the auto-negotiation process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 if((phyreg & PHY_DUPLEX_STATUS) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 /* Set Ethernet duplex mode to Full-duplex following the auto-negotiation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 (heth->Init).DuplexMode = ETH_MODE_FULLDUPLEX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 /* Set Ethernet duplex mode to Half-duplex following the auto-negotiation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 (heth->Init).DuplexMode = ETH_MODE_HALFDUPLEX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 /* Configure the MAC with the speed fixed by the auto-negotiation process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 if((phyreg & PHY_SPEED_STATUS) == PHY_SPEED_STATUS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 /* Set Ethernet speed to 10M following the auto-negotiation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 (heth->Init).Speed = ETH_SPEED_10M;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 /* Set Ethernet speed to 100M following the auto-negotiation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 (heth->Init).Speed = ETH_SPEED_100M;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 else /* AutoNegotiation Disable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 /* Check parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 assert_param(IS_ETH_SPEED(heth->Init.Speed));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 /* Set MAC Speed and Duplex Mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 if(HAL_ETH_WritePHYRegister(heth, PHY_BCR, ((uint16_t)((heth->Init).DuplexMode >> 3) |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 (uint16_t)((heth->Init).Speed >> 1))) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 /* In case of write timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 err = ETH_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 /* Config MAC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 ETH_MACDMAConfig(heth, err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 /* Set the ETH peripheral state to READY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 /* Return HAL_ERROR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 /* Delay to assure PHY configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 HAL_Delay(PHY_CONFIG_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 /* Config MAC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 ETH_MACDMAConfig(heth, err);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 /* Set ETH HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 * @brief De-Initializes the ETH peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 /* De-Init the low level hardware : GPIO, CLOCK, NVIC. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 HAL_ETH_MspDeInit(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 /* Set ETH HAL state to Disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 heth->State= HAL_ETH_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 /* Release Lock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 * @brief Initializes the DMA Tx descriptors in chain mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 * @param DMATxDescTab: Pointer to the first Tx desc list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 * @param TxBuff: Pointer to the first TxBuffer list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 * @param TxBuffCount: Number of the used Tx desc in the list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 HAL_StatusTypeDef HAL_ETH_DMATxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMATxDescTab, uint8_t *TxBuff, uint32_t TxBuffCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 uint32_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 ETH_DMADescTypeDef *dmatxdesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 /* Set the DMATxDescToSet pointer with the first one of the DMATxDescTab list */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 heth->TxDesc = DMATxDescTab;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 /* Fill each DMATxDesc descriptor with the right values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 for(i=0; i < TxBuffCount; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 /* Get the pointer on the ith member of the Tx Desc list */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 dmatxdesc = DMATxDescTab + i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 /* Set Second Address Chained bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 dmatxdesc->Status = ETH_DMATXDESC_TCH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 /* Set Buffer1 address pointer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 dmatxdesc->Buffer1Addr = (uint32_t)(&TxBuff[i*ETH_TX_BUF_SIZE]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 if ((heth->Init).ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 /* Set the DMA Tx descriptors checksum insertion */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 dmatxdesc->Status |= ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 /* Initialize the next descriptor with the Next Descriptor Polling Enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 if(i < (TxBuffCount-1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 /* Set next descriptor address register with next descriptor base address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 dmatxdesc->Buffer2NextDescAddr = (uint32_t)(DMATxDescTab+i+1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 dmatxdesc->Buffer2NextDescAddr = (uint32_t) DMATxDescTab;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 /* Set Transmit Descriptor List Address Register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 (heth->Instance)->DMATDLAR = (uint32_t) DMATxDescTab;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 /* Set ETH HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 * @brief Initializes the DMA Rx descriptors in chain mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 * @param DMARxDescTab: Pointer to the first Rx desc list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 * @param RxBuff: Pointer to the first RxBuffer list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 * @param RxBuffCount: Number of the used Rx desc in the list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 HAL_StatusTypeDef HAL_ETH_DMARxDescListInit(ETH_HandleTypeDef *heth, ETH_DMADescTypeDef *DMARxDescTab, uint8_t *RxBuff, uint32_t RxBuffCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 uint32_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 ETH_DMADescTypeDef *DMARxDesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 /* Set the Ethernet RxDesc pointer with the first one of the DMARxDescTab list */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 heth->RxDesc = DMARxDescTab;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 /* Fill each DMARxDesc descriptor with the right values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 for(i=0; i < RxBuffCount; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 /* Get the pointer on the ith member of the Rx Desc list */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 DMARxDesc = DMARxDescTab+i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 /* Set Own bit of the Rx descriptor Status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 DMARxDesc->Status = ETH_DMARXDESC_OWN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 /* Set Buffer1 size and Second Address Chained bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 DMARxDesc->ControlBufferSize = ETH_DMARXDESC_RCH | ETH_RX_BUF_SIZE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 /* Set Buffer1 address pointer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 DMARxDesc->Buffer1Addr = (uint32_t)(&RxBuff[i*ETH_RX_BUF_SIZE]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 if((heth->Init).RxMode == ETH_RXINTERRUPT_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 /* Enable Ethernet DMA Rx Descriptor interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 DMARxDesc->ControlBufferSize &= ~ETH_DMARXDESC_DIC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 /* Initialize the next descriptor with the Next Descriptor Polling Enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 if(i < (RxBuffCount-1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 /* Set next descriptor address register with next descriptor base address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab+i+1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 /* Set Receive Descriptor List Address Register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 (heth->Instance)->DMARDLAR = (uint32_t) DMARxDescTab;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 /* Set ETH HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 * @brief Initializes the ETH MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 __weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 the HAL_ETH_MspInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 * @brief DeInitializes ETH MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 __weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 the HAL_ETH_MspDeInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 /** @defgroup ETH_Exported_Functions_Group2 IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 * @brief Data transfers functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 ##### IO operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 (+) Transmit a frame
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 HAL_ETH_TransmitFrame();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 (+) Receive a frame
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 HAL_ETH_GetReceivedFrame();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 HAL_ETH_GetReceivedFrame_IT();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 (+) Read from an External PHY register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 HAL_ETH_ReadPHYRegister();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 (+) Write to an External PHY register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 HAL_ETH_WritePHYRegister();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 * @brief Sends an Ethernet frame.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 * @param FrameLength: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameLength)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 uint32_t bufcount = 0, size = 0, i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 if (FrameLength == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 /* Set ETH HAL state to READY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 if(((heth->TxDesc)->Status & ETH_DMATXDESC_OWN) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 /* OWN bit set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 heth->State = HAL_ETH_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 /* Get the number of needed Tx buffers for the current frame */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 if (FrameLength > ETH_TX_BUF_SIZE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 bufcount = FrameLength/ETH_TX_BUF_SIZE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 if (FrameLength % ETH_TX_BUF_SIZE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 bufcount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 bufcount = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 if (bufcount == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 /* Set LAST and FIRST segment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 heth->TxDesc->Status |=ETH_DMATXDESC_FS|ETH_DMATXDESC_LS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 /* Set frame size */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 heth->TxDesc->ControlBufferSize = (FrameLength & ETH_DMATXDESC_TBS1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 /* Point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 heth->TxDesc= (ETH_DMADescTypeDef *)(heth->TxDesc->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 for (i=0; i< bufcount; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 /* Clear FIRST and LAST segment bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 heth->TxDesc->Status &= ~(ETH_DMATXDESC_FS | ETH_DMATXDESC_LS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 if (i == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 /* Setting the first segment bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 heth->TxDesc->Status |= ETH_DMATXDESC_FS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 /* Program size */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 heth->TxDesc->ControlBufferSize = (ETH_TX_BUF_SIZE & ETH_DMATXDESC_TBS1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 if (i == (bufcount-1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 /* Setting the last segment bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 heth->TxDesc->Status |= ETH_DMATXDESC_LS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 size = FrameLength - (bufcount-1)*ETH_TX_BUF_SIZE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 heth->TxDesc->ControlBufferSize = (size & ETH_DMATXDESC_TBS1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 /* point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 heth->TxDesc = (ETH_DMADescTypeDef *)(heth->TxDesc->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 if (((heth->Instance)->DMASR & ETH_DMASR_TBUS) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 /* Clear TBUS ETHERNET DMA flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 (heth->Instance)->DMASR = ETH_DMASR_TBUS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 /* Resume DMA transmission*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 (heth->Instance)->DMATPDR = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 /* Set ETH HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 * @brief Checks for received frames.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 HAL_StatusTypeDef HAL_ETH_GetReceivedFrame(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 uint32_t framelength = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 /* Check the ETH state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 /* Check if segment is not owned by DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 /* (((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) && ((heth->RxDesc->Status & ETH_DMARXDESC_LS) != (uint32_t)RESET)) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 if(((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 /* Check if last segment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 if(((heth->RxDesc->Status & ETH_DMARXDESC_LS) != (uint32_t)RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 /* increment segment count */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 (heth->RxFrameInfos).SegCount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 /* Check if last segment is first segment: one segment contains the frame */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 if ((heth->RxFrameInfos).SegCount == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 (heth->RxFrameInfos).FSRxDesc =heth->RxDesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 heth->RxFrameInfos.LSRxDesc = heth->RxDesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 framelength = (((heth->RxDesc)->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 heth->RxFrameInfos.length = framelength;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 /* Get the address of the buffer start address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 heth->RxFrameInfos.buffer = ((heth->RxFrameInfos).FSRxDesc)->Buffer1Addr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 /* point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 heth->RxDesc = (ETH_DMADescTypeDef*) ((heth->RxDesc)->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 /* Set HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 /* Check if first segment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 else if((heth->RxDesc->Status & ETH_DMARXDESC_FS) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 (heth->RxFrameInfos).FSRxDesc = heth->RxDesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 (heth->RxFrameInfos).LSRxDesc = NULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 (heth->RxFrameInfos).SegCount = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 /* Point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 /* Check if intermediate segment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 (heth->RxFrameInfos).SegCount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 /* Point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 /* Set ETH HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 * @brief Gets the Received frame in interrupt mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 HAL_StatusTypeDef HAL_ETH_GetReceivedFrame_IT(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 uint32_t descriptorscancounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 /* Set ETH HAL State to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 /* Scan descriptors owned by CPU */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 while (((heth->RxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) && (descriptorscancounter < ETH_RXBUFNB))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 /* Just for security */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 descriptorscancounter++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 /* Check if first segment in frame */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 /* ((heth->RxDesc->Status & ETH_DMARXDESC_FS) != (uint32_t)RESET) && ((heth->RxDesc->Status & ETH_DMARXDESC_LS) == (uint32_t)RESET)) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 if((heth->RxDesc->Status & (ETH_DMARXDESC_FS | ETH_DMARXDESC_LS)) == (uint32_t)ETH_DMARXDESC_FS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 heth->RxFrameInfos.FSRxDesc = heth->RxDesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 heth->RxFrameInfos.SegCount = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 /* Point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 /* Check if intermediate segment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 /* ((heth->RxDesc->Status & ETH_DMARXDESC_LS) == (uint32_t)RESET)&& ((heth->RxDesc->Status & ETH_DMARXDESC_FS) == (uint32_t)RESET)) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 else if ((heth->RxDesc->Status & (ETH_DMARXDESC_LS | ETH_DMARXDESC_FS)) == (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 /* Increment segment count */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 (heth->RxFrameInfos.SegCount)++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 /* Point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 heth->RxDesc = (ETH_DMADescTypeDef*)(heth->RxDesc->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 /* Should be last segment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 /* Last segment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 heth->RxFrameInfos.LSRxDesc = heth->RxDesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 /* Increment segment count */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 (heth->RxFrameInfos.SegCount)++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 /* Check if last segment is first segment: one segment contains the frame */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 if ((heth->RxFrameInfos.SegCount) == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 heth->RxFrameInfos.FSRxDesc = heth->RxDesc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 heth->RxFrameInfos.length = (((heth->RxDesc)->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 /* Get the address of the buffer start address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 heth->RxFrameInfos.buffer =((heth->RxFrameInfos).FSRxDesc)->Buffer1Addr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 /* Point to next descriptor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 heth->RxDesc = (ETH_DMADescTypeDef*) (heth->RxDesc->Buffer2NextDescAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 /* Set HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 /* Set HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 * @brief This function handles ETH interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 /* Frame received */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 if (__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_R))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 /* Receive complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 HAL_ETH_RxCpltCallback(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 /* Clear the Eth DMA Rx IT pending bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_R);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 /* Set HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 /* Frame transmitted */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 else if (__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_T))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 /* Transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 HAL_ETH_TxCpltCallback(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 /* Clear the Eth DMA Tx IT pending bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_T);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 /* Set HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 /* Clear the interrupt flags */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_IT_NIS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 /* ETH DMA Error */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 if(__HAL_ETH_DMA_GET_FLAG(heth, ETH_DMA_FLAG_AIS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 /* Ethernet Error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 HAL_ETH_ErrorCallback(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 /* Clear the interrupt flags */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 __HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_FLAG_AIS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 /* Set HAL State to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 * @brief Tx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 __weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 the HAL_ETH_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 * @brief Rx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 __weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 the HAL_ETH_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 * @brief Ethernet transfer error callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 __weak void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 the HAL_ETH_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 * @brief Reads a PHY register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 * PHY_BCR: Transceiver Basic Control Register,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 * PHY_BSR: Transceiver Basic Status Register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 * More PHY register could be read depending on the used PHY
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 * @param RegValue: PHY register value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t *RegValue)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 /* Check parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 /* Check the ETH peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 if(heth->State == HAL_ETH_STATE_BUSY_RD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 /* Set ETH HAL State to BUSY_RD */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 heth->State = HAL_ETH_STATE_BUSY_RD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 /* Get the ETHERNET MACMIIAR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 tmpreg = heth->Instance->MACMIIAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 /* Keep only the CSR Clock Range CR[2:0] bits value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 tmpreg &= ~ETH_MACMIIAR_CR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 /* Prepare the MII address register value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 tmpreg |=(((uint32_t)heth->Init.PhyAddress << 11) & ETH_MACMIIAR_PA); /* Set the PHY device address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR); /* Set the PHY register address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 tmpreg &= ~ETH_MACMIIAR_MW; /* Set the read mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 /* Write the result value into the MII Address register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 heth->Instance->MACMIIAR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 /* Check for the Busy flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 while((tmpreg & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 if((HAL_GetTick() - tickstart ) > PHY_READ_TO)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 tmpreg = heth->Instance->MACMIIAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 /* Get MACMIIDR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 *RegValue = (uint16_t)(heth->Instance->MACMIIDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 /* Set ETH HAL State to READY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 * @brief Writes to a PHY register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 * PHY_BCR: Transceiver Control Register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 * More PHY register could be written depending on the used PHY
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 * @param RegValue: the value to write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 HAL_StatusTypeDef HAL_ETH_WritePHYRegister(ETH_HandleTypeDef *heth, uint16_t PHYReg, uint32_t RegValue)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 /* Check parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 assert_param(IS_ETH_PHY_ADDRESS(heth->Init.PhyAddress));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 /* Check the ETH peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 if(heth->State == HAL_ETH_STATE_BUSY_WR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 /* Set ETH HAL State to BUSY_WR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 heth->State = HAL_ETH_STATE_BUSY_WR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 /* Get the ETHERNET MACMIIAR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 tmpreg = heth->Instance->MACMIIAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 /* Keep only the CSR Clock Range CR[2:0] bits value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 tmpreg &= ~ETH_MACMIIAR_CR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 /* Prepare the MII register address value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 tmpreg |=(((uint32_t)heth->Init.PhyAddress<<11) & ETH_MACMIIAR_PA); /* Set the PHY device address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR); /* Set the PHY register address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 tmpreg |= ETH_MACMIIAR_MW; /* Set the write mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 /* Give the value to the MII data register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 heth->Instance->MACMIIDR = (uint16_t)RegValue;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 /* Write the result value into the MII Address register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 heth->Instance->MACMIIAR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 /* Check for the Busy flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 while((tmpreg & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 if((HAL_GetTick() - tickstart ) > PHY_WRITE_TO)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 tmpreg = heth->Instance->MACMIIAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 /* Set ETH HAL State to READY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 /** @defgroup ETH_Exported_Functions_Group3 Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 * @brief Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 (+) Enable MAC and DMA transmission and reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 HAL_ETH_Start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 (+) Disable MAC and DMA transmission and reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 HAL_ETH_Stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 (+) Set the MAC configuration in runtime mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 HAL_ETH_ConfigMAC();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 (+) Set the DMA configuration in runtime mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 HAL_ETH_ConfigDMA();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 * @brief Enables Ethernet MAC and DMA reception/transmission
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 /* Enable transmit state machine of the MAC for transmission on the MII */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 ETH_MACTransmissionEnable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 /* Enable receive state machine of the MAC for reception from the MII */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 ETH_MACReceptionEnable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 /* Flush Transmit FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 ETH_FlushTransmitFIFO(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 /* Start DMA transmission */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 ETH_DMATransmissionEnable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 /* Start DMA reception */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 ETH_DMAReceptionEnable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 /* Set the ETH state to READY*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 * @brief Stop Ethernet MAC and DMA reception/transmission
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 heth->State = HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 /* Stop DMA transmission */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 ETH_DMATransmissionDisable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 /* Stop DMA reception */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 ETH_DMAReceptionDisable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 /* Disable receive state machine of the MAC for reception from the MII */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 ETH_MACReceptionDisable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 /* Flush Transmit FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 ETH_FlushTransmitFIFO(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 /* Disable transmit state machine of the MAC for transmission on the MII */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 ETH_MACTransmissionDisable(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 /* Set the ETH state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 heth->State = HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 * @brief Set ETH MAC Configuration.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 * @param macconf: MAC Configuration structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 HAL_StatusTypeDef HAL_ETH_ConfigMAC(ETH_HandleTypeDef *heth, ETH_MACInitTypeDef *macconf)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 heth->State= HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 assert_param(IS_ETH_SPEED(heth->Init.Speed));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 assert_param(IS_ETH_DUPLEX_MODE(heth->Init.DuplexMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 if (macconf != NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 assert_param(IS_ETH_WATCHDOG(macconf->Watchdog));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 assert_param(IS_ETH_JABBER(macconf->Jabber));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 assert_param(IS_ETH_INTER_FRAME_GAP(macconf->InterFrameGap));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 assert_param(IS_ETH_CARRIER_SENSE(macconf->CarrierSense));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 assert_param(IS_ETH_RECEIVE_OWN(macconf->ReceiveOwn));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 assert_param(IS_ETH_LOOPBACK_MODE(macconf->LoopbackMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 assert_param(IS_ETH_CHECKSUM_OFFLOAD(macconf->ChecksumOffload));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 assert_param(IS_ETH_RETRY_TRANSMISSION(macconf->RetryTransmission));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(macconf->AutomaticPadCRCStrip));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 assert_param(IS_ETH_BACKOFF_LIMIT(macconf->BackOffLimit));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 assert_param(IS_ETH_DEFERRAL_CHECK(macconf->DeferralCheck));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 assert_param(IS_ETH_RECEIVE_ALL(macconf->ReceiveAll));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 assert_param(IS_ETH_SOURCE_ADDR_FILTER(macconf->SourceAddrFilter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 assert_param(IS_ETH_CONTROL_FRAMES(macconf->PassControlFrames));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(macconf->BroadcastFramesReception));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 assert_param(IS_ETH_DESTINATION_ADDR_FILTER(macconf->DestinationAddrFilter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 assert_param(IS_ETH_PROMISCUOUS_MODE(macconf->PromiscuousMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(macconf->MulticastFramesFilter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 assert_param(IS_ETH_UNICAST_FRAMES_FILTER(macconf->UnicastFramesFilter));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 assert_param(IS_ETH_PAUSE_TIME(macconf->PauseTime));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 assert_param(IS_ETH_ZEROQUANTA_PAUSE(macconf->ZeroQuantaPause));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(macconf->PauseLowThreshold));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(macconf->UnicastPauseFrameDetect));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 assert_param(IS_ETH_RECEIVE_FLOWCONTROL(macconf->ReceiveFlowControl));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(macconf->TransmitFlowControl));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 assert_param(IS_ETH_VLAN_TAG_COMPARISON(macconf->VLANTagComparison));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(macconf->VLANTagIdentifier));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 /*------------------------ ETHERNET MACCR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 /* Get the ETHERNET MACCR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 /* Clear WD, PCE, PS, TE and RE bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 tmpreg &= ETH_MACCR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 tmpreg |= (uint32_t)(macconf->Watchdog |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 macconf->Jabber |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 macconf->InterFrameGap |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 macconf->CarrierSense |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 (heth->Init).Speed |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 macconf->ReceiveOwn |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 macconf->LoopbackMode |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 (heth->Init).DuplexMode |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 macconf->ChecksumOffload |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 macconf->RetryTransmission |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 macconf->AutomaticPadCRCStrip |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 macconf->BackOffLimit |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 macconf->DeferralCheck);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 /* Write to ETHERNET MACCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 (heth->Instance)->MACCR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 /* Wait until the write operation will be taken into account :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 (heth->Instance)->MACCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 /*----------------------- ETHERNET MACFFR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 /* Write to ETHERNET MACFFR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 (heth->Instance)->MACFFR = (uint32_t)(macconf->ReceiveAll |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 macconf->SourceAddrFilter |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 macconf->PassControlFrames |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 macconf->BroadcastFramesReception |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 macconf->DestinationAddrFilter |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 macconf->PromiscuousMode |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 macconf->MulticastFramesFilter |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 macconf->UnicastFramesFilter);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 /* Wait until the write operation will be taken into account :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 tmpreg = (heth->Instance)->MACFFR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 (heth->Instance)->MACFFR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 /* Write to ETHERNET MACHTHR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 (heth->Instance)->MACHTHR = (uint32_t)macconf->HashTableHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 /* Write to ETHERNET MACHTLR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 (heth->Instance)->MACHTLR = (uint32_t)macconf->HashTableLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 /*----------------------- ETHERNET MACFCR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371 /* Get the ETHERNET MACFCR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 tmpreg = (heth->Instance)->MACFCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 /* Clear xx bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 tmpreg &= ETH_MACFCR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 tmpreg |= (uint32_t)((macconf->PauseTime << 16) |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 macconf->ZeroQuantaPause |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 macconf->PauseLowThreshold |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 macconf->UnicastPauseFrameDetect |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 macconf->ReceiveFlowControl |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 macconf->TransmitFlowControl);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 /* Write to ETHERNET MACFCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 (heth->Instance)->MACFCR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 /* Wait until the write operation will be taken into account :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 tmpreg = (heth->Instance)->MACFCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 (heth->Instance)->MACFCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392 /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 (heth->Instance)->MACVLANTR = (uint32_t)(macconf->VLANTagComparison |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 macconf->VLANTagIdentifier);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 /* Wait until the write operation will be taken into account :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398 tmpreg = (heth->Instance)->MACVLANTR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400 (heth->Instance)->MACVLANTR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 else /* macconf == NULL : here we just configure Speed and Duplex mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 /*------------------------ ETHERNET MACCR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 /* Get the ETHERNET MACCR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408 /* Clear FES and DM bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409 tmpreg &= ~((uint32_t)0x00004800);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 tmpreg |= (uint32_t)(heth->Init.Speed | heth->Init.DuplexMode);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 /* Write to ETHERNET MACCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 (heth->Instance)->MACCR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 (heth->Instance)->MACCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423 /* Set the ETH state to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 * @brief Sets ETH DMA Configuration.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437 * @param dmaconf: DMA Configuration structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 HAL_StatusTypeDef HAL_ETH_ConfigDMA(ETH_HandleTypeDef *heth, ETH_DMAInitTypeDef *dmaconf)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 __HAL_LOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447 /* Set the ETH peripheral state to BUSY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 heth->State= HAL_ETH_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450 /* Check parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(dmaconf->DropTCPIPChecksumErrorFrame));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 assert_param(IS_ETH_RECEIVE_STORE_FORWARD(dmaconf->ReceiveStoreForward));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453 assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(dmaconf->FlushReceivedFrame));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(dmaconf->TransmitStoreForward));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(dmaconf->TransmitThresholdControl));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456 assert_param(IS_ETH_FORWARD_ERROR_FRAMES(dmaconf->ForwardErrorFrames));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(dmaconf->ForwardUndersizedGoodFrames));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(dmaconf->ReceiveThresholdControl));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 assert_param(IS_ETH_SECOND_FRAME_OPERATE(dmaconf->SecondFrameOperate));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(dmaconf->AddressAlignedBeats));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 assert_param(IS_ETH_FIXED_BURST(dmaconf->FixedBurst));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 assert_param(IS_ETH_RXDMA_BURST_LENGTH(dmaconf->RxDMABurstLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 assert_param(IS_ETH_TXDMA_BURST_LENGTH(dmaconf->TxDMABurstLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464 assert_param(IS_ETH_ENHANCED_DESCRIPTOR_FORMAT(dmaconf->EnhancedDescriptorFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(dmaconf->DescriptorSkipLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(dmaconf->DMAArbitration));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 /*----------------------- ETHERNET DMAOMR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469 /* Get the ETHERNET DMAOMR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 tmpreg = (heth->Instance)->DMAOMR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 /* Clear xx bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 tmpreg &= ETH_DMAOMR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 tmpreg |= (uint32_t)(dmaconf->DropTCPIPChecksumErrorFrame |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 dmaconf->ReceiveStoreForward |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 dmaconf->FlushReceivedFrame |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477 dmaconf->TransmitStoreForward |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478 dmaconf->TransmitThresholdControl |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479 dmaconf->ForwardErrorFrames |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 dmaconf->ForwardUndersizedGoodFrames |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481 dmaconf->ReceiveThresholdControl |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 dmaconf->SecondFrameOperate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 /* Write to ETHERNET DMAOMR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 (heth->Instance)->DMAOMR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 tmpreg = (heth->Instance)->DMAOMR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 (heth->Instance)->DMAOMR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 /*----------------------- ETHERNET DMABMR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 (heth->Instance)->DMABMR = (uint32_t)(dmaconf->AddressAlignedBeats |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 dmaconf->FixedBurst |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 dmaconf->RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497 dmaconf->TxDMABurstLength |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 dmaconf->EnhancedDescriptorFormat |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 (dmaconf->DescriptorSkipLength << 2) |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500 dmaconf->DMAArbitration |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 tmpreg = (heth->Instance)->DMABMR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507 (heth->Instance)->DMABMR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 /* Set the ETH state to Ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 heth->State= HAL_ETH_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 __HAL_UNLOCK(heth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 /** @defgroup ETH_Exported_Functions_Group4 Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 * @brief Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528 ##### Peripheral State functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 This subsection permits to get in run-time the status of the peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 and the data flow.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 (+) Get the ETH handle state:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 HAL_ETH_GetState();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 * @brief Return the ETH HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547 HAL_ETH_StateTypeDef HAL_ETH_GetState(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 /* Return ETH state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550 return heth->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 /** @addtogroup ETH_Private_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566 * @brief Configures Ethernet MAC and DMA with default parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569 * @param err: Ethernet Init error
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 ETH_MACInitTypeDef macinit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 ETH_DMAInitTypeDef dmainit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 if (err != ETH_SUCCESS) /* Auto-negotiation failed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 /* Set Ethernet duplex mode to Full-duplex */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 (heth->Init).DuplexMode = ETH_MODE_FULLDUPLEX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583 /* Set Ethernet speed to 100M */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 (heth->Init).Speed = ETH_SPEED_100M;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 /* Ethernet MAC default initialization **************************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 macinit.Watchdog = ETH_WATCHDOG_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589 macinit.Jabber = ETH_JABBER_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 macinit.InterFrameGap = ETH_INTERFRAMEGAP_96BIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 macinit.CarrierSense = ETH_CARRIERSENCE_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 macinit.ReceiveOwn = ETH_RECEIVEOWN_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 macinit.LoopbackMode = ETH_LOOPBACKMODE_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 if(heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 macinit.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 macinit.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 macinit.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604 macinit.BackOffLimit = ETH_BACKOFFLIMIT_10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605 macinit.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 macinit.ReceiveAll = ETH_RECEIVEAll_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 macinit.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 macinit.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 macinit.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610 macinit.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611 macinit.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612 macinit.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 macinit.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 macinit.HashTableHigh = 0x0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 macinit.HashTableLow = 0x0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616 macinit.PauseTime = 0x0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 macinit.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618 macinit.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 macinit.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620 macinit.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621 macinit.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622 macinit.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623 macinit.VLANTagIdentifier = 0x0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 /*------------------------ ETHERNET MACCR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 /* Get the ETHERNET MACCR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 /* Clear WD, PCE, PS, TE and RE bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629 tmpreg &= ETH_MACCR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 /* Set the WD bit according to ETH Watchdog value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 /* Set the JD: bit according to ETH Jabber value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632 /* Set the IFG bit according to ETH InterFrameGap value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 /* Set the DCRS bit according to ETH CarrierSense value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 /* Set the FES bit according to ETH Speed value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 /* Set the DO bit according to ETH ReceiveOwn value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636 /* Set the LM bit according to ETH LoopbackMode value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 /* Set the DM bit according to ETH Mode value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638 /* Set the IPCO bit according to ETH ChecksumOffload value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 /* Set the DR bit according to ETH RetryTransmission value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641 /* Set the BL bit according to ETH BackOffLimit value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642 /* Set the DC bit according to ETH DeferralCheck value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 tmpreg |= (uint32_t)(macinit.Watchdog |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644 macinit.Jabber |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 macinit.InterFrameGap |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 macinit.CarrierSense |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 (heth->Init).Speed |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 macinit.ReceiveOwn |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649 macinit.LoopbackMode |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 (heth->Init).DuplexMode |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 macinit.ChecksumOffload |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 macinit.RetryTransmission |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 macinit.AutomaticPadCRCStrip |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 macinit.BackOffLimit |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655 macinit.DeferralCheck);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 /* Write to ETHERNET MACCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 (heth->Instance)->MACCR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 (heth->Instance)->MACCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666 /*----------------------- ETHERNET MACFFR Configuration --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 /* Set the RA bit according to ETH ReceiveAll value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 /* Set the PCF bit according to ETH PassControlFrames value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670 /* Set the DBF bit according to ETH BroadcastFramesReception value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671 /* Set the DAIF bit according to ETH DestinationAddrFilter value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672 /* Set the PR bit according to ETH PromiscuousMode value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 /* Write to ETHERNET MACFFR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 (heth->Instance)->MACFFR = (uint32_t)(macinit.ReceiveAll |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677 macinit.SourceAddrFilter |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 macinit.PassControlFrames |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 macinit.BroadcastFramesReception |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680 macinit.DestinationAddrFilter |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 macinit.PromiscuousMode |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682 macinit.MulticastFramesFilter |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 macinit.UnicastFramesFilter);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687 tmpreg = (heth->Instance)->MACFFR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689 (heth->Instance)->MACFFR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 /*--------------- ETHERNET MACHTHR and MACHTLR Configuration --------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692 /* Write to ETHERNET MACHTHR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693 (heth->Instance)->MACHTHR = (uint32_t)macinit.HashTableHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1694
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695 /* Write to ETHERNET MACHTLR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696 (heth->Instance)->MACHTLR = (uint32_t)macinit.HashTableLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697 /*----------------------- ETHERNET MACFCR Configuration -------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699 /* Get the ETHERNET MACFCR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 tmpreg = (heth->Instance)->MACFCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701 /* Clear xx bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1702 tmpreg &= ETH_MACFCR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 /* Set the PT bit according to ETH PauseTime value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1705 /* Set the DZPQ bit according to ETH ZeroQuantaPause value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706 /* Set the PLT bit according to ETH PauseLowThreshold value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 /* Set the UP bit according to ETH UnicastPauseFrameDetect value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1708 /* Set the RFE bit according to ETH ReceiveFlowControl value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1709 /* Set the TFE bit according to ETH TransmitFlowControl value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1710 tmpreg |= (uint32_t)((macinit.PauseTime << 16) |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1711 macinit.ZeroQuantaPause |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1712 macinit.PauseLowThreshold |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1713 macinit.UnicastPauseFrameDetect |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1714 macinit.ReceiveFlowControl |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1715 macinit.TransmitFlowControl);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1717 /* Write to ETHERNET MACFCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1718 (heth->Instance)->MACFCR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1719
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1720 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1721 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1722 tmpreg = (heth->Instance)->MACFCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1723 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1724 (heth->Instance)->MACFCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1725
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1726 /*----------------------- ETHERNET MACVLANTR Configuration ----------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1727 /* Set the ETV bit according to ETH VLANTagComparison value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1728 /* Set the VL bit according to ETH VLANTagIdentifier value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1729 (heth->Instance)->MACVLANTR = (uint32_t)(macinit.VLANTagComparison |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1730 macinit.VLANTagIdentifier);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1731
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1732 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1733 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1734 tmpreg = (heth->Instance)->MACVLANTR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1735 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1736 (heth->Instance)->MACVLANTR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1737
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1738 /* Ethernet DMA default initialization ************************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1739 dmainit.DropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1740 dmainit.ReceiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1741 dmainit.FlushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1742 dmainit.TransmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1743 dmainit.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1744 dmainit.ForwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1745 dmainit.ForwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1746 dmainit.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1747 dmainit.SecondFrameOperate = ETH_SECONDFRAMEOPERARTE_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1748 dmainit.AddressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1749 dmainit.FixedBurst = ETH_FIXEDBURST_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1750 dmainit.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1751 dmainit.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1752 dmainit.EnhancedDescriptorFormat = ETH_DMAENHANCEDDESCRIPTOR_ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1753 dmainit.DescriptorSkipLength = 0x0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1754 dmainit.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1755
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1756 /* Get the ETHERNET DMAOMR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1757 tmpreg = (heth->Instance)->DMAOMR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1758 /* Clear xx bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1759 tmpreg &= ETH_DMAOMR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1760
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1761 /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1762 /* Set the RSF bit according to ETH ReceiveStoreForward value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1763 /* Set the DFF bit according to ETH FlushReceivedFrame value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1764 /* Set the TSF bit according to ETH TransmitStoreForward value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1765 /* Set the TTC bit according to ETH TransmitThresholdControl value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1766 /* Set the FEF bit according to ETH ForwardErrorFrames value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1767 /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1768 /* Set the RTC bit according to ETH ReceiveThresholdControl value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1769 /* Set the OSF bit according to ETH SecondFrameOperate value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1770 tmpreg |= (uint32_t)(dmainit.DropTCPIPChecksumErrorFrame |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1771 dmainit.ReceiveStoreForward |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1772 dmainit.FlushReceivedFrame |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1773 dmainit.TransmitStoreForward |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1774 dmainit.TransmitThresholdControl |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1775 dmainit.ForwardErrorFrames |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1776 dmainit.ForwardUndersizedGoodFrames |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1777 dmainit.ReceiveThresholdControl |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1778 dmainit.SecondFrameOperate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1780 /* Write to ETHERNET DMAOMR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1781 (heth->Instance)->DMAOMR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1782
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1783 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1784 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1785 tmpreg = (heth->Instance)->DMAOMR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1786 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1787 (heth->Instance)->DMAOMR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1788
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1789 /*----------------------- ETHERNET DMABMR Configuration ------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1790 /* Set the AAL bit according to ETH AddressAlignedBeats value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1791 /* Set the FB bit according to ETH FixedBurst value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1792 /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1793 /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1794 /* Set the Enhanced DMA descriptors bit according to ETH EnhancedDescriptorFormat value*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1795 /* Set the DSL bit according to ETH DesciptorSkipLength value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1796 /* Set the PR and DA bits according to ETH DMAArbitration value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1797 (heth->Instance)->DMABMR = (uint32_t)(dmainit.AddressAlignedBeats |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1798 dmainit.FixedBurst |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1799 dmainit.RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1800 dmainit.TxDMABurstLength |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1801 dmainit.EnhancedDescriptorFormat |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1802 (dmainit.DescriptorSkipLength << 2) |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1803 dmainit.DMAArbitration |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1804 ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1805
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1806 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1807 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1808 tmpreg = (heth->Instance)->DMABMR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1809 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1810 (heth->Instance)->DMABMR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1811
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1812 if((heth->Init).RxMode == ETH_RXINTERRUPT_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1813 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1814 /* Enable the Ethernet Rx Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1815 __HAL_ETH_DMA_ENABLE_IT((heth), ETH_DMA_IT_NIS | ETH_DMA_IT_R);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1816 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1817
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1818 /* Initialize MAC address in ethernet MAC */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1819 ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1820 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1821
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1822 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1823 * @brief Configures the selected MAC address.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1824 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1825 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1826 * @param MacAddr: The MAC address to configure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1827 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1828 * @arg ETH_MAC_Address0: MAC Address0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1829 * @arg ETH_MAC_Address1: MAC Address1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1830 * @arg ETH_MAC_Address2: MAC Address2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1831 * @arg ETH_MAC_Address3: MAC Address3
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1832 * @param Addr: Pointer to MAC address buffer data (6 bytes)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1833 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1834 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1835 static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1836 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1837 uint32_t tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1838
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1839 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1840 assert_param(IS_ETH_MAC_ADDRESS0123(MacAddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1841
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1842 /* Calculate the selected MAC address high register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1843 tmpreg = ((uint32_t)Addr[5] << 8) | (uint32_t)Addr[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1844 /* Load the selected MAC address high register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1845 (*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_HBASE + MacAddr))) = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1846 /* Calculate the selected MAC address low register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1847 tmpreg = ((uint32_t)Addr[3] << 24) | ((uint32_t)Addr[2] << 16) | ((uint32_t)Addr[1] << 8) | Addr[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1848
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1849 /* Load the selected MAC address low register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1850 (*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_LBASE + MacAddr))) = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1851 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1852
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1853 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1854 * @brief Enables the MAC transmission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1855 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1856 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1857 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1858 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1859 static void ETH_MACTransmissionEnable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1860 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1861 __IO uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1862
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1863 /* Enable the MAC transmission */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1864 (heth->Instance)->MACCR |= ETH_MACCR_TE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1865
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1866 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1867 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1868 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1869 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1870 (heth->Instance)->MACCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1871 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1872
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1873 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1874 * @brief Disables the MAC transmission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1875 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1876 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1877 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1878 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1879 static void ETH_MACTransmissionDisable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1880 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1881 __IO uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1882
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1883 /* Disable the MAC transmission */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1884 (heth->Instance)->MACCR &= ~ETH_MACCR_TE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1885
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1886 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1887 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1888 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1889 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1890 (heth->Instance)->MACCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1891 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1892
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1893 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1894 * @brief Enables the MAC reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1895 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1896 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1897 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1898 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1899 static void ETH_MACReceptionEnable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1900 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1901 __IO uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1902
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1903 /* Enable the MAC reception */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1904 (heth->Instance)->MACCR |= ETH_MACCR_RE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1905
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1906 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1907 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1908 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1909 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1910 (heth->Instance)->MACCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1911 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1912
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1913 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1914 * @brief Disables the MAC reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1915 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1916 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1917 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1918 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1919 static void ETH_MACReceptionDisable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1920 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1921 __IO uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1922
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1923 /* Disable the MAC reception */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1924 (heth->Instance)->MACCR &= ~ETH_MACCR_RE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1925
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1926 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1927 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1928 tmpreg = (heth->Instance)->MACCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1929 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1930 (heth->Instance)->MACCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1931 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1932
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1933 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1934 * @brief Enables the DMA transmission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1935 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1936 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1937 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1938 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1939 static void ETH_DMATransmissionEnable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1940 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1941 /* Enable the DMA transmission */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1942 (heth->Instance)->DMAOMR |= ETH_DMAOMR_ST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1943 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1944
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1945 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1946 * @brief Disables the DMA transmission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1947 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1948 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1949 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1950 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1951 static void ETH_DMATransmissionDisable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1952 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1953 /* Disable the DMA transmission */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1954 (heth->Instance)->DMAOMR &= ~ETH_DMAOMR_ST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1955 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1956
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1957 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1958 * @brief Enables the DMA reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1959 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1960 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1961 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1962 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1963 static void ETH_DMAReceptionEnable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1964 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1965 /* Enable the DMA reception */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1966 (heth->Instance)->DMAOMR |= ETH_DMAOMR_SR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1967 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1968
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1969 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1970 * @brief Disables the DMA reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1971 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1972 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1973 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1974 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1975 static void ETH_DMAReceptionDisable(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1976 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1977 /* Disable the DMA reception */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1978 (heth->Instance)->DMAOMR &= ~ETH_DMAOMR_SR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1979 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1980
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1981 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1982 * @brief Clears the ETHERNET transmit FIFO.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1983 * @param heth: pointer to a ETH_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1984 * the configuration information for ETHERNET module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1985 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1986 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1987 static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1988 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1989 __IO uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1990
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1991 /* Set the Flush Transmit FIFO bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1992 (heth->Instance)->DMAOMR |= ETH_DMAOMR_FTF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1993
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1994 /* Wait until the write operation will be taken into account:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1995 at least four TX_CLK/RX_CLK clock cycles */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1996 tmpreg = (heth->Instance)->DMAOMR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1997 HAL_Delay(ETH_REG_WRITE_DELAY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1998 (heth->Instance)->DMAOMR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1999 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2001 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2002 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2003 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2004
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2005 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2006 #endif /* HAL_ETH_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2007 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2008 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2009 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2010
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2011 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2012 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2013 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2015 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/