Skip to content

Commit dc3c7fc

Browse files
Ashok RaoAshok Rao
authored andcommitted
Adding MTB ublox ODIN W2
1 parent 9ebefcd commit dc3c7fc

File tree

4 files changed

+461
-0
lines changed

4 files changed

+461
-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,143 @@
1+
#include <string.h>
2+
#include "stm32f4xx_hal.h"
3+
#include "mbed_toolchain.h"
4+
5+
#define C029_OTP_START_ADDRESS (0x1FFF7800U)
6+
#define C029_OTP_END_ADDRESS (C029_OTP_START_ADDRESS + (16*32))
7+
#define C029_MAC_ETHERNET_ID (3)
8+
9+
typedef MBED_PACKED(struct) C029_OTP_Header {
10+
uint8_t id;
11+
uint8_t len;
12+
uint8_t data[];
13+
} C029_OTP_Header;
14+
15+
static int _macRetrieved = 0;
16+
static char _macAddr[6] = { 0x02, 0x02, 0xF7, 0xF0, 0x00, 0x00 };
17+
18+
static C029_OTP_Header *increment(C029_OTP_Header *pTemp)
19+
{
20+
uint8_t len = 0;
21+
uint8_t id = 0;
22+
uint8_t *p = (uint8_t*)pTemp;
23+
24+
memcpy((void*)&id, (void*)pTemp, 1);
25+
26+
if (id == 0xFF){
27+
p++;
28+
} else {
29+
p++;
30+
memcpy((void*)&len, (void*)p++, 1);
31+
p += len;
32+
}
33+
return (C029_OTP_Header*)p;
34+
}
35+
36+
/**
37+
* Override HAL Eth Init function
38+
*/
39+
void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
40+
{
41+
GPIO_InitTypeDef GPIO_InitStructure;
42+
if (heth->Instance == ETH) {
43+
44+
/* Enable GPIOs clocks */
45+
__HAL_RCC_GPIOA_CLK_ENABLE();
46+
__HAL_RCC_GPIOB_CLK_ENABLE();
47+
__HAL_RCC_GPIOC_CLK_ENABLE();
48+
49+
/** ETH GPIO Configuration
50+
RMII_REF_CLK ----------------------> PA1
51+
RMII_MDIO -------------------------> PA2
52+
RMII_MDC --------------------------> PC1
53+
RMII_MII_CRS_DV -------------------> PA7
54+
RMII_MII_RXD0 ---------------------> PC4
55+
RMII_MII_RXD1 ---------------------> PC5
56+
RMII_MII_RXER ---------------------> PG2
57+
RMII_MII_TX_EN --------------------> PB11
58+
RMII_MII_TXD0 ---------------------> PB12
59+
RMII_MII_TXD1 ---------------------> PB13
60+
*/
61+
/* Configure PA1, PA2 and PA7 */
62+
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
63+
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
64+
GPIO_InitStructure.Pull = GPIO_PULLUP;
65+
GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_7;
66+
GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
67+
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
68+
69+
GPIO_InitStructure.Pull = GPIO_NOPULL;
70+
GPIO_InitStructure.Pin = GPIO_PIN_1;
71+
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
72+
73+
/* Configure PB13 */
74+
GPIO_InitStructure.Pin = GPIO_PIN_13 | GPIO_PIN_11 | GPIO_PIN_12;
75+
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
76+
77+
/* Configure PC1, PC4 and PC5 */
78+
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
79+
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
80+
81+
/* Enable the Ethernet global Interrupt */
82+
HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0);
83+
HAL_NVIC_EnableIRQ(ETH_IRQn);
84+
85+
/* Enable ETHERNET clock */
86+
__HAL_RCC_ETH_CLK_ENABLE();
87+
}
88+
}
89+
90+
/**
91+
* Override HAL Eth DeInit function
92+
*/
93+
void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
94+
{
95+
if (heth->Instance == ETH) {
96+
/* Peripheral clock disable */
97+
__HAL_RCC_ETH_CLK_DISABLE();
98+
99+
/** ETH GPIO Configuration
100+
RMII_REF_CLK ----------------------> PA1
101+
RMII_MDIO -------------------------> PA2
102+
RMII_MDC --------------------------> PC1
103+
RMII_MII_CRS_DV -------------------> PA7
104+
RMII_MII_RXD0 ---------------------> PC4
105+
RMII_MII_RXD1 ---------------------> PC5
106+
RMII_MII_RXER ---------------------> PG2
107+
RMII_MII_TX_EN --------------------> PB11
108+
RMII_MII_TXD0 ---------------------> PB12
109+
RMII_MII_TXD1 ---------------------> PB13
110+
*/
111+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7);
112+
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13 | GPIO_PIN_11 | GPIO_PIN_12);
113+
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5);
114+
115+
/* Disable the Ethernet global Interrupt */
116+
NVIC_DisableIRQ(ETH_IRQn);
117+
}
118+
}
119+
120+
uint8_t mbed_otp_mac_address(char *mac)
121+
{
122+
C029_OTP_Header *pFound = NULL;
123+
C029_OTP_Header *pTemp = (C029_OTP_Header*)C029_OTP_START_ADDRESS;
124+
C029_OTP_Header temp;
125+
126+
if (_macRetrieved == 0) {
127+
while ((pTemp >= (C029_OTP_Header*)C029_OTP_START_ADDRESS) && (pTemp < (C029_OTP_Header*)C029_OTP_END_ADDRESS)){
128+
memcpy((void*)&temp, (void*)pTemp, sizeof(temp));
129+
if (temp.id == C029_MAC_ETHERNET_ID){
130+
pFound = pTemp;
131+
break;
132+
}
133+
pTemp = increment(pTemp);
134+
}
135+
if (pFound != NULL) {
136+
memcpy(_macAddr, pFound->data, 6);
137+
_macRetrieved = 1;
138+
}
139+
}
140+
memcpy(mac, _macAddr, 6);
141+
142+
return 1;
143+
}

0 commit comments

Comments
 (0)