forked from kiibohd/controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchip_version.h
More file actions
252 lines (227 loc) · 6.73 KB
/
Copy pathchip_version.h
File metadata and controls
252 lines (227 loc) · 6.73 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* Copyright (C) 2017 by Jacob Alexander
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
// ----- Defines -----
//
// - SIM_SDID Lookup -
//
// ----- Includes -----
#include <stdint.h>
#include <Lib/kinetis.h>
// ----- Variables -----
// See 12.2.7 SIM_SDID - https://www.nxp.com/docs/en/reference-manual/K22P64M120SF5V2RM.pdf
// Can be updated as long as it doesn't conflict with older versions
// Mark reserved as --
// PINID
const char *ChipVersion_pincount[] = {
"--", // 0 - 0000
"--", // 1 - 0001
"32-pin", // 2 - 0010
"--", // 3 - 0011
"48-pin", // 4 - 0100
"64-pin", // 5 - 0101
"80-pin", // 6 - 0110
"81/121-pin", // 7 - 0111
"100-pin", // 8 - 1000
"121-pin", // 9 - 1001
"144-pin", // 10 - 1010
"WLCSP", // 11 - 1011 - Custom pinout (WLCSP)
"--", // 12 - 1100
"--", // 13 - 1101
"256-pin", // 14 - 1110
"--", // 15 - 1111
};
// See 12.2.7 SIM_SDID - https://www.nxp.com/docs/en/reference-manual/K22P64M120SF5V2RM.pdf
// Can be updated as long as it doesn't conflict with older versions
// Mark reserved as --
// FAMID
const char *ChipVersion_familyid[] = {
"K10/12", // 0 - 000 - K10, K12 Family
"K20/22", // 1 - 001 - K20, K22 Family
"K30/11/61", // 2 - 010 - K30, K11 or K61 Family
"K40/21", // 3 - 011 - K40, K21 Family
"K60/62", // 4 - 100 - K60, K62 Family
"K70", // 5 - 101 - K70 Family
"--", // 6 - 110
"--", // 7 - 111
};
// See 12.2.17 SIM_FCFG1 - https://www.nxp.com/docs/en/reference-manual/K22P64M120SF5V2RM.pdf
// Can be updated as long as it doesn't conflict with older versions
// Mark reserved as 0xFFFF
// NVMSIZE
uint16_t ChipVersion_nvmsize[] = {
0, // 0000 - 0 kB FlexNVM
0xFFFF, // 0001
0xFFFF, // 0010
32, // 0011 - 32 kB FlexNVM
64, // 0101 - 64 kB FlexNVM
128, // 0111 - 128 kB FlexNVM
0xFFFF, // 1000
256, // 1001 - 256 kB FlexNVM
0xFFFF, // 1010
512, // 1011 - 512 kB FlexNVM
0xFFFF, // 1100
0xFFFF, // 1101
0xFFFF, // 1110
0xFFFF, // 1111
512, // 1111 - 512 kB FlexNVM
};
// See 12.2.17 SIM_FCFG1 - https://www.nxp.com/docs/en/reference-manual/K22P64M120SF5V2RM.pdf
// Can be updated as long as it doesn't conflict with older versions
// Mark reserved as 0xFFFF
// PFSIZE
uint16_t ChipVersion_pflashsize[] = {
0xFFFF, // 0000
0xFFFF, // 0001
0xFFFF, // 0010
32, // 0011 - 32 kB Program Flash
0xFFFF, // 0100
64, // 0101 - 64 kB Program Flash
0xFFFF, // 0110
128, // 0111 - 128 kB Program Flash
0xFFFF, // 1000
256, // 1001 - 256 kB Program Flash
0xFFFF, // 1010
512, // 1011 - 512 kB Program Flash
0xFFFF, // 1100
1024, // 1101 - 1024 kB Program Flash
0xFFFF, // 1110
1024, // 1111 - 1024 kB Program Flash
};
// See 12.2.17 SIM_FCFG1 - https://www.nxp.com/docs/en/reference-manual/K22P64M120SF5V2RM.pdf
// Can be updated as long as it doesn't conflict with older versions
// Mark reserved as 0xFFFF
// EESIZE
uint16_t ChipVersion_eepromsize[] = {
16384, // 0000 - 16 kB EEPROM
8192, // 0001 - 8 kB EEPROM
4096, // 0010 - 4 kB EEPROM
2048, // 0011 - 2 kB EEPROM
1024, // 0100 - 1 kB EEPROM
512, // 0101 - 512 B EEPROM
256, // 0110 - 256 B EEPROM
128, // 0111 - 128 B EEPROM
64, // 1000 - 64 B EEPROM
32, // 1001 - 32 B EEPROM
0xFFFF, // 1010
0xFFFF, // 1011
0xFFFF, // 1100
0xFFFF, // 1101
0xFFFF, // 1110
0, // 1111 - 0 B EEPROM
};
// See 12.2.1 SIM_SOPT1 - https://www.nxp.com/docs/en/reference-manual/K22P64M120SF5V2RM.pdf
// Can be updated as long as it doesn't conflict with older versions
// Mark reserved as 0xFFFF
// RAMSIZE
uint16_t ChipVersion_ramsize[] = {
0xFFFF, // 0000
8, // 0001 - 8 kB RAM
0xFFFF, // 0010
16, // 0011 - 16 kB RAM
24, // 0100 - 24 kB RAM
32, // 0101 - 32 kB RAM
48, // 0110 - 48 kB RAM
64, // 0111 - 64 kB RAM
96, // 1000 - 96 kB RAM
128, // 1001 - 128 kB RAM
0xFFFF, // 1010
256, // 1011 - 256 kB RAM
0xFFFF, // 1100
0xFFFF, // 1101
0xFFFF, // 1110
0xFFFF, // 1111
};
// ----- Function Declarations -----
// ----- Functions -----
const char *ChipVersion_cpuid_partno()
{
switch ( SCB_CPUID_PARTNO )
{
case 0xC24:
return "Cortex-M4";
default:
return "--";
}
}
const char *ChipVersion_cpuid_implementor()
{
switch ( SCB_CPUID_IMPLEMENTOR )
{
case 0x41:
return "ARM";
default:
return "--";
}
}
// Attempts to detect the chip part number using registers only
// Not perfect, but is quite useful
// Returns -- if unknown
const char *ChipVersion_lookup()
{
// Kinetis K-Series pg. 7
// http://cache.freescale.com/files/product/doc/BRORDERINFO.pdf
//
// The first m stands for production, the other option is p (unqualified sample)
//uint8_t family = SIM_SDID_FAMID; // e.g. k20
// TODO e.g. d (Cortex-M4)
//uint8_t flex = SIM_FCFG1_NVMSIZE ? 1 : 0; // e.g. x (Flex memory)
uint16_t pflash = ChipVersion_pflashsize[ SIM_FCFG1_PFSIZE ]; // e.g. 256 (256 kB)
// TODO e.g. a (3rd rev)
// TODO e.g. v (-40C to +105C)
//uint8_t pincount = SIM_SDID_PINID; // e.g. LH (64 LQFP)
// TODO e.g. 7 (70 MHz)
// Using openocd method of using the SDID mask
// Not perfect, but generally ok, also using the pincount
if ( SIM_SDID & 0x00000095 )
{
switch ( pflash )
{
case 128:
return "mk20dx128vlh7";
case 256:
return "mk20dx256vlh7";
default:
return "mk20dxXXXvlh7";
}
}
else if ( SIM_SDID & 0x00000099 ) // TODO Might be 0x97 81/121-pin
{
switch ( pflash )
{
case 256:
return "mk20dx256vmc7";
default:
return "mk20dxXXXvmc7";
}
}
else if ( SIM_SDID & 0x00000315 )
{
switch ( pflash )
{
case 512:
return "mk22fx512avlh12";
default:
return "mk22fxXXXavlh12";
}
}
return "--";
}