Skip to content

Commit eacccdd

Browse files
author
andreas.larsson
committed
Added mbed_mac_address
1 parent 0e5a0d6 commit eacccdd

File tree

1 file changed

+56
-0
lines changed
  • features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_C029

1 file changed

+56
-0
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_C029/stm32f4_eth_init.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1+
#include <string.h>
12
#include "stm32f4xx_hal.h"
23

4+
#define C029_OTP_START_ADDRESS (0x1FFF7800U)
5+
#define C029_OTP_END_ADDRESS (C029_OTP_START_ADDRESS + (16*32))
6+
#define C029_MAC_ETHERNET_ID (3)
7+
8+
typedef struct C029_OTP_Header {
9+
uint8_t id;
10+
uint8_t len;
11+
uint8_t data[];
12+
} __attribute__((__packed__)) C029_OTP_Header;
13+
14+
static int _macRetrieved = 0;
15+
static char _macAddr[6] = { 0x02, 0x02, 0xF7, 0xF0, 0x00, 0x00 };
16+
17+
static C029_OTP_Header *increment(C029_OTP_Header *pTemp)
18+
{
19+
uint8_t len = 0;
20+
uint8_t id = 0;
21+
uint8_t *p = (uint8_t*)pTemp;
22+
23+
memcpy((void*)&id, (void*)pTemp, 1);
24+
25+
if (id == 0xFF){
26+
p++;
27+
}
28+
else {
29+
p++;
30+
memcpy((void*)&len, (void*)p++, 1);
31+
p += len;
32+
}
33+
return (C029_OTP_Header*)p;
34+
}
35+
336
/**
437
* Override HAL Eth Init function
538
*/
@@ -83,4 +116,27 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
83116
/* Disable the Ethernet global Interrupt */
84117
NVIC_DisableIRQ(ETH_IRQn);
85118
}
119+
}
120+
121+
void mbed_mac_address(char *mac)
122+
{
123+
C029_OTP_Header *pFound = NULL;
124+
C029_OTP_Header *pTemp = (C029_OTP_Header*)C029_OTP_START_ADDRESS;
125+
C029_OTP_Header temp;
126+
127+
if (_macRetrieved == 0) {
128+
while ((pTemp >= (C029_OTP_Header*)C029_OTP_START_ADDRESS) && (pTemp < (C029_OTP_Header*)C029_OTP_END_ADDRESS)){
129+
memcpy((void*)&temp, (void*)pTemp, sizeof(temp));
130+
if (temp.id == C029_MAC_ETHERNET_ID){
131+
pFound = pTemp;
132+
break;
133+
}
134+
pTemp = increment(pTemp);
135+
}
136+
if (pFound != NULL) {
137+
memcpy(_macAddr, pFound->data, 6);
138+
_macRetrieved = 1;
139+
}
140+
}
141+
memcpy(mac, _macAddr, 6);
86142
}

0 commit comments

Comments
 (0)