Merge pull request #415 from texane/chipid_refactor
[fw/stlink] / src / chipid.c
1 #include "stlink.h"
2 #include "stlink/chipid.h"
3
4 static const struct stlink_chipid_params devices[] = {
5         {
6             //RM0385 and DS10916 document was used to find these paramaters
7             .chip_id = STLINK_CHIPID_STM32_F7,
8             .description = "F7 device",
9             .flash_type = FLASH_TYPE_F4,
10             .flash_size_reg = 0x1ff0f442,      // section 41.2
11             .flash_pagesize = 0x800,           // No flash pages
12             .sram_size = 0x50000,              // "SRAM" byte size in hex from DS Fig 18
13             .bootrom_base = 0x00100000,        // "System memory" starting address from DS Fig 18
14             .bootrom_size = 0xEDC0             // "System memory" byte size in hex from DS Fig 18
15         },
16         { // table 2, PM0063
17             .chip_id = STLINK_CHIPID_STM32_F1_MEDIUM,
18             .description = "F1 Medium-density device",
19             .flash_type = FLASH_TYPE_F0,
20             .flash_size_reg = 0x1ffff7e0,
21             .flash_pagesize = 0x400,
22             .sram_size = 0x5000,
23             .bootrom_base = 0x1ffff000,
24             .bootrom_size = 0x800
25         },
26         {  // table 1, PM0059
27             .chip_id = STLINK_CHIPID_STM32_F2,
28             .description = "F2 device",
29             .flash_type = FLASH_TYPE_F4,
30             .flash_size_reg = 0x1fff7a22, /* As in RM0033 Rev 5*/
31             .flash_pagesize = 0x20000,
32             .sram_size = 0x20000,
33             .bootrom_base = 0x1fff0000,
34             .bootrom_size = 0x7800
35         },
36         { // PM0063
37             .chip_id = STLINK_CHIPID_STM32_F1_LOW,
38             .description = "F1 Low-density device",
39             .flash_type = FLASH_TYPE_F0,
40             .flash_size_reg = 0x1ffff7e0,
41             .flash_pagesize = 0x400,
42             .sram_size = 0x2800,
43             .bootrom_base = 0x1ffff000,
44             .bootrom_size = 0x800
45         },
46         {
47             .chip_id = STLINK_CHIPID_STM32_F4,
48             .description = "F4 device",
49             .flash_type = FLASH_TYPE_F4,
50             .flash_size_reg = 0x1FFF7A22,  /* As in rm0090 since Rev 2*/
51             .flash_pagesize = 0x4000,
52             .sram_size = 0x30000,
53             .bootrom_base = 0x1fff0000,
54             .bootrom_size = 0x7800
55         },
56         {
57             .chip_id = STLINK_CHIPID_STM32_F4_DSI,
58             .description = "F46x and F47x device",
59             .flash_type = FLASH_TYPE_F4,
60             .flash_size_reg = 0x1FFF7A22,  /* As in rm0090 since Rev 2*/
61             .flash_pagesize = 0x4000,
62             .sram_size = 0x40000,
63             .bootrom_base = 0x1fff0000,
64             .bootrom_size = 0x7800
65         },
66         {
67             .chip_id = STLINK_CHIPID_STM32_F4_HD,
68             .description = "F42x and F43x device",
69             .flash_type = FLASH_TYPE_F4,
70             .flash_size_reg = 0x1FFF7A22,  /* As in rm0090 since Rev 2*/
71             .flash_pagesize = 0x4000,
72             .sram_size = 0x40000,
73             .bootrom_base = 0x1fff0000,
74             .bootrom_size = 0x7800
75         },
76         {
77             .chip_id = STLINK_CHIPID_STM32_F4_LP,
78             .description = "F4 device (low power)",
79             .flash_type = FLASH_TYPE_F4,
80             .flash_size_reg = 0x1FFF7A22,
81             .flash_pagesize = 0x4000,
82             .sram_size = 0x10000,
83             .bootrom_base = 0x1fff0000,
84             .bootrom_size = 0x7800
85         },
86         {
87             .chip_id = STLINK_CHIPID_STM32_F411RE,
88             .description = "F4 device (low power) - stm32f411re",
89             .flash_type = FLASH_TYPE_F4,
90             .flash_size_reg = 0x1FFF7A22,
91             .flash_pagesize = 0x4000,
92             .sram_size = 0x20000,
93             .bootrom_base = 0x1fff0000,
94             .bootrom_size = 0x7800
95         },
96         {
97             .chip_id = STLINK_CHIPID_STM32_F4_DE,
98             .description = "F4 device (Dynamic Efficency)",
99             .flash_type = FLASH_TYPE_F4,
100             .flash_size_reg = 0x1FFF7A22,
101             .flash_pagesize = 0x4000,
102             .sram_size = 0x18000,
103             .bootrom_base = 0x1fff0000,
104             .bootrom_size = 0x7800
105         },
106         {
107             .chip_id = STLINK_CHIPID_STM32_F1_HIGH,
108             .description = "F1 High-density device",
109             .flash_type = FLASH_TYPE_F0,
110             .flash_size_reg = 0x1ffff7e0,
111             .flash_pagesize = 0x800,
112             .sram_size = 0x10000,
113             .bootrom_base = 0x1ffff000,
114             .bootrom_size = 0x800
115         },
116         {
117             // This ignores the EEPROM! (and uses the page erase size,
118             // not the sector write protection...)
119             .chip_id = STLINK_CHIPID_STM32_L1_MEDIUM,
120             .description = "L1 Med-density device",
121             .flash_type = FLASH_TYPE_L0,
122             .flash_size_reg = 0x1ff8004c,
123             .flash_pagesize = 0x100,
124             .sram_size = 0x4000,
125             .bootrom_base = 0x1ff00000,
126             .bootrom_size = 0x1000
127         },
128         {
129             .chip_id = STLINK_CHIPID_STM32_L1_CAT2,
130             .description = "L1 Cat.2 device",
131             .flash_type = FLASH_TYPE_L0,
132             .flash_size_reg = 0x1ff8004c,
133             .flash_pagesize = 0x100,
134             .sram_size = 0x8000,
135             .bootrom_base = 0x1ff00000,
136             .bootrom_size = 0x1000
137         },
138         {
139             .chip_id = STLINK_CHIPID_STM32_L1_MEDIUM_PLUS,
140             .description = "L1 Medium-Plus-density device",
141             .flash_type = FLASH_TYPE_L0,
142             .flash_size_reg = 0x1ff800cc,
143             .flash_pagesize = 0x100,
144             .sram_size = 0x8000,/*Not completely clear if there are some with 48K*/
145             .bootrom_base = 0x1ff00000,
146             .bootrom_size = 0x1000
147         },
148         {
149             .chip_id = STLINK_CHIPID_STM32_L1_HIGH,
150             .description = "L1 High-density device",
151             .flash_type = FLASH_TYPE_L0,
152             .flash_size_reg = 0x1ff800cc,
153             .flash_pagesize = 0x100,
154             .sram_size = 0xC000, /*Not completely clear if there are some with 32K*/
155             .bootrom_base = 0x1ff00000,
156             .bootrom_size = 0x1000
157         },
158         {
159             .chip_id = STLINK_CHIPID_STM32_L152_RE,
160             .description = "L152RE",
161             .flash_type = FLASH_TYPE_L0,
162             .flash_size_reg = 0x1ff800cc,
163             .flash_pagesize = 0x100,
164             .sram_size = 0x14000, /*Not completely clear if there are some with 32K*/
165             .bootrom_base = 0x1ff00000,
166             .bootrom_size = 0x1000
167         },
168         {
169             .chip_id = STLINK_CHIPID_STM32_F1_CONN,
170             .description = "F1 Connectivity line device",
171             .flash_type = FLASH_TYPE_F0,
172             .flash_size_reg = 0x1ffff7e0,
173             .flash_pagesize = 0x800,
174             .sram_size = 0x10000,
175             .bootrom_base = 0x1fffb000,
176             .bootrom_size = 0x4800
177         },
178         {//Low and Medium density VL have same chipid. RM0041 25.6.1
179             .chip_id = STLINK_CHIPID_STM32_F1_VL_MEDIUM_LOW,
180             .description = "F1 Medium/Low-density Value Line device",
181             .flash_type = FLASH_TYPE_F0,
182             .flash_size_reg = 0x1ffff7e0,
183             .flash_pagesize = 0x400,
184             .sram_size = 0x2000,//0x1000 for low density devices
185             .bootrom_base = 0x1ffff000,
186             .bootrom_size = 0x800
187         },
188         {
189             // STM32F446x family. Support based on DM00135183.pdf (RM0390) document.
190             .chip_id = STLINK_CHIPID_STM32_F446,
191             .description = "F446 device",
192             .flash_type = FLASH_TYPE_F4,
193             .flash_size_reg = 0x1fff7a22,
194             .flash_pagesize = 0x20000,
195             .sram_size = 0x20000,
196             .bootrom_base = 0x1fff0000,
197             .bootrom_size = 0x7800
198         },
199         {
200             // This is STK32F303VCT6 device from STM32 F3 Discovery board.
201             // Support based on DM00043574.pdf (RM0316) document.
202             .chip_id = STLINK_CHIPID_STM32_F3,
203             .description = "F3 device",
204             .flash_type = FLASH_TYPE_F0,
205             .flash_size_reg = 0x1ffff7cc,
206             .flash_pagesize = 0x800,
207             .sram_size = 0xa000,
208             .bootrom_base = 0x1ffff000,
209             .bootrom_size = 0x800
210         },
211         {
212             // This is STK32F373VCT6 device from STM32 F373 eval board
213             // Support based on 303 above (37x and 30x have same memory map)
214             .chip_id = STLINK_CHIPID_STM32_F37x,
215             .description = "F3 device",
216             .flash_type = FLASH_TYPE_F0,
217             .flash_size_reg = 0x1ffff7cc,
218             .flash_pagesize = 0x800,
219             .sram_size = 0xa000,
220             .bootrom_base = 0x1ffff000,
221             .bootrom_size = 0x800
222         },
223         {
224             .chip_id = STLINK_CHIPID_STM32_F1_VL_HIGH,
225             .description = "F1 High-density value line device",
226             .flash_type = FLASH_TYPE_F0,
227             .flash_size_reg = 0x1ffff7e0,
228             .flash_pagesize = 0x800,
229             .sram_size = 0x8000,
230             .bootrom_base = 0x1ffff000,
231             .bootrom_size = 0x800
232         },
233         {
234             .chip_id = STLINK_CHIPID_STM32_F1_XL,
235             .description = "F1 XL-density device",
236             .flash_type = FLASH_TYPE_F0,
237             .flash_size_reg = 0x1ffff7e0,
238             .flash_pagesize = 0x800,
239             .sram_size = 0x18000,
240             .bootrom_base = 0x1fffe000,
241             .bootrom_size = 0x1800
242         },
243         {
244             //Use this as an example for mapping future chips:
245             //RM0091 document was used to find these paramaters
246             .chip_id = STLINK_CHIPID_STM32_F0_CAN,
247             .description = "F07x device",
248             .flash_type = FLASH_TYPE_F0,
249             .flash_size_reg = 0x1ffff7cc,      // "Flash size data register" (pg735)
250             .flash_pagesize = 0x800,           // Page sizes listed in Table 4
251             .sram_size = 0x4000,               // "SRAM" byte size in hex from Table 2
252             .bootrom_base = 0x1fffC800,                // "System memory" starting address from Table 2
253             .bootrom_size = 0x3000             // "System memory" byte size in hex from Table 2
254         },
255         {
256             //Use this as an example for mapping future chips:
257             //RM0091 document was used to find these paramaters
258             .chip_id = STLINK_CHIPID_STM32_F0,
259             .description = "F0 device",
260             .flash_type = FLASH_TYPE_F0,
261             .flash_size_reg = 0x1ffff7cc,       // "Flash size data register" (pg735)
262             .flash_pagesize = 0x400,            // Page sizes listed in Table 4
263             .sram_size = 0x2000,                // "SRAM" byte size in hex from Table 2
264             .bootrom_base = 0x1fffec00,         // "System memory" starting address from Table 2
265             .bootrom_size = 0xC00               // "System memory" byte size in hex from Table 2
266         },
267         {
268             .chip_id = STLINK_CHIPID_STM32_F09X,
269             .description = "F09X device",
270             .flash_type = FLASH_TYPE_F0,
271             .flash_size_reg = 0x1ffff7cc,       // "Flash size data register" (pg735)
272             .flash_pagesize = 0x800,            // Page sizes listed in Table 4 (pg 56)
273             .sram_size = 0x8000,                // "SRAM" byte size in hex from Table 2 (pg 50)
274             .bootrom_base = 0x1fffd800,         // "System memory" starting address from Table 2
275             .bootrom_size = 0x2000              // "System memory" byte size in hex from Table 2
276         },
277         {
278             //Use this as an example for mapping future chips:
279             //RM0091 document was used to find these paramaters
280             .chip_id = STLINK_CHIPID_STM32_F04,
281             .description = "F04x device",
282             .flash_type = FLASH_TYPE_F0,
283             .flash_size_reg = 0x1ffff7cc,       // "Flash size data register" (pg735)
284             .flash_pagesize = 0x400,            // Page sizes listed in Table 4
285             .sram_size = 0x1800,                // "SRAM" byte size in hex from Table 2
286             .bootrom_base = 0x1fffec00,         // "System memory" starting address from Table 2
287             .bootrom_size = 0xC00               // "System memory" byte size in hex from Table 2
288         },
289         {
290             //Use this as an example for mapping future chips:
291             //RM0091 document was used to find these paramaters
292             .chip_id = STLINK_CHIPID_STM32_F0_SMALL,
293             .description = "F0 small device",
294             .flash_type = FLASH_TYPE_F0,
295             .flash_size_reg = 0x1ffff7cc,       // "Flash size data register" (pg735)
296             .flash_pagesize = 0x400,            // Page sizes listed in Table 4
297             .sram_size = 0x1000,                // "SRAM" byte size in hex from Table 2
298             .bootrom_base = 0x1fffec00,         // "System memory" starting address from Table 2
299             .bootrom_size = 0xC00               // "System memory" byte size in hex from Table 2
300         },
301         {
302             // STM32F30x
303             .chip_id = STLINK_CHIPID_STM32_F3_SMALL,
304             .description = "F3 small device",
305             .flash_type = FLASH_TYPE_F0,
306             .flash_size_reg = 0x1ffff7cc,
307             .flash_pagesize = 0x800,
308             .sram_size = 0xa000,
309             .bootrom_base = 0x1fffd800,
310             .bootrom_size = 0x2000
311         },
312         {
313             // STM32L0x
314             // RM0367,RM0377 documents was used to find these parameters
315             .chip_id = STLINK_CHIPID_STM32_L0,
316             .description = "L0x3 device",
317             .flash_type = FLASH_TYPE_L0,
318             .flash_size_reg = 0x1ff8007c,
319             .flash_pagesize = 0x80,
320             .sram_size = 0x2000,
321             .bootrom_base = 0x1ff0000,
322             .bootrom_size = 0x1000
323         },
324         {
325             // STM32L0x Category 5
326             // RM0367,RM0377 documents was used to find these parameters
327             .chip_id = STLINK_CHIPID_STM32_L0_CAT5,
328             .description = "L0x Category 5 device",
329             .flash_type = FLASH_TYPE_L0,
330             .flash_size_reg = 0x1ff8007c,
331             .flash_pagesize = 0x80,
332             .sram_size = 0x5000,
333             .bootrom_base = 0x1ff0000,
334             .bootrom_size = 0x2000
335         },
336         {
337             // STM32L0x Category 2
338             // RM0367,RM0377 documents was used to find these parameters
339             .chip_id = STLINK_CHIPID_STM32_L0_CAT2,
340             .description = "L0x Category 2 device",
341             .flash_type = FLASH_TYPE_L0,
342             .flash_size_reg = 0x1ff8007c,
343             .flash_pagesize = 0x80,
344             .sram_size = 0x2000,
345             .bootrom_base = 0x1ff0000,
346             .bootrom_size = 0x1000
347         },
348         {
349             // STM32F334
350             // RM0364 document was used to find these parameters
351             .chip_id = STLINK_CHIPID_STM32_F334,
352             .description = "F334 device",
353             .flash_type = FLASH_TYPE_F0,
354             .flash_size_reg = 0x1ffff7cc,
355             .flash_pagesize = 0x800,
356             .sram_size = 0x3000,
357             .bootrom_base = 0x1fffd800,
358             .bootrom_size = 0x2000
359         },
360         {
361             // This is STK32F303RET6 device from STM32 F3 Nucelo board.
362             // Support based on DM00043574.pdf (RM0316) document rev 5.
363             .chip_id = STLINK_CHIPID_STM32_F303_HIGH,
364             .description = "F303 high density device",
365             .flash_type = FLASH_TYPE_F0,
366             .flash_size_reg = 0x1ffff7cc,    // 34.2.1 Flash size data register
367             .flash_pagesize = 0x800,         // 4.2.1 Flash memory organization
368             .sram_size = 0x10000,            // 3.3 Embedded SRAM
369             .bootrom_base = 0x1fffd800,      // 3.3.2 / Table 4 System Memory
370             .bootrom_size = 0x2000
371         },
372         {
373             // STM32L4x6
374             // From RM0351.
375             .chip_id = STLINK_CHIPID_STM32_L4,
376             .description = "L4 device",
377             .flash_type = FLASH_TYPE_L4,
378             .flash_size_reg = 0x1fff75e0,    // "Flash size data register" (sec 45.2, page 1671)
379             .flash_pagesize = 0x800,         // 2K (sec 3.2, page 78; also appears in sec 3.3.1 and tables 4-6 on pages 79-81)
380             // SRAM1 is "up to" 96k in the standard Cortex-M memory map;
381             // SRAM2 is 32k mapped at at 0x10000000 (sec 2.3, page 73 for
382             // sizes; table 2, page 74 for SRAM2 location)
383             .sram_size = 0x18000,
384             .bootrom_base = 0x1fff0000,      // Tables 4-6, pages 80-81 (Bank 1 system memory)
385             .bootrom_size = 0x7000           // 28k (per bank), same source as base
386         },
387
388  };
389
390 const struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chipid)
391 {
392         struct stlink_chipid_params *params = NULL;
393
394         for (size_t n = 0; n < STLINK_ARRAY_SIZE(devices); n++) {
395                 if (devices[n].chip_id == chipid) {
396                         params = &devices[n];
397                         break;
398                 }
399         }
400
401         return params;
402 }