Merge pull request #2107 from cesanta/standex

read MAC from flash
This commit is contained in:
Sergio R. Caprile 2023-03-07 15:59:14 -03:00 committed by GitHub
commit 3801e1eade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 2 deletions

View File

@ -173,3 +173,13 @@ static inline int uart_read_ready(UART0_Type *uart) {
static inline uint8_t uart_read_byte(UART0_Type *uart) { static inline uint8_t uart_read_byte(UART0_Type *uart) {
return (uint8_t) (uart->DR & 0xFF); 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 \
}

View File

@ -72,7 +72,7 @@ int main(void) {
struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr = struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr =
1}; // See driver_tm4c.h 1}; // See driver_tm4c.h
struct mg_tcpip_if mif = { struct mg_tcpip_if mif = {
.mac = {2, 0, 1, 2, 3, 5}, .mac = READ_PREFLASHED_MAC(),
.driver = &mg_tcpip_driver_tm4c, .driver = &mg_tcpip_driver_tm4c,
.driver_data = &driver_data, .driver_data = &driver_data,
}; };

View File

@ -173,3 +173,13 @@ static inline int uart_read_ready(UART0_Type *uart) {
static inline uint8_t uart_read_byte(UART0_Type *uart) { static inline uint8_t uart_read_byte(UART0_Type *uart) {
return (uint8_t) (uart->DR & 0xFF); 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 \
}

View File

@ -57,7 +57,7 @@ static void server(void *args) {
ethernet_init(); ethernet_init();
struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr = 1}; struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr = 1};
struct mg_tcpip_if mif = { struct mg_tcpip_if mif = {
.mac = {2, 0, 1, 2, 3, 5}, .mac = READ_PREFLASHED_MAC(),
.driver = &mg_tcpip_driver_tm4c, .driver = &mg_tcpip_driver_tm4c,
.driver_data = &driver_data, .driver_data = &driver_data,
}; };