Skip to content

Commit af9e073

Browse files
Merge pull request #5740 from ashok-rao/master
Adding MTB ublox ODIN W2 as a new target.
2 parents c00efae + c849db2 commit af9e073

File tree

4 files changed

+476
-0
lines changed

4 files changed

+476
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "stm32f4xx_hal.h"
18+
19+
void _eth_config_mac(ETH_HandleTypeDef *heth)
20+
{
21+
ETH_MACInitTypeDef macconf =
22+
{
23+
.Watchdog = ETH_WATCHDOG_ENABLE,
24+
.Jabber = ETH_JABBER_ENABLE,
25+
.InterFrameGap = ETH_INTERFRAMEGAP_96BIT,
26+
.CarrierSense = ETH_CARRIERSENCE_ENABLE,
27+
.ReceiveOwn = ETH_RECEIVEOWN_ENABLE,
28+
.LoopbackMode = ETH_LOOPBACKMODE_DISABLE,
29+
.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE,
30+
.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE,
31+
.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE,
32+
.BackOffLimit = ETH_BACKOFFLIMIT_10,
33+
.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE,
34+
.ReceiveAll = ETH_RECEIVEAll_DISABLE,
35+
.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE,
36+
.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL,
37+
.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE,
38+
.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL,
39+
.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE,
40+
.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_NONE, // Disable multicast filter
41+
.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT,
42+
.HashTableHigh = 0x0U,
43+
.HashTableLow = 0x0U,
44+
.PauseTime = 0x0U,
45+
.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE,
46+
.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4,
47+
.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE,
48+
.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE,
49+
.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE,
50+
.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT,
51+
.VLANTagIdentifier = 0x0U
52+
};
53+
54+
if (heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE) {
55+
macconf.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;
56+
} else {
57+
macconf.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
58+
}
59+
60+
(void) HAL_ETH_ConfigMAC(heth, &macconf);
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/* Copyright (c) 2017 ARM Limited
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
17+
#include <string.h>
18+
#include "stm32f4xx_hal.h"
19+
#include "mbed_toolchain.h"
20+
21+
#define C029_OTP_START_ADDRESS (0x1FFF7800U)
22+
#define C029_OTP_END_ADDRESS (C029_OTP_START_ADDRESS + (16*32))
23+
#define C029_MAC_ETHERNET_ID (3)
24+
25+
typedef MBED_PACKED(struct) C029_OTP_Header {
26+
uint8_t id;
27+
uint8_t len;
28+
uint8_t data[];
29+
} C029_OTP_Header;
30+
31+
static int _macRetrieved = 0;
32+
static char _macAddr[6] = { 0x02, 0x02, 0xF7, 0xF0, 0x00, 0x00 };
33+
34+
static C029_OTP_Header *increment(C029_OTP_Header *pTemp)
35+
{
36+
uint8_t len = 0;
37+
uint8_t id = 0;
38+
uint8_t *p = (uint8_t*)pTemp;
39+
40+
memcpy((void*)&id, (void*)pTemp, 1);
41+
42+
if (id == 0xFF){
43+
p++;
44+
} else {
45+
p++;
46+
memcpy((void*)&len, (void*)p++, 1);
47+
p += len;
48+
}
49+
return (C029_OTP_Header*)p;
50+
}
51+
52+
/**
53+
* Override HAL Eth Init function
54+
*/
55+
void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
56+
{
57+
GPIO_InitTypeDef GPIO_InitStructure;
58+
if (heth->Instance == ETH) {
59+
60+
/* Enable GPIOs clocks */
61+
__HAL_RCC_GPIOA_CLK_ENABLE();
62+
__HAL_RCC_GPIOB_CLK_ENABLE();
63+
__HAL_RCC_GPIOC_CLK_ENABLE();
64+
65+
/** ETH GPIO Configuration
66+
RMII_REF_CLK ----------------------> PA1
67+
RMII_MDIO -------------------------> PA2
68+
RMII_MDC --------------------------> PC1
69+
RMII_MII_CRS_DV -------------------> PA7
70+
RMII_MII_RXD0 ---------------------> PC4
71+
RMII_MII_RXD1 ---------------------> PC5
72+
RMII_MII_RXER ---------------------> PG2
73+
RMII_MII_TX_EN --------------------> PB11
74+
RMII_MII_TXD0 ---------------------> PB12
75+
RMII_MII_TXD1 ---------------------> PB13
76+
*/
77+
/* Configure PA1, PA2 and PA7 */
78+
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
79+
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
80+
GPIO_InitStructure.Pull = GPIO_PULLUP;
81+
GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_7;
82+
GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
83+
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
84+
85+
GPIO_InitStructure.Pull = GPIO_NOPULL;
86+
GPIO_InitStructure.Pin = GPIO_PIN_1;
87+
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
88+
89+
/* Configure PB13 */
90+
GPIO_InitStructure.Pin = GPIO_PIN_13 | GPIO_PIN_11 | GPIO_PIN_12;
91+
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
92+
93+
/* Configure PC1, PC4 and PC5 */
94+
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
95+
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
96+
97+
/* Enable the Ethernet global Interrupt */
98+
HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0);
99+
HAL_NVIC_EnableIRQ(ETH_IRQn);
100+
101+
/* Enable ETHERNET clock */
102+
__HAL_RCC_ETH_CLK_ENABLE();
103+
}
104+
}
105+
106+
/**
107+
* Override HAL Eth DeInit function
108+
*/
109+
void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
110+
{
111+
if (heth->Instance == ETH) {
112+
/* Peripheral clock disable */
113+
__HAL_RCC_ETH_CLK_DISABLE();
114+
115+
/** ETH GPIO Configuration
116+
RMII_REF_CLK ----------------------> PA1
117+
RMII_MDIO -------------------------> PA2
118+
RMII_MDC --------------------------> PC1
119+
RMII_MII_CRS_DV -------------------> PA7
120+
RMII_MII_RXD0 ---------------------> PC4
121+
RMII_MII_RXD1 ---------------------> PC5
122+
RMII_MII_RXER ---------------------> PG2
123+
RMII_MII_TX_EN --------------------> PB11
124+
RMII_MII_TXD0 ---------------------> PB12
125+
RMII_MII_TXD1 ---------------------> PB13
126+
*/
127+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7);
128+
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13 | GPIO_PIN_11 | GPIO_PIN_12);
129+
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5);
130+
131+
/* Disable the Ethernet global Interrupt */
132+
NVIC_DisableIRQ(ETH_IRQn);
133+
}
134+
}
135+
136+
uint8_t mbed_otp_mac_address(char *mac)
137+
{
138+
C029_OTP_Header *pFound = NULL;
139+
C029_OTP_Header *pTemp = (C029_OTP_Header*)C029_OTP_START_ADDRESS;
140+
C029_OTP_Header temp;
141+
142+
if (_macRetrieved == 0) {
143+
while ((pTemp >= (C029_OTP_Header*)C029_OTP_START_ADDRESS) && (pTemp < (C029_OTP_Header*)C029_OTP_END_ADDRESS)){
144+
memcpy((void*)&temp, (void*)pTemp, sizeof(temp));
145+
if (temp.id == C029_MAC_ETHERNET_ID){
146+
pFound = pTemp;
147+
break;
148+
}
149+
pTemp = increment(pTemp);
150+
}
151+
if (pFound != NULL) {
152+
memcpy(_macAddr, pFound->data, 6);
153+
_macRetrieved = 1;
154+
}
155+
}
156+
memcpy(mac, _macAddr, 6);
157+
158+
return 1;
159+
}

0 commit comments

Comments
 (0)