Skip to content

Commit 229dc61

Browse files
Add IWDG as STM32.wdtEnable(timeout) / STM32.wdtReset()
1 parent 5a49ad1 commit 229dc61

File tree

14 files changed

+151
-6
lines changed

14 files changed

+151
-6
lines changed

cores/stm32l4/STM32.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ uint64_t STM32Class::getSerial()
4545
return (((uint64_t)serial0 << 16) | ((uint64_t)serial1 >> 16));
4646
}
4747

48+
void STM32Class::getUID(uint32_t uid[3])
49+
{
50+
uid[0] = *((uint32_t*)0x1fff7590);
51+
uid[1] = *((uint32_t*)0x1fff7594);
52+
uid[2] = *((uint32_t*)0x1fff7598);
53+
}
54+
4855
float STM32Class::getVBAT()
4956
{
5057
int32_t vbat_data, vref_data, vrefint;
@@ -196,6 +203,17 @@ void STM32Class::reset()
196203
stm32l4_system_reset();
197204
}
198205

206+
void STM32Class::wdtEnable(uint32_t timeout)
207+
{
208+
stm32l4_iwdg_enable(timeout);
209+
}
210+
211+
void STM32Class::wdtReset()
212+
{
213+
stm32l4_iwdg_reset();
214+
}
215+
216+
199217
bool STM32Class::flashErase(uint32_t address, uint32_t count)
200218
{
201219
if (address & 2047) {

cores/stm32l4/STM32.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
class STM32Class {
5757
public:
5858
uint64_t getSerial();
59+
void getUID(uint32_t uid[3]);
5960

6061
float getVBAT();
6162
float getVREF();
@@ -72,6 +73,9 @@ class STM32Class {
7273
void shutdown(uint32_t pin, uint32_t mode, uint32_t timeout = 0);
7374
void reset();
7475

76+
void wdtEnable(uint32_t timeout);
77+
void wdtReset();
78+
7579
bool flashErase(uint32_t address, uint32_t count);
7680
bool flashProgram(uint32_t address, const void *data, uint32_t count);
7781

cores/stm32l4/stm32l4_wiring_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern "C" {
5151
#include "stm32l4_flash.h"
5252
#include "stm32l4_sdmmc.h"
5353
#include "stm32l4_sdspi.h"
54+
#include "stm32l4_iwdg.h"
5455

5556
#define STM32L4_SVCALL_IRQ_PRIORITY 15
5657
#define STM32L4_PENDSV_IRQ_PRIORITY 15
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2017 Thomas Roell. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to
6+
* deal with the Software without restriction, including without limitation the
7+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8+
* sell copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimers.
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimers in the
15+
* documentation and/or other materials provided with the distribution.
16+
* 3. Neither the name of Thomas Roell, nor the names of its contributors
17+
* may be used to endorse or promote products derived from this Software
18+
* without specific prior written permission.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26+
* WITH THE SOFTWARE.
27+
*/
28+
29+
#if !defined(_STM32L4_IWDG_H)
30+
#define _STM32L4_IWDG_H
31+
32+
#include <stdint.h>
33+
34+
#include "stm32l4xx.h"
35+
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
40+
extern void stm32l4_iwdg_enable(uint32_t timeout);
41+
42+
static inline void stm32l4_iwdg_reset(void)
43+
{
44+
IWDG->KR = 0xaaaa;
45+
}
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif /* _STM32L4_NVIC_H */
16 Bytes
Binary file not shown.
16 Bytes
Binary file not shown.
16 Bytes
Binary file not shown.
4.28 KB
Binary file not shown.
4.28 KB
Binary file not shown.
4.28 KB
Binary file not shown.

0 commit comments

Comments
 (0)