stm32/mphalport: Add mp_hal_get_mac() helper function.

This commit is contained in:
Damien George 2019-02-22 21:53:41 +11:00
parent 75a35448e1
commit cc63e19332
2 changed files with 20 additions and 0 deletions

View File

@ -162,3 +162,14 @@ void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed) {
uint32_t pin = pin_obj->pin;
gpio->OSPEEDR = (gpio->OSPEEDR & ~(3 << (2 * pin))) | (speed << (2 * pin));
}
MP_WEAK void mp_hal_get_mac(int idx, uint8_t buf[6]) {
// Generate a random locally administered MAC address (LAA)
uint8_t *id = (uint8_t *)MP_HAL_UNIQUE_ID_ADDRESS;
buf[0] = 0x02; // LAA range
buf[1] = (id[11] << 4) | (id[10] & 0xf);
buf[2] = (id[9] << 4) | (id[8] & 0xf);
buf[3] = (id[7] << 4) | (id[6] & 0xf);
buf[4] = id[2];
buf[5] = (id[0] << 2) | idx;
}

View File

@ -79,3 +79,12 @@ void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint32_t alt);
bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint8_t fn, uint8_t unit);
void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed);
enum {
MP_HAL_MAC_WLAN0 = 0,
MP_HAL_MAC_WLAN1,
MP_HAL_MAC_BDADDR,
MP_HAL_MAC_ETH0,
};
void mp_hal_get_mac(int idx, uint8_t buf[6]);