Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others
nz32s.cpp@3:99cb87ee1792, 2015-08-30 (annotated)
- Committer:
- modtronix
- Date:
- Sun Aug 30 09:23:05 2015 +1000
- Revision:
- 3:99cb87ee1792
- Parent:
- 2:cd263c5e86f2
- Child:
- 5:e1297df8ee0d
Updated, added new files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
modtronix | 2:cd263c5e86f2 | 1 | /** |
modtronix | 2:cd263c5e86f2 | 2 | * File: modtronix_nz32s.cpp |
modtronix | 2:cd263c5e86f2 | 3 | * |
modtronix | 2:cd263c5e86f2 | 4 | * Author: Modtronix Engineering - www.modtronix.com |
modtronix | 2:cd263c5e86f2 | 5 | * |
modtronix | 2:cd263c5e86f2 | 6 | * Description: |
modtronix | 2:cd263c5e86f2 | 7 | * |
modtronix | 2:cd263c5e86f2 | 8 | * Software License Agreement: |
modtronix | 2:cd263c5e86f2 | 9 | * This software has been written or modified by Modtronix Engineering. The code |
modtronix | 2:cd263c5e86f2 | 10 | * may be modified and can be used free of charge for commercial and non commercial |
modtronix | 2:cd263c5e86f2 | 11 | * applications. If this is modified software, any license conditions from original |
modtronix | 2:cd263c5e86f2 | 12 | * software also apply. Any redistribution must include reference to 'Modtronix |
modtronix | 2:cd263c5e86f2 | 13 | * Engineering' and web link(www.modtronix.com) in the file header. |
modtronix | 2:cd263c5e86f2 | 14 | * |
modtronix | 2:cd263c5e86f2 | 15 | * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, |
modtronix | 2:cd263c5e86f2 | 16 | * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
modtronix | 2:cd263c5e86f2 | 17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE |
modtronix | 2:cd263c5e86f2 | 18 | * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
modtronix | 2:cd263c5e86f2 | 19 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
modtronix | 2:cd263c5e86f2 | 20 | */ |
modtronix | 2:cd263c5e86f2 | 21 | #include "mbed.h" |
modtronix | 2:cd263c5e86f2 | 22 | #include <stdarg.h> |
modtronix | 2:cd263c5e86f2 | 23 | #include <stdio.h> |
modtronix | 2:cd263c5e86f2 | 24 | |
modtronix | 3:99cb87ee1792 | 25 | #define DEBUG_ENABLE 1 |
modtronix | 3:99cb87ee1792 | 26 | #include "mx_default_debug.h" |
modtronix | 3:99cb87ee1792 | 27 | |
modtronix | 3:99cb87ee1792 | 28 | //Includes that use debugging - Include AFTER debug defines/includes above! It uses them for debugging! |
modtronix | 3:99cb87ee1792 | 29 | #include "nz32s.h" |
modtronix | 3:99cb87ee1792 | 30 | |
modtronix | 2:cd263c5e86f2 | 31 | |
modtronix | 2:cd263c5e86f2 | 32 | // DEFINES //////////////////////////////////////////////////////////////////// |
modtronix | 2:cd263c5e86f2 | 33 | |
modtronix | 2:cd263c5e86f2 | 34 | |
modtronix | 2:cd263c5e86f2 | 35 | // GLOBAL VARIABLES /////////////////////////////////////////////////////////// |
modtronix | 2:cd263c5e86f2 | 36 | |
modtronix | 2:cd263c5e86f2 | 37 | |
modtronix | 2:cd263c5e86f2 | 38 | // Function Prototypes //////////////////////////////////////////////////////// |
modtronix | 2:cd263c5e86f2 | 39 | |
modtronix | 2:cd263c5e86f2 | 40 | |
modtronix | 3:99cb87ee1792 | 41 | IWDG_HandleTypeDef NZ32S::hiwdg; //Watchdog Timer |
modtronix | 2:cd263c5e86f2 | 42 | |
modtronix | 2:cd263c5e86f2 | 43 | /** |
modtronix | 2:cd263c5e86f2 | 44 | * Reset I2C bus |
modtronix | 2:cd263c5e86f2 | 45 | */ |
modtronix | 3:99cb87ee1792 | 46 | void NZ32S::i2c_reset(uint8_t busNumber, PinName sda, PinName scl) { |
modtronix | 2:cd263c5e86f2 | 47 | #if defined(STM32) || defined(STM32L1) |
modtronix | 2:cd263c5e86f2 | 48 | i2c_t objI2C; |
modtronix | 2:cd263c5e86f2 | 49 | |
modtronix | 2:cd263c5e86f2 | 50 | if (busNumber == 1) { |
modtronix | 2:cd263c5e86f2 | 51 | objI2C.i2c = I2C_1; |
modtronix | 2:cd263c5e86f2 | 52 | } |
modtronix | 2:cd263c5e86f2 | 53 | else if (busNumber == 2) { |
modtronix | 2:cd263c5e86f2 | 54 | objI2C.i2c = I2C_2; |
modtronix | 2:cd263c5e86f2 | 55 | } |
modtronix | 2:cd263c5e86f2 | 56 | |
modtronix | 2:cd263c5e86f2 | 57 | objI2C.slave = 0; |
modtronix | 2:cd263c5e86f2 | 58 | i2c_init(&objI2C, sda, scl); |
modtronix | 2:cd263c5e86f2 | 59 | //i2c_reset(&objI2C); //i2c_init() above calls i2c_reset() |
modtronix | 2:cd263c5e86f2 | 60 | //pc.printf("\r\nI2C1 Reset"); |
modtronix | 2:cd263c5e86f2 | 61 | |
modtronix | 2:cd263c5e86f2 | 62 | MX_DEBUG("\r\nI2C1 Reset"); |
modtronix | 2:cd263c5e86f2 | 63 | |
modtronix | 3:99cb87ee1792 | 64 | #endif //#if defined(STM32) || defined(STM32L1) |
modtronix | 2:cd263c5e86f2 | 65 | } |
modtronix | 3:99cb87ee1792 | 66 | |
modtronix | 3:99cb87ee1792 | 67 | void NZ32S::print_reset_cause(bool clearFlags) { |
modtronix | 3:99cb87ee1792 | 68 | #if defined(STM32) || defined(STM32L1) |
modtronix | 3:99cb87ee1792 | 69 | if ( __HAL_RCC_GET_FLAG(PWR_FLAG_SB)) |
modtronix | 3:99cb87ee1792 | 70 | MX_DEBUG("\r\nSystem resumed from STANDBY mode"); |
modtronix | 3:99cb87ee1792 | 71 | |
modtronix | 3:99cb87ee1792 | 72 | if ( __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST)) |
modtronix | 3:99cb87ee1792 | 73 | MX_DEBUG("\r\nSoftware Reset"); |
modtronix | 3:99cb87ee1792 | 74 | |
modtronix | 3:99cb87ee1792 | 75 | if ( __HAL_RCC_GET_FLAG(RCC_FLAG_PORRST)) |
modtronix | 3:99cb87ee1792 | 76 | MX_DEBUG("\r\nPower-On-Reset"); |
modtronix | 3:99cb87ee1792 | 77 | |
modtronix | 3:99cb87ee1792 | 78 | if ( __HAL_RCC_GET_FLAG(RCC_FLAG_PINRST)) // Always set, test other cases first |
modtronix | 3:99cb87ee1792 | 79 | MX_DEBUG("\r\nExternal Pin Reset"); |
modtronix | 3:99cb87ee1792 | 80 | |
modtronix | 3:99cb87ee1792 | 81 | if ( __HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) |
modtronix | 3:99cb87ee1792 | 82 | MX_DEBUG("\r\nWatchdog Reset"); |
modtronix | 3:99cb87ee1792 | 83 | |
modtronix | 3:99cb87ee1792 | 84 | if ( __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) != RESET) |
modtronix | 3:99cb87ee1792 | 85 | MX_DEBUG("\r\nWindow Watchdog Reset"); |
modtronix | 3:99cb87ee1792 | 86 | |
modtronix | 3:99cb87ee1792 | 87 | if ( __HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST) != RESET) |
modtronix | 3:99cb87ee1792 | 88 | MX_DEBUG("\r\nLow Power Reset"); |
modtronix | 3:99cb87ee1792 | 89 | |
modtronix | 3:99cb87ee1792 | 90 | // if ( __HAL_RCC_GET_FLAG(RCC_FLAG_BORRST) != RESET) // F4 Usually set with POR |
modtronix | 3:99cb87ee1792 | 91 | // MX_DEBUG("\r\nBrown-Out Reset"); |
modtronix | 3:99cb87ee1792 | 92 | |
modtronix | 3:99cb87ee1792 | 93 | if (clearFlags) { |
modtronix | 3:99cb87ee1792 | 94 | __HAL_RCC_CLEAR_RESET_FLAGS(); // The flags cleared after use |
modtronix | 3:99cb87ee1792 | 95 | } |
modtronix | 3:99cb87ee1792 | 96 | #endif //#if defined(STM32) || defined(STM32L1) |
modtronix | 3:99cb87ee1792 | 97 | } |
modtronix | 3:99cb87ee1792 | 98 |