From 5bdb6f22e9eedff0e8da121faf763e40827eb50a Mon Sep 17 00:00:00 2001 From: david_s5 Date: Thu, 6 Mar 2014 06:49:48 -1000 Subject: [PATCH 1/2] USE_ONLY_PANIC is defualt in release build --- SPARK_Firmware_Driver/inc/config.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SPARK_Firmware_Driver/inc/config.h b/SPARK_Firmware_Driver/inc/config.h index 429051b..cfb91d8 100644 --- a/SPARK_Firmware_Driver/inc/config.h +++ b/SPARK_Firmware_Driver/inc/config.h @@ -13,8 +13,14 @@ #define RELEASE_BUILD #undef DEBUG_BUILD #endif -//#define USE_ONLY_PANIC // Define to remove all Logging and only have Panic + +#if defined(DEBUG_BUILD) +#define DBGMCU_SETTINGS (DBGMCU_CR_DBG_SLEEP|DBGMCU_CR_DBG_STOP|DBGMCU_CR_DBG_STANDBY|DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP) +#else +#define USE_ONLY_PANIC // Define to remove all Logging and only have Panic +#define DBGMCU_SETTINGS (DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP) +#endif // define to include __FILE__ information within the debug output #define INCLUDE_FILE_INFO_IN_DEBUG #define MAX_DEBUG_MESSAGE_LENGTH 120 From 1a222a686f53090535cb61246c45801be805c154 Mon Sep 17 00:00:00 2001 From: david_s5 Date: Thu, 6 Mar 2014 06:50:38 -1000 Subject: [PATCH 2/2] Better IWD handeling --- CC3000_Host_Driver/evnt_handler.c | 1 + SPARK_Firmware_Driver/inc/hw_config.h | 19 +++++++++++++++++++ SPARK_Firmware_Driver/inc/panic_codes.h | 5 +++-- SPARK_Firmware_Driver/src/hw_config.c | 20 ++++++++++---------- SPARK_Firmware_Driver/src/panic.c | 16 +++++++++++++--- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/CC3000_Host_Driver/evnt_handler.c b/CC3000_Host_Driver/evnt_handler.c index dead6bc..aac4645 100644 --- a/CC3000_Host_Driver/evnt_handler.c +++ b/CC3000_Host_Driver/evnt_handler.c @@ -237,6 +237,7 @@ hci_event_handler(void *pRetParams, unsigned char *from, long *fromlen) { if (tSLInformation.usEventOrDataReceived == 0) { + KICK_WDT(); volatile system_tick_t now = GetSystem1MsTick(); volatile long elapsed = now - start; if (elapsed < 0) { // Did we wrap diff --git a/SPARK_Firmware_Driver/inc/hw_config.h b/SPARK_Firmware_Driver/inc/hw_config.h index b12539a..b87ac17 100644 --- a/SPARK_Firmware_Driver/inc/hw_config.h +++ b/SPARK_Firmware_Driver/inc/hw_config.h @@ -29,6 +29,7 @@ /* Includes ------------------------------------------------------------------*/ #include "platform_config.h" +#include "config.h" #include "sst25vf_spi.h" #include "cc3000_common.h" #include "usb_type.h" @@ -273,4 +274,22 @@ extern uint16_t FLASH_OTA_Update_SysFlag; extern unsigned char wlan_rx_buffer[]; extern unsigned char wlan_tx_buffer[]; +enum eSystemHealth { + FIRST_RETRY = 1, + SECOND_RETRY = 2, + THIRD_RETRY = 3, + ENTERED_SparkCoreConfig, + ENTERED_Main, + ENTERED_WLAN_Loop, + ENTERED_Setup, + ENTERED_Loop, + RAN_Loop, + PRESERVE_APP, +}; + +#define SET_SYS_HEALTH(health) BKP_WriteBackupRegister(BKP_DR1, (health)) +#define GET_SYS_HEALTH() BKP_ReadBackupRegister(BKP_DR1) +extern uint16_t sys_health_cache; +#define DECLARE_SYS_HEALTH(health) do { if ((health) > sys_health_cache) {SET_SYS_HEALTH(sys_health_cache=(health));}} while(0) +#define KICK_WDT() IWDG_ReloadCounter() #endif /*__HW_CONFIG_H*/ diff --git a/SPARK_Firmware_Driver/inc/panic_codes.h b/SPARK_Firmware_Driver/inc/panic_codes.h index 4a1a9ad..f2715fb 100644 --- a/SPARK_Firmware_Driver/inc/panic_codes.h +++ b/SPARK_Firmware_Driver/inc/panic_codes.h @@ -22,6 +22,7 @@ def_panic_codes(System,RGB_COLOR_RED,OutOfHeap) def_panic_codes(System,RGB_COLOR_RED,SPIOverRun) -def_panic_codes(Softare,RGB_COLOR_RED,AssertionFailure) -def_panic_codes(Softare,RGB_COLOR_RED,InvalidCase) +def_panic_codes(Sofwtare,RGB_COLOR_RED,AssertionFailure) +def_panic_codes(Sofwtare,RGB_COLOR_RED,InvalidCase) +def_panic_codes(Sofwtare,RGB_COLOR_RED,PureVirtualCall) diff --git a/SPARK_Firmware_Driver/src/hw_config.c b/SPARK_Firmware_Driver/src/hw_config.c index 0efcd20..38a8e01 100644 --- a/SPARK_Firmware_Driver/src/hw_config.c +++ b/SPARK_Firmware_Driver/src/hw_config.c @@ -37,6 +37,7 @@ /* Private variables ---------------------------------------------------------*/ uint8_t USE_SYSTEM_FLAGS = 0; //0, 1 +uint16_t sys_health_cache = 0; // Used by the SYS_HEALTH macros store new heath if higher volatile uint32_t TimingDelay; volatile uint32_t TimingLED; @@ -107,9 +108,13 @@ __IO uint16_t sFLASH_SPI_CR; * @brief Initialise Data Watchpoint and Trace Register (DWT). * @param None * @retval None + * + * */ + static void DWT_Init(void) { + DBGMCU->CR |= DBGMCU_SETTINGS; CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; @@ -231,6 +236,7 @@ void Delay_Microsecond(uint32_t uSec) while (1) { + KICK_WDT(); volatile uint32_t current_DWT_CYCCNT = DWT->CYCCNT; volatile long elapsed_DWT_CYCCNT = current_DWT_CYCCNT - last_DWT_CYCCNT; @@ -239,7 +245,6 @@ void Delay_Microsecond(uint32_t uSec) { elapsed_DWT_CYCCNT = last_DWT_CYCCNT + current_DWT_CYCCNT; } - if((elapsed_DWT_CYCCNT / SYSTEM_US_TICKS) >= uSec) { break; @@ -344,21 +349,17 @@ void Enter_STANDBY_Mode(void) void IWDG_Reset_Enable(uint32_t msTimeout) { - uint16_t Reload_Value; - - if(msTimeout > 10000) - msTimeout = 10000; //Max IWDG timeout that can be set is 10 sec - /* Enable write access to IWDG_PR and IWDG_RLR registers */ IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); /* IWDG counter clock: LSI/256 */ IWDG_SetPrescaler(IWDG_Prescaler_256); - /* IWDG timeout may vary due to LSI frequency dispersion */ - Reload_Value = (uint16_t)((msTimeout * 40) / 256); //Assuming LSI Frequency = 40000 + /* IWDG timeout may vary due to LSI frequency dispersion */ + msTimeout = ((msTimeout * 40) / 256); //Assuming LSI Frequency = 40000 + if (msTimeout > 0xfff) msTimeout = 0xfff; // 26214.4 - IWDG_SetReload(Reload_Value); + IWDG_SetReload((uint16_t)msTimeout); /* Reload IWDG counter */ IWDG_ReloadCounter(); @@ -1761,4 +1762,3 @@ system_tick_t GetSystem1MsTick() { return system_1ms_tick; } - diff --git a/SPARK_Firmware_Driver/src/panic.c b/SPARK_Firmware_Driver/src/panic.c index cd2b210..84cacce 100644 --- a/SPARK_Firmware_Driver/src/panic.c +++ b/SPARK_Firmware_Driver/src/panic.c @@ -9,6 +9,7 @@ #include "hw_config.h" #include "spark_macros.h" #include "panic.h" +#include "debug.h" #define LOOPSPERMSEC 5483 @@ -33,12 +34,17 @@ static const flash_codes_t flash_codes[] = { void panic_(ePanicCode code) { __disable_irq(); + // Flush any serial message to help the poor bugger debug this; flash_codes_t pcd = flash_codes[code]; - LED_SetRGBColor(RGB_COLOR_WHITE); - LED_Off(LED_RGB); + LED_SetRGBColor(RGB_COLOR_RED); + LED_On(LED_RGB); uint16_t c; - while(1) { + int loops = 2; + if (debug_output_)(debug_output_("!")); + LED_Off(LED_RGB); + while(loops) { // preamble + KICK_WDT(); for (c = 3; c; c--) { LED_SetRGBColor(pcd.led); LED_On(LED_RGB); @@ -77,5 +83,9 @@ void panic_(ePanicCode code) } // pause Delay_Microsecond(MS2u(800)); +#ifdef RELEASE_BUILD + if (--loops == 0) NVIC_SystemReset(); +#endif } + }