From 3e419303a7f20c02b9d8de506dae70e33c0a1894 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Mon, 6 Mar 2023 17:32:43 -0300 Subject: [PATCH] read MAC from flash --- examples/ti/ek-tm4c1294xl-baremetal/hal.h | 10 ++++++++++ examples/ti/ek-tm4c1294xl-baremetal/main.c | 2 +- examples/ti/ek-tm4c1294xl-freertos/hal.h | 10 ++++++++++ examples/ti/ek-tm4c1294xl-freertos/main.c | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/examples/ti/ek-tm4c1294xl-baremetal/hal.h b/examples/ti/ek-tm4c1294xl-baremetal/hal.h index 30628a7c..457d2999 100644 --- a/examples/ti/ek-tm4c1294xl-baremetal/hal.h +++ b/examples/ti/ek-tm4c1294xl-baremetal/hal.h @@ -173,3 +173,13 @@ static inline int uart_read_ready(UART0_Type *uart) { static inline uint8_t uart_read_byte(UART0_Type *uart) { return (uint8_t) (uart->DR & 0xFF); } + +// Helper macro for reading pre-flashed MAC from user registers +#define READ_PREFLASHED_MAC() \ + { \ + (FLASH_CTRL->USERREG0 >> 0) & 0xFF, (FLASH_CTRL->USERREG0 >> 8) & 0xFF, \ + (FLASH_CTRL->USERREG0 >> 16) & 0xFF, \ + (FLASH_CTRL->USERREG1 >> 0) & 0xFF, \ + (FLASH_CTRL->USERREG1 >> 8) & 0xFF, \ + (FLASH_CTRL->USERREG1 >> 16) & 0xFF \ + } diff --git a/examples/ti/ek-tm4c1294xl-baremetal/main.c b/examples/ti/ek-tm4c1294xl-baremetal/main.c index 05dca4fe..f5221b8b 100644 --- a/examples/ti/ek-tm4c1294xl-baremetal/main.c +++ b/examples/ti/ek-tm4c1294xl-baremetal/main.c @@ -72,7 +72,7 @@ int main(void) { struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr = 1}; // See driver_tm4c.h struct mg_tcpip_if mif = { - .mac = {2, 0, 1, 2, 3, 5}, + .mac = READ_PREFLASHED_MAC(), .driver = &mg_tcpip_driver_tm4c, .driver_data = &driver_data, }; diff --git a/examples/ti/ek-tm4c1294xl-freertos/hal.h b/examples/ti/ek-tm4c1294xl-freertos/hal.h index 30628a7c..457d2999 100644 --- a/examples/ti/ek-tm4c1294xl-freertos/hal.h +++ b/examples/ti/ek-tm4c1294xl-freertos/hal.h @@ -173,3 +173,13 @@ static inline int uart_read_ready(UART0_Type *uart) { static inline uint8_t uart_read_byte(UART0_Type *uart) { return (uint8_t) (uart->DR & 0xFF); } + +// Helper macro for reading pre-flashed MAC from user registers +#define READ_PREFLASHED_MAC() \ + { \ + (FLASH_CTRL->USERREG0 >> 0) & 0xFF, (FLASH_CTRL->USERREG0 >> 8) & 0xFF, \ + (FLASH_CTRL->USERREG0 >> 16) & 0xFF, \ + (FLASH_CTRL->USERREG1 >> 0) & 0xFF, \ + (FLASH_CTRL->USERREG1 >> 8) & 0xFF, \ + (FLASH_CTRL->USERREG1 >> 16) & 0xFF \ + } diff --git a/examples/ti/ek-tm4c1294xl-freertos/main.c b/examples/ti/ek-tm4c1294xl-freertos/main.c index eb839431..74279af8 100644 --- a/examples/ti/ek-tm4c1294xl-freertos/main.c +++ b/examples/ti/ek-tm4c1294xl-freertos/main.c @@ -57,7 +57,7 @@ static void server(void *args) { ethernet_init(); struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr = 1}; struct mg_tcpip_if mif = { - .mac = {2, 0, 1, 2, 3, 5}, + .mac = READ_PREFLASHED_MAC(), .driver = &mg_tcpip_driver_tm4c, .driver_data = &driver_data, };