Browse Source

- 와치독 기능 구현
- Uart Data 받을 때 마다 와치독 Refresh 하도록 수정
- Bluecell protocol / MBIC protocol 두개의 통신 할 때 와치독 Init 하도록 수정
- 와치독 드라이버 추가
- 기능 13초에서 ~15초 사이에 리셋 한다.
- 하드웨어 와치독 IC 추가 취소로 인해 할당 된 핀제거

PYJ 5 years ago
parent
commit
45042aca76

File diff suppressed because it is too large
+ 2 - 2
.mxproject


+ 1 - 0
Bluecell_Inc/Bluecell_operate.h

@@ -1595,6 +1595,7 @@ extern BLUESTATUS_st bluecell_Currdatastatus;
1595 1595
 extern volatile uint32_t ALCTimerCnt;
1596 1596
 extern volatile uint32_t AGCTimerCnt;
1597 1597
 
1598
+extern IWDG_HandleTypeDef hiwdg;
1598 1599
 
1599 1600
 
1600 1601
 extern void Bluecell_DataInit();

+ 1 - 1
Bluecell_Inc/uart.h

@@ -29,7 +29,7 @@ typedef struct  {
29 29
 
30 30
 extern UART_HandleTypeDef huart1;
31 31
 extern UART_HandleTypeDef huart2;
32
-
32
+extern IWDG_HandleTypeDef hiwdg;
33 33
 
34 34
 extern UARTQUEUE TerminalQueue;
35 35
 void PutDataToUartQueue(UART_HandleTypeDef *huart, uint8_t data);

+ 9 - 0
Bluecell_Src/Bluecell_operate.c

@@ -2398,9 +2398,14 @@ bool Bluecell_Operate(uint8_t* data){
2398 2398
     case Bluecell_StatusReq:
2399 2399
         if(Initialize == false){
2400 2400
 //            printf("Atten Init \r\n");
2401
+
2401 2402
             Bluecell_DataInit();
2402 2403
             HAL_Delay(10);
2403 2404
             Bluecell_AttenInitialize();
2405
+              if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
2406
+              {
2407
+                Error_Handler();
2408
+              }            
2404 2409
             Initialize = true;
2405 2410
         }
2406 2411
         DataStatusSet();
@@ -4570,6 +4575,10 @@ bool MBIC_Operate(uint8_t* data){
4570 4575
             Bluecell_DataInit();
4571 4576
             Bluecell_AttenInitialize();
4572 4577
             Initialize = true;
4578
+          if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
4579
+          {
4580
+            Error_Handler();
4581
+          }
4573 4582
         }
4574 4583
         HFR_TypeInit();        
4575 4584
         data[MBIC_CMD_0] = 0x80;//MBIC_ERRRESPONSE;

+ 2 - 0
Bluecell_Src/uart.c

@@ -18,6 +18,7 @@ UARTQUEUE TerminalQueue;
18 18
 UARTQUEUE WifiQueue;
19 19
 uart_hal_tx_type uart_hal_tx;
20 20
 extern volatile uint32_t UartRxTimerCnt;
21
+
21 22
 extern bool Bluecell_Operate(uint8_t* data);
22 23
 extern void MBIC_Operate(uint8_t * data);
23 24
 
@@ -97,6 +98,7 @@ void GetDataFromUartQueue(UART_HandleTypeDef *huart)
97 98
     pQueue->data--;
98 99
     
99 100
     if(pQueue->data == 0){
101
+	HAL_IWDG_Refresh(&hiwdg);
100 102
 //        printf("data cnt zero !!!  \r\n");
101 103
         //RF_Ctrl_Main(&uart_buf[Header]);
102 104
 //        HAL_UART_Transmit(dst, &temp_buf[BLUECELL_HEADER00], 11, 3000);

+ 222 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_iwdg.h

@@ -0,0 +1,222 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_iwdg.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of IWDG HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
10
+  * All rights reserved.</center></h2>
11
+  *
12
+  * This software component is licensed by ST under BSD 3-Clause license,
13
+  * the "License"; You may not use this file except in compliance with the
14
+  * License. You may obtain a copy of the License at:
15
+  *                        opensource.org/licenses/BSD-3-Clause
16
+  *
17
+  ******************************************************************************
18
+  */
19
+
20
+/* Define to prevent recursive inclusion -------------------------------------*/
21
+#ifndef STM32F1xx_HAL_IWDG_H
22
+#define STM32F1xx_HAL_IWDG_H
23
+
24
+#ifdef __cplusplus
25
+extern "C" {
26
+#endif
27
+
28
+/* Includes ------------------------------------------------------------------*/
29
+#include "stm32f1xx_hal_def.h"
30
+
31
+/** @addtogroup STM32F1xx_HAL_Driver
32
+  * @{
33
+  */
34
+
35
+/** @addtogroup IWDG
36
+  * @{
37
+  */
38
+
39
+/* Exported types ------------------------------------------------------------*/
40
+/** @defgroup IWDG_Exported_Types IWDG Exported Types
41
+  * @{
42
+  */
43
+
44
+/**
45
+  * @brief  IWDG Init structure definition
46
+  */
47
+typedef struct
48
+{
49
+  uint32_t Prescaler;  /*!< Select the prescaler of the IWDG.
50
+                            This parameter can be a value of @ref IWDG_Prescaler */
51
+
52
+  uint32_t Reload;     /*!< Specifies the IWDG down-counter reload value.
53
+                            This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
54
+
55
+} IWDG_InitTypeDef;
56
+
57
+/**
58
+  * @brief  IWDG Handle Structure definition
59
+  */
60
+typedef struct
61
+{
62
+  IWDG_TypeDef                 *Instance;  /*!< Register base address    */
63
+
64
+  IWDG_InitTypeDef             Init;       /*!< IWDG required parameters */
65
+
66
+} IWDG_HandleTypeDef;
67
+
68
+/**
69
+  * @}
70
+  */
71
+
72
+/* Exported constants --------------------------------------------------------*/
73
+/** @defgroup IWDG_Exported_Constants IWDG Exported Constants
74
+  * @{
75
+  */
76
+
77
+/** @defgroup IWDG_Prescaler IWDG Prescaler
78
+  * @{
79
+  */
80
+#define IWDG_PRESCALER_4                0x00000000U                   /*!< IWDG prescaler set to 4   */
81
+#define IWDG_PRESCALER_8                IWDG_PR_PR_0                  /*!< IWDG prescaler set to 8   */
82
+#define IWDG_PRESCALER_16               IWDG_PR_PR_1                  /*!< IWDG prescaler set to 16  */
83
+#define IWDG_PRESCALER_32               (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 32  */
84
+#define IWDG_PRESCALER_64               IWDG_PR_PR_2                  /*!< IWDG prescaler set to 64  */
85
+#define IWDG_PRESCALER_128              (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 128 */
86
+#define IWDG_PRESCALER_256              (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< IWDG prescaler set to 256 */
87
+/**
88
+  * @}
89
+  */
90
+
91
+/**
92
+  * @}
93
+  */
94
+
95
+
96
+/* Exported macros -----------------------------------------------------------*/
97
+/** @defgroup IWDG_Exported_Macros IWDG Exported Macros
98
+  * @{
99
+  */
100
+
101
+/**
102
+  * @brief  Enable the IWDG peripheral.
103
+  * @param  __HANDLE__  IWDG handle
104
+  * @retval None
105
+  */
106
+#define __HAL_IWDG_START(__HANDLE__)                WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
107
+
108
+/**
109
+  * @brief  Reload IWDG counter with value defined in the reload register
110
+  *         (write access to IWDG_PR & IWDG_RLR registers disabled).
111
+  * @param  __HANDLE__  IWDG handle
112
+  * @retval None
113
+  */
114
+#define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__)       WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
115
+
116
+/**
117
+  * @}
118
+  */
119
+
120
+/* Exported functions --------------------------------------------------------*/
121
+/** @defgroup IWDG_Exported_Functions  IWDG Exported Functions
122
+  * @{
123
+  */
124
+
125
+/** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions
126
+  * @{
127
+  */
128
+/* Initialization/Start functions  ********************************************/
129
+HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
130
+/**
131
+  * @}
132
+  */
133
+
134
+/** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
135
+  * @{
136
+  */
137
+/* I/O operation functions ****************************************************/
138
+HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
139
+/**
140
+  * @}
141
+  */
142
+
143
+/**
144
+  * @}
145
+  */
146
+
147
+/* Private constants ---------------------------------------------------------*/
148
+/** @defgroup IWDG_Private_Constants IWDG Private Constants
149
+  * @{
150
+  */
151
+
152
+/**
153
+  * @brief  IWDG Key Register BitMask
154
+  */
155
+#define IWDG_KEY_RELOAD                 0x0000AAAAU  /*!< IWDG Reload Counter Enable   */
156
+#define IWDG_KEY_ENABLE                 0x0000CCCCU  /*!< IWDG Peripheral Enable       */
157
+#define IWDG_KEY_WRITE_ACCESS_ENABLE    0x00005555U  /*!< IWDG KR Write Access Enable  */
158
+#define IWDG_KEY_WRITE_ACCESS_DISABLE   0x00000000U  /*!< IWDG KR Write Access Disable */
159
+
160
+/**
161
+  * @}
162
+  */
163
+
164
+/* Private macros ------------------------------------------------------------*/
165
+/** @defgroup IWDG_Private_Macros IWDG Private Macros
166
+  * @{
167
+  */
168
+
169
+/**
170
+  * @brief  Enable write access to IWDG_PR and IWDG_RLR registers.
171
+  * @param  __HANDLE__  IWDG handle
172
+  * @retval None
173
+  */
174
+#define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__)  WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
175
+
176
+/**
177
+  * @brief  Disable write access to IWDG_PR and IWDG_RLR registers.
178
+  * @param  __HANDLE__  IWDG handle
179
+  * @retval None
180
+  */
181
+#define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
182
+
183
+/**
184
+  * @brief  Check IWDG prescaler value.
185
+  * @param  __PRESCALER__  IWDG prescaler value
186
+  * @retval None
187
+  */
188
+#define IS_IWDG_PRESCALER(__PRESCALER__)      (((__PRESCALER__) == IWDG_PRESCALER_4)  || \
189
+                                               ((__PRESCALER__) == IWDG_PRESCALER_8)  || \
190
+                                               ((__PRESCALER__) == IWDG_PRESCALER_16) || \
191
+                                               ((__PRESCALER__) == IWDG_PRESCALER_32) || \
192
+                                               ((__PRESCALER__) == IWDG_PRESCALER_64) || \
193
+                                               ((__PRESCALER__) == IWDG_PRESCALER_128)|| \
194
+                                               ((__PRESCALER__) == IWDG_PRESCALER_256))
195
+
196
+/**
197
+  * @brief  Check IWDG reload value.
198
+  * @param  __RELOAD__  IWDG reload value
199
+  * @retval None
200
+  */
201
+#define IS_IWDG_RELOAD(__RELOAD__)            ((__RELOAD__) <= IWDG_RLR_RL)
202
+
203
+/**
204
+  * @}
205
+  */
206
+
207
+/**
208
+  * @}
209
+  */
210
+
211
+/**
212
+  * @}
213
+  */
214
+
215
+
216
+#ifdef __cplusplus
217
+}
218
+#endif
219
+
220
+#endif /* STM32F1xx_HAL_IWDG_H */
221
+
222
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 240 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c

@@ -0,0 +1,240 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_iwdg.c
4
+  * @author  MCD Application Team
5
+  * @brief   IWDG HAL module driver.
6
+  *          This file provides firmware functions to manage the following
7
+  *          functionalities of the Independent Watchdog (IWDG) peripheral:
8
+  *           + Initialization and Start functions
9
+  *           + IO operation functions
10
+  *
11
+  @verbatim
12
+  ==============================================================================
13
+                    ##### IWDG Generic features #####
14
+  ==============================================================================
15
+  [..]
16
+    (+) The IWDG can be started by either software or hardware (configurable
17
+        through option byte).
18
+
19
+    (+) The IWDG is clocked by Low-Speed clock (LSI) and thus stays active even
20
+        if the main clock fails.
21
+
22
+    (+) Once the IWDG is started, the LSI is forced ON and both can not be
23
+        disabled. The counter starts counting down from the reset value (0xFFF).
24
+        When it reaches the end of count value (0x000) a reset signal is
25
+        generated (IWDG reset).
26
+
27
+    (+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register,
28
+        the IWDG_RLR value is reloaded in the counter and the watchdog reset is
29
+        prevented.
30
+
31
+    (+) The IWDG is implemented in the VDD voltage domain that is still functional
32
+        in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
33
+        IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
34
+        reset occurs.
35
+
36
+    (+) Debug mode : When the microcontroller enters debug mode (core halted),
37
+        the IWDG counter either continues to work normally or stops, depending
38
+        on DBG_IWDG_STOP configuration bit in DBG module, accessible through
39
+        __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros
40
+
41
+    [..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
42
+         The IWDG timeout may vary due to LSI frequency dispersion. STM32F1xx
43
+         devices provide the capability to measure the LSI frequency (LSI clock
44
+         connected internally to TIM5 CH4 input capture). The measured value
45
+         can be used to have an IWDG timeout with an acceptable accuracy.
46
+
47
+                     ##### How to use this driver #####
48
+  ==============================================================================
49
+  [..]
50
+    (#) Use IWDG using HAL_IWDG_Init() function to :
51
+      (++) Enable instance by writing Start keyword in IWDG_KEY register. LSI
52
+           clock is forced ON and IWDG counter starts downcounting.
53
+      (++) Enable write access to configuration register: IWDG_PR & IWDG_RLR.
54
+      (++) Configure the IWDG prescaler and counter reload value. This reload
55
+           value will be loaded in the IWDG counter each time the watchdog is
56
+           reloaded, then the IWDG will start counting down from this value.
57
+      (++) wait for status flags to be reset"
58
+
59
+    (#) Then the application program must refresh the IWDG counter at regular
60
+        intervals during normal operation to prevent an MCU reset, using
61
+        HAL_IWDG_Refresh() function.
62
+
63
+     *** IWDG HAL driver macros list ***
64
+     ====================================
65
+     [..]
66
+       Below the list of most used macros in IWDG HAL driver:
67
+      (+) __HAL_IWDG_START: Enable the IWDG peripheral
68
+      (+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in
69
+          the reload register
70
+
71
+  @endverbatim
72
+  ******************************************************************************
73
+  * @attention
74
+  *
75
+  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
76
+  * All rights reserved.</center></h2>
77
+  *
78
+  * This software component is licensed by ST under BSD 3-Clause license,
79
+  * the "License"; You may not use this file except in compliance with the
80
+  * License. You may obtain a copy of the License at:
81
+  *                        opensource.org/licenses/BSD-3-Clause
82
+  *
83
+  ******************************************************************************
84
+  */
85
+
86
+/* Includes ------------------------------------------------------------------*/
87
+#include "stm32f1xx_hal.h"
88
+
89
+/** @addtogroup STM32F1xx_HAL_Driver
90
+  * @{
91
+  */
92
+
93
+#ifdef HAL_IWDG_MODULE_ENABLED
94
+/** @defgroup IWDG IWDG
95
+  * @brief IWDG HAL module driver.
96
+  * @{
97
+  */
98
+
99
+/* Private typedef -----------------------------------------------------------*/
100
+/* Private define ------------------------------------------------------------*/
101
+/** @defgroup IWDG_Private_Defines IWDG Private Defines
102
+  * @{
103
+  */
104
+/* Status register need 5 RC LSI divided by prescaler clock to be updated. With
105
+   higher prescaler (256), and according to HSI variation, we need to wait at
106
+   least 6 cycles so 48 ms. */
107
+#define HAL_IWDG_DEFAULT_TIMEOUT            48U
108
+/**
109
+  * @}
110
+  */
111
+
112
+/* Private macro -------------------------------------------------------------*/
113
+/* Private variables ---------------------------------------------------------*/
114
+/* Private function prototypes -----------------------------------------------*/
115
+/* Exported functions --------------------------------------------------------*/
116
+
117
+/** @addtogroup IWDG_Exported_Functions
118
+  * @{
119
+  */
120
+
121
+/** @addtogroup IWDG_Exported_Functions_Group1
122
+  *  @brief    Initialization and Start functions.
123
+  *
124
+@verbatim
125
+ ===============================================================================
126
+          ##### Initialization and Start functions #####
127
+ ===============================================================================
128
+ [..]  This section provides functions allowing to:
129
+      (+) Initialize the IWDG according to the specified parameters in the
130
+          IWDG_InitTypeDef of associated handle.
131
+      (+) Once initialization is performed in HAL_IWDG_Init function, Watchdog
132
+          is reloaded in order to exit function with correct time base.
133
+
134
+@endverbatim
135
+  * @{
136
+  */
137
+
138
+/**
139
+  * @brief  Initialize the IWDG according to the specified parameters in the
140
+  *         IWDG_InitTypeDef and start watchdog. Before exiting function,
141
+  *         watchdog is refreshed in order to have correct time base.
142
+  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
143
+  *                the configuration information for the specified IWDG module.
144
+  * @retval HAL status
145
+  */
146
+HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
147
+{
148
+  uint32_t tickstart;
149
+
150
+  /* Check the IWDG handle allocation */
151
+  if (hiwdg == NULL)
152
+  {
153
+    return HAL_ERROR;
154
+  }
155
+
156
+  /* Check the parameters */
157
+  assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
158
+  assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
159
+  assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
160
+
161
+  /* Enable IWDG. LSI is turned on automaticaly */
162
+  __HAL_IWDG_START(hiwdg);
163
+
164
+  /* Enable write access to IWDG_PR and IWDG_RLR registers by writing 0x5555 in KR */
165
+  IWDG_ENABLE_WRITE_ACCESS(hiwdg);
166
+
167
+  /* Write to IWDG registers the Prescaler & Reload values to work with */
168
+  hiwdg->Instance->PR = hiwdg->Init.Prescaler;
169
+  hiwdg->Instance->RLR = hiwdg->Init.Reload;
170
+
171
+  /* Check pending flag, if previous update not done, return timeout */
172
+  tickstart = HAL_GetTick();
173
+
174
+  /* Wait for register to be updated */
175
+  while (hiwdg->Instance->SR != RESET)
176
+  {
177
+    if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
178
+    {
179
+      return HAL_TIMEOUT;
180
+    }
181
+  }
182
+
183
+  /* Reload IWDG counter with value defined in the reload register */
184
+  __HAL_IWDG_RELOAD_COUNTER(hiwdg);
185
+
186
+  /* Return function status */
187
+  return HAL_OK;
188
+}
189
+
190
+/**
191
+  * @}
192
+  */
193
+
194
+/** @addtogroup IWDG_Exported_Functions_Group2
195
+  *  @brief   IO operation functions
196
+  *
197
+@verbatim
198
+ ===============================================================================
199
+                      ##### IO operation functions #####
200
+ ===============================================================================
201
+ [..]  This section provides functions allowing to:
202
+      (+) Refresh the IWDG.
203
+
204
+@endverbatim
205
+  * @{
206
+  */
207
+
208
+/**
209
+  * @brief  Refresh the IWDG.
210
+  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
211
+  *                the configuration information for the specified IWDG module.
212
+  * @retval HAL status
213
+  */
214
+HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
215
+{
216
+  /* Reload IWDG counter with value defined in the reload register */
217
+  __HAL_IWDG_RELOAD_COUNTER(hiwdg);
218
+
219
+  /* Return function status */
220
+  return HAL_OK;
221
+}
222
+
223
+/**
224
+  * @}
225
+  */
226
+
227
+/**
228
+  * @}
229
+  */
230
+
231
+#endif /* HAL_IWDG_MODULE_ENABLED */
232
+/**
233
+  * @}
234
+  */
235
+
236
+/**
237
+  * @}
238
+  */
239
+
240
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 1 - 1
Inc/stm32f1xx_hal_conf.h

@@ -48,7 +48,7 @@
48 48
 #define HAL_I2C_MODULE_ENABLED
49 49
 /*#define HAL_I2S_MODULE_ENABLED   */
50 50
 /*#define HAL_IRDA_MODULE_ENABLED   */
51
-/*#define HAL_IWDG_MODULE_ENABLED   */
51
+#define HAL_IWDG_MODULE_ENABLED
52 52
 /*#define HAL_NOR_MODULE_ENABLED   */
53 53
 /*#define HAL_NAND_MODULE_ENABLED   */
54 54
 /*#define HAL_PCCARD_MODULE_ENABLED   */

+ 18 - 11
STM32F103ZET_JDASMBIC.ioc

@@ -91,19 +91,23 @@ File.Version=6
91 91
 GPIO.groupedBy=Group By Peripherals
92 92
 I2C2.I2C_Mode=I2C_Standard
93 93
 I2C2.IPParameters=I2C_Mode
94
+IWDG.IPParameters=Reload,Prescaler
95
+IWDG.Prescaler=IWDG_PRESCALER_128
96
+IWDG.Reload=4095
94 97
 KeepUserPlacement=false
95 98
 Mcu.Family=STM32F1
96 99
 Mcu.IP0=ADC1
97 100
 Mcu.IP1=ADC3
101
+Mcu.IP10=USART2
98 102
 Mcu.IP2=DMA
99 103
 Mcu.IP3=I2C2
100
-Mcu.IP4=NVIC
101
-Mcu.IP5=RCC
102
-Mcu.IP6=SYS
103
-Mcu.IP7=TIM6
104
-Mcu.IP8=USART1
105
-Mcu.IP9=USART2
106
-Mcu.IPNb=10
104
+Mcu.IP4=IWDG
105
+Mcu.IP5=NVIC
106
+Mcu.IP6=RCC
107
+Mcu.IP7=SYS
108
+Mcu.IP8=TIM6
109
+Mcu.IP9=USART1
110
+Mcu.IPNb=11
107 111
 Mcu.Name=STM32F103Z(C-D-E)Tx
108 112
 Mcu.Package=LQFP144
109 113
 Mcu.Pin0=PE3
@@ -160,13 +164,14 @@ Mcu.Pin54=PG15
160 164
 Mcu.Pin55=PB6
161 165
 Mcu.Pin56=PB7
162 166
 Mcu.Pin57=PB9
163
-Mcu.Pin58=VP_SYS_VS_tim2
164
-Mcu.Pin59=VP_TIM6_VS_ClockSourceINT
167
+Mcu.Pin58=VP_IWDG_VS_IWDG
168
+Mcu.Pin59=VP_SYS_VS_tim2
165 169
 Mcu.Pin6=PF9
170
+Mcu.Pin60=VP_TIM6_VS_ClockSourceINT
166 171
 Mcu.Pin7=PF10
167 172
 Mcu.Pin8=PC2
168 173
 Mcu.Pin9=PA2
169
-Mcu.PinsNb=60
174
+Mcu.PinsNb=61
170 175
 Mcu.ThirdPartyNb=0
171 176
 Mcu.UserConstants=
172 177
 Mcu.UserName=STM32F103ZETx
@@ -456,7 +461,7 @@ ProjectManager.StackSize=0x400
456 461
 ProjectManager.TargetToolchain=TrueSTUDIO
457 462
 ProjectManager.ToolChainLocation=
458 463
 ProjectManager.UnderRoot=true
459
-ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_ADC1_Init-ADC1-false-HAL-true,6-MX_ADC3_Init-ADC3-false-HAL-true,7-MX_USART2_UART_Init-USART2-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_I2C2_Init-I2C2-false-HAL-true
464
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_ADC1_Init-ADC1-false-HAL-true,6-MX_ADC3_Init-ADC3-false-HAL-true,7-MX_USART2_UART_Init-USART2-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_I2C2_Init-I2C2-false-HAL-true,10-MX_IWDG_Init-IWDG-false-HAL-true
460 465
 RCC.ADCFreqValue=14000000
461 466
 RCC.ADCPresc=RCC_ADCPCLK2_DIV4
462 467
 RCC.AHBFreq_Value=56000000
@@ -500,6 +505,8 @@ USART1.VirtualMode=VM_ASYNC
500 505
 USART2.BaudRate=115200
501 506
 USART2.IPParameters=VirtualMode,BaudRate
502 507
 USART2.VirtualMode=VM_ASYNC
508
+VP_IWDG_VS_IWDG.Mode=IWDG_Activate
509
+VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
503 510
 VP_SYS_VS_tim2.Mode=TIM2
504 511
 VP_SYS_VS_tim2.Signal=SYS_VS_tim2
505 512
 VP_TIM6_VS_ClockSourceINT.Mode=Enable_Timer

+ 45 - 3
Src/main.c

@@ -53,6 +53,8 @@ DMA_HandleTypeDef hdma_adc3;
53 53
 
54 54
 I2C_HandleTypeDef hi2c2;
55 55
 
56
+IWDG_HandleTypeDef hiwdg;
57
+
56 58
 TIM_HandleTypeDef htim6;
57 59
 
58 60
 UART_HandleTypeDef huart1;
@@ -157,6 +159,7 @@ static void MX_ADC3_Init(void);
157 159
 static void MX_USART2_UART_Init(void);
158 160
 static void MX_TIM6_Init(void);
159 161
 static void MX_I2C2_Init(void);
162
+static void MX_IWDG_Init(void);
160 163
 static void MX_NVIC_Init(void);
161 164
 /* USER CODE BEGIN PFP */
162 165
 extern void Booting_LedInit(void);
@@ -264,6 +267,7 @@ int main(void)
264 267
   MX_USART2_UART_Init();
265 268
   MX_TIM6_Init();
266 269
   MX_I2C2_Init();
270
+  MX_IWDG_Init();
267 271
 
268 272
   /* Initialize interrupts */
269 273
   MX_NVIC_Init();
@@ -296,7 +300,16 @@ int main(void)
296 300
     printf("Copyright (c) 2020. BLUECELL\r\n");
297 301
     printf("****************************************\r\n");
298 302
 #endif // PYJ.2020.05.06_END --  
299
-  
303
+    /* whachdog Reset Operated? */
304
+  //   if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) == SET)
305
+  // {
306
+  //   __HAL_RCC_CLEAR_RESET_FLAGS();
307
+  // }
308
+
309
+  /* USER CODE END 2 */
310
+
311
+  /* Infinite loop */
312
+  /* USER CODE BEGIN WHILE */
300 313
   while (1)
301 314
   {
302 315
     Boot_LED_Toggle(); /*LED Check*/
@@ -326,9 +339,10 @@ void SystemClock_Config(void)
326 339
 
327 340
   /** Initializes the CPU, AHB and APB busses clocks 
328 341
   */
329
-  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
342
+  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
330 343
   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
331 344
   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
345
+  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
332 346
   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
333 347
   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
334 348
   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL14;
@@ -572,6 +586,35 @@ static void MX_I2C2_Init(void)
572 586
 
573 587
 }
574 588
 
589
+/**
590
+  * @brief IWDG Initialization Function
591
+  * @param None
592
+  * @retval None
593
+  */
594
+static void MX_IWDG_Init(void)
595
+{
596
+
597
+  /* USER CODE BEGIN IWDG_Init 0 */
598
+
599
+  /* USER CODE END IWDG_Init 0 */
600
+
601
+  /* USER CODE BEGIN IWDG_Init 1 */
602
+
603
+  /* USER CODE END IWDG_Init 1 */
604
+  hiwdg.Instance = IWDG;
605
+  hiwdg.Init.Prescaler = IWDG_PRESCALER_128;
606
+  hiwdg.Init.Reload = 4095;
607
+#if 1  
608
+//  if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
609
+//  {
610
+//    Error_Handler();
611
+//  }
612
+  /* USER CODE BEGIN IWDG_Init 2 */
613
+#endif
614
+  /* USER CODE END IWDG_Init 2 */
615
+
616
+}
617
+
575 618
 /**
576 619
   * @brief TIM6 Initialization Function
577 620
   * @param None
@@ -874,7 +917,6 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
874 917
       LDTimerCnt++;
875 918
       ALCTimerCnt++;
876 919
       AGCTimerCnt++;
877
-      
878 920
 //    pdata = &bluecell_Currdatastatus.ATT_UL1_PATH;
879 921
     UL_Shutdown_Timer(DET_Alarm_UL1_Shutdown_Index);
880 922
 //    pdata = &bluecell_Currdatastatus.ATT_UL2_PATH;