-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperistent_test.cpp
102 lines (85 loc) · 2.56 KB
/
peristent_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//persistent data test
//pic32mm0256gpm064
//xc32 2.15 or xc32 2.10
#include <cstdint>
#include "Osc.hpp"
#include "Delay.hpp"
#include "Resets.hpp"
#include "Uart.hpp"
Uart info{Uart::UART2, Pins::C6, Pins::C7, 921600};
unsigned int __attribute__((persistent)) pattern;
int main()
{
uint8_t r = (uint8_t)Resets::cause();
/*
enum
CAUSE : uint8_t {
EXTR = 1<<7, SWR = 1<<6, //1<<5 none- reads 0
WDTO = 1<<4, SLEEP = 1<<3, IDLE = 1<<2, BOR = 1<<1, POR = 1<<0
};
*/
const char* causes[] = {
"POR","BOR","IDLE","SLEEP","WDTO","SOMETHING WRONG","SWR","EXTR"
};
//set osc to 24MHz
Osc osc;
osc.pll_set(osc.MUL12, osc.DIV4); //8*12/4 = 24MHz
osc.sosc(true); //enable sosc if not already
osc.tun_auto(true); //let sosc tune frc
//info uart on
info.on( true );
//print pattern value and reset cause
info.printf( "\r\n\r\npattern: %d\r\n", pattern++ );
info.printf( "Reset Cause: 0x%02X - ", r );
for(auto i = 0; i < 8; i++){
if( r bitand (1<<i) ) {
info.printf( "%s ", causes[i] );
}
}
//delay
info.printf( "\r\nDelay 2 seconds...");
Delay::wait( 2_sec );
info.printf( "done. Resetting...");
Delay::wait( 100_ms ); //wait for chars to make it out
//inc pattern 0-9
if( pattern > 9 ) pattern = 0;
//swreset
Resets::swreset();
for(;;){}
};
/*
pattern: -14663259
Reset Cause: 0x80 - EXTR
Delay 2 seconds...done. Resetting...
pattern: 0
Reset Cause: 0x40 - SWR
Delay 2 seconds...done. Resetting...
pattern: 1
Reset Cause: 0x40 - SWR
Delay 2 seconds...done. Resetting...
//2 3 4 5 6 7
pattern: 8
Reset Cause: 0x40 - SWR
Delay 2 seconds...done. Resetting...
pattern: 9
Reset Cause: 0x40 - SWR
Delay 2 seconds...done. Resetting...
pattern: 0
Reset Cause: 0x40 - SWR
Delay 2 seconds...done. Resetting...
map file-
.persist 0x80000008 0x4
0x80000008 _persist_begin = .
*(.persist .persist.*)
*(.pbss .pbss.*)
.pbss.pattern 0x80000008 0x4 build/default/production/peristent_test.o
0x80000008 pattern
0x8000000c . = ALIGN (0x4)
0x8000000c _persist_end = .
.data 0x8000000c 0x0
*(.gnu.linkonce.d.*)
*(.data1)
0x8000000c . = ALIGN (0x4)
0x8000000c . = .
0x80008000 _gp = (ALIGN (0x10) + 0x7ff0)
*/