From 533b5d0ce03304d7d66a7ba70f26a24e430bfbe3 Mon Sep 17 00:00:00 2001 From: Rob Riggs Date: Sun, 6 Jan 2019 16:39:34 -0600 Subject: [PATCH] Fix #3. Store error message in SRAM and reset. Return error message in GET_ALL_VALUES. --- Inc/main.h | 2 +- Src/main.c | 11 ++++++++--- TNC/KissHardware.cpp | 3 +++ TNC/KissHardware.hpp | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Inc/main.h b/Inc/main.h index 9caa5b4..176ff96 100644 --- a/Inc/main.h +++ b/Inc/main.h @@ -159,7 +159,7 @@ extern int reset_requested; extern char serial_number[25]; extern char serial_number_64[17]; extern uint8_t mac_address[6]; - +extern char error_message[80]; #define CxxErrorHandler() _Error_Handler(const_cast(__FILE__), __LINE__) diff --git a/Src/main.c b/Src/main.c index 1f1610f..90a2b77 100644 --- a/Src/main.c +++ b/Src/main.c @@ -149,6 +149,7 @@ 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}; +char error_message[80] __attribute__((section(".bss3"))) = {0}; /* USER CODE END PV */ @@ -346,7 +347,9 @@ int main(void) SystemClock_Config(); /* USER CODE BEGIN SysInit */ +#ifdef KISS_LOGGING printf("start\r\n"); +#endif // Note that it is important that all GPIO interrupts are disabled until // the FreeRTOS kernel has started. All GPIO interrupts send messages @@ -525,6 +528,7 @@ int main(void) // Initialize the BM78 Bluetooth module and the RTC date/time the first time we boot. if (!bm78_initialized()) { bm78_initialize(); + memset(error_message, 0, sizeof(error_message)); // init_rtc_date_time(); } else bm78_wait_until_ready(); @@ -567,6 +571,7 @@ int main(void) HAL_FLASH_OB_Launch(); } #endif + /* USER CODE END RTOS_QUEUES */ @@ -1395,9 +1400,9 @@ void _Error_Handler(char *file, int line) #ifdef KISS_LOGGING printf("Error handler called from file %s on line %d\r\n", file, line); #endif - while(1) - { - } + snprintf(error_message, sizeof(error_message), "Error: %s:%d", file, line); + + NVIC_SystemReset(); /* USER CODE END Error_Handler_Debug */ } diff --git a/TNC/KissHardware.cpp b/TNC/KissHardware.cpp index 119c8ad..53d2df6 100644 --- a/TNC/KissHardware.cpp +++ b/TNC/KissHardware.cpp @@ -491,6 +491,9 @@ void Hardware::handle_request(hdlc::IoFrame* frame) { 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); + if (*error_message) { + reply(hardware::GET_ERROR_MSG, (uint8_t*) error_message, sizeof(error_message)); + } break; case hardware::EXTENDED_CMD: diff --git a/TNC/KissHardware.hpp b/TNC/KissHardware.hpp index 82e1aef..2db81ae 100644 --- a/TNC/KissHardware.hpp +++ b/TNC/KissHardware.hpp @@ -105,6 +105,7 @@ constexpr const uint8_t GET_SERIAL_NUMBER = 47; constexpr const uint8_t GET_MAC_ADDRESS = 48; constexpr const uint8_t GET_DATETIME = 49; constexpr const uint8_t SET_DATETIME = 50; +constexpr const uint8_t GET_ERROR_MSG = 51; constexpr const uint8_t SET_BLUETOOTH_NAME = 65; constexpr const uint8_t GET_BLUETOOTH_NAME = 66;