mimxrt/mphalport: Fix strict aliasing error with unique id.
This commit is contained in:
parent
6bda80d811
commit
2f4aca0381
@ -140,8 +140,8 @@ uint64_t mp_hal_time_ns(void) {
|
||||
// MAC address
|
||||
|
||||
void mp_hal_get_unique_id(uint8_t id[]) {
|
||||
*(uint32_t *)&id[0] = OCOTP->CFG0;
|
||||
*(uint32_t *)&id[4] = OCOTP->CFG1;
|
||||
*(uint32_t *)id = OCOTP->CFG0;
|
||||
*(uint32_t *)(id + 4) = OCOTP->CFG1;
|
||||
}
|
||||
|
||||
// Generate a random locally administered MAC address (LAA)
|
||||
@ -150,12 +150,12 @@ void mp_hal_generate_laa_mac(int idx, uint8_t buf[6]) {
|
||||
unsigned char id[8];
|
||||
mp_hal_get_unique_id(id);
|
||||
|
||||
uint32_t pt1 = *(uint32_t *)&id[0];
|
||||
uint32_t pt2 = *(uint32_t *)&id[4];
|
||||
uint32_t *pt1 = (uint32_t *)id;
|
||||
uint32_t *pt2 = (uint32_t *)(id + 4);
|
||||
|
||||
buf[0] = 0x02; // Locally Administered MAC
|
||||
*(uint32_t *)&buf[1] = pt1 ^ (pt1 >> 8);
|
||||
*(uint16_t *)&buf[4] = (uint16_t)(pt2 ^ pt2 >> 16);
|
||||
*(uint32_t *)&buf[1] = *pt1 ^ (*pt1 >> 8);
|
||||
*(uint16_t *)&buf[4] = (uint16_t)(*pt2 ^ *pt2 >> 16);
|
||||
buf[5] ^= (uint8_t)idx;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user