diff --git a/.gitignore b/.gitignore index 11ee114..71438dd 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,8 @@ ARM_Debug/ com.atollic* /ARM_Release/ +*.sav +*.save +*.bak +*.patch +*.works diff --git a/Inc/main.h b/Inc/main.h index 7d4006a..9caa5b4 100644 --- a/Inc/main.h +++ b/Inc/main.h @@ -54,7 +54,7 @@ /* Includes ------------------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include /* USER CODE END Includes */ /* Private define ------------------------------------------------------------*/ @@ -158,6 +158,8 @@ extern int reset_requested; extern char serial_number[25]; extern char serial_number_64[17]; +extern uint8_t mac_address[6]; + #define CxxErrorHandler() _Error_Handler(const_cast(__FILE__), __LINE__) diff --git a/Src/main.c b/Src/main.c index 83ba2ba..5c6cea6 100644 --- a/Src/main.c +++ b/Src/main.c @@ -147,6 +147,8 @@ int lost_power = 0; int reset_requested = 0; char serial_number[25]; char serial_number_64[17] = {0}; +// Make sure it is not overwritten during resets (bss3). +uint8_t mac_address[6] __attribute__((section(".bss3"))) = {0}; /* USER CODE END PV */ diff --git a/TNC/IOEventTask.cpp b/TNC/IOEventTask.cpp index df6ad6f..f01add8 100644 --- a/TNC/IOEventTask.cpp +++ b/TNC/IOEventTask.cpp @@ -359,6 +359,9 @@ void print_startup_banner() mobilinkd::tnc::kiss::FIRMWARE_VERSION); INFO("CPU core clock: %luHz", SystemCoreClock); INFO(" Serial number: %08lX %08lX %08lX", uid[0], uid[1], uid[2]); + INFO("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X", + mac_address[0], mac_address[1], mac_address[2], + mac_address[3], mac_address[4], mac_address[5]) uint8_t* version_ptr = (uint8_t*) 0x1FFF6FF2; diff --git a/TNC/KissHardware.cpp b/TNC/KissHardware.cpp index 6488762..119c8ad 100644 --- a/TNC/KissHardware.cpp +++ b/TNC/KissHardware.cpp @@ -485,10 +485,11 @@ void Hardware::handle_request(hdlc::IoFrame* frame) { reply16(hardware::GET_CAPABILITIES, hardware::CAP_EEPROM_SAVE|hardware::CAP_BATTERY_LEVEL| hardware::CAP_ADJUST_INPUT|hardware::CAP_DFU_FIRMWARE); - reply16(hardware::GET_MIN_INPUT_GAIN, 0); - reply16(hardware::GET_MAX_INPUT_GAIN, 4); - reply8(hardware::GET_MIN_INPUT_TWIST, -3); - reply8(hardware::GET_MAX_INPUT_TWIST, 9); + reply16(hardware::GET_MIN_INPUT_GAIN, 0); // Constants for this FW + reply16(hardware::GET_MAX_INPUT_GAIN, 4); // Constants for this FW + reply8(hardware::GET_MIN_INPUT_TWIST, -3); // Constants for this FW + reply8(hardware::GET_MAX_INPUT_TWIST, 9); // Constants for this FW + reply(hardware::GET_MAC_ADDRESS, mac_address, sizeof(mac_address)); reply(hardware::GET_DATETIME, get_rtc_datetime(), 7); break; diff --git a/TNC/bm78.cpp b/TNC/bm78.cpp index addc5af..856ed9e 100644 --- a/TNC/bm78.cpp +++ b/TNC/bm78.cpp @@ -76,6 +76,32 @@ void enter_program_mode() } } +bool read_mac_address() +{ + // Read (cmd = 0x29) the first 6 bytes at address 0. + uint8_t cmd[] = { 0x01, 0x29, 0xfc, 0x03, 0x00, 0x00, 0x06 }; + constexpr const uint16_t BLOCK_SIZE = 6; + if (HAL_UART_Transmit(&huart3, cmd, sizeof(cmd), 100) != HAL_OK) + { + ERROR("read_mac_address transmit failed"); + return false; + } + + uint8_t buffer[BLOCK_SIZE + 10]; + if (HAL_UART_Receive(&huart3, buffer, sizeof(buffer), 1000) != HAL_OK) + { + ERROR("read_mac_address receive failed"); + return false; + } + + for (size_t i = 0; i != BLOCK_SIZE; ++i) + { + mac_address[5 - i] = buffer[i + 10]; // Reverse the bytes + } + + return true; +} + /** * Exit BM78 EEPROM programming mode and return to pass-through mode. * @@ -502,6 +528,7 @@ int bm78_initialize() enter_program_mode(); if (!write_eeprom()) result = 1; else if (!write_serial()) result = 2; + else if (!read_mac_address()) result = 3; exit_program_mode(); #if 1