Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others

Revision:
3:99cb87ee1792
Parent:
2:cd263c5e86f2
Child:
5:e1297df8ee0d
--- a/nz32s.cpp	Sat Aug 29 13:54:00 2015 +1000
+++ b/nz32s.cpp	Sun Aug 30 09:23:05 2015 +1000
@@ -19,10 +19,15 @@
  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  */
 #include "mbed.h"
-#include "nz32s.h"
 #include <stdarg.h>
 #include <stdio.h>
 
+#define DEBUG_ENABLE            1
+#include "mx_default_debug.h"
+
+//Includes that use debugging - Include AFTER debug defines/includes above! It uses them for debugging!
+#include "nz32s.h"
+
 
 // DEFINES ////////////////////////////////////////////////////////////////////
 
@@ -33,34 +38,12 @@
 // Function Prototypes ////////////////////////////////////////////////////////
 
 
-// DEBUG ////////////////////////////////////////////////////////////////////
-//IMPORTANT, when enabling debugging, it is very important to note the following:
-//- If (MX_DEBUG_IS_POINTER==1), ensure there is global Stream pointer defined somewhere in code to override "pMxDebug = NULL" below!
-//- If (MX_DEBUG_IS_POINTER==0), define a mxDebug() function somewhere in code to handel debug output
-#define DEBUG_ENABLE            1
-#if (DEBUG_ENABLE==1) && !defined(NDEBUG)
-//Alternative method in stead of using NULL below. This requires to create derived Stream class in each file we want to use debugging
-//    class modtronixDebugStream : public Stream {int _putc(int value) {return 0;}int _getc() {return 0;}};
-//    static modtronixDebugStream modtronixDebug;
-//    WEAK Stream* pMxDebug = &modtronixDebug;
-#if (MX_DEBUG_IS_POINTER==1)        //More efficient, but only works if pMxDebug is defined in code. Disabled by default!
-        WEAK Stream* pMxDebug = NULL;
-        #define MX_DEBUG  pMxDebug->printf
-    #else
-        WEAK void mxDebug(const char *format, ...) {}
-        #define MX_DEBUG mxDebug
-    #endif
-#else
-    //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
-    #define MX_DEBUG(format, args...) ((void)0)
-#endif
-
-
+IWDG_HandleTypeDef NZ32S::hiwdg;    //Watchdog Timer
 
 /**
  * Reset I2C bus
  */
-void nz32s_resetI2C(uint8_t busNumber, PinName sda, PinName scl) {
+void NZ32S::i2c_reset(uint8_t busNumber, PinName sda, PinName scl) {
 #if defined(STM32) || defined(STM32L1)
     i2c_t objI2C;
 
@@ -78,5 +61,38 @@
 
     MX_DEBUG("\r\nI2C1 Reset");
 
-#endif
+#endif  //#if defined(STM32) || defined(STM32L1)
 }
+
+void NZ32S::print_reset_cause(bool clearFlags) {
+#if defined(STM32) || defined(STM32L1)
+    if ( __HAL_RCC_GET_FLAG(PWR_FLAG_SB))
+        MX_DEBUG("\r\nSystem resumed from STANDBY mode");
+
+    if ( __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST))
+        MX_DEBUG("\r\nSoftware Reset");
+
+    if ( __HAL_RCC_GET_FLAG(RCC_FLAG_PORRST))
+        MX_DEBUG("\r\nPower-On-Reset");
+
+    if ( __HAL_RCC_GET_FLAG(RCC_FLAG_PINRST)) // Always set, test other cases first
+        MX_DEBUG("\r\nExternal Pin Reset");
+
+    if ( __HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
+        MX_DEBUG("\r\nWatchdog Reset");
+
+    if ( __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) != RESET)
+        MX_DEBUG("\r\nWindow Watchdog Reset");
+
+    if ( __HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST) != RESET)
+        MX_DEBUG("\r\nLow Power Reset");
+
+//    if ( __HAL_RCC_GET_FLAG(RCC_FLAG_BORRST) != RESET) // F4 Usually set with POR
+//        MX_DEBUG("\r\nBrown-Out Reset");
+
+    if (clearFlags) {
+        __HAL_RCC_CLEAR_RESET_FLAGS(); // The flags cleared after use
+    }
+#endif  //#if defined(STM32) || defined(STM32L1)
+}
+