libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
desig.c
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2020 Karl Palsson <karlp@tweak.net.au>
5 *
6 * This library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
23
25{
26 uint32_t v;
27 uint32_t device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK;
28 switch (device_id) {
29 case 0x416:
30 return *(uint32_t*)DESIG_FLASH_SIZE_BASE_CAT12;
31 case 0x429:
32 v = *(uint32_t*)DESIG_FLASH_SIZE_BASE_CAT12;
33 return v & 0xff;
34 case 0x427:
35 case 0x437:
36 return *(uint32_t*)DESIG_FLASH_SIZE_BASE_CAT3456;
37 case 0x436:
38 v = *(uint32_t*)DESIG_FLASH_SIZE_BASE_CAT3456;
39 return v ? 256 : 384;
40 }
41
43}
44
45void desig_get_unique_id(uint32_t *result)
46{
47 uint32_t device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK;
48 uint32_t* uid_base = 0;
49 switch (device_id) {
50 case 0x416:
51 case 0x429:
52 uid_base = (uint32_t*)DESIG_UNIQUE_ID_BASE_CAT12;
53 break;
54 case 0x427:
55 case 0x436:
56 case 0x437:
57 uid_base = (uint32_t*)DESIG_UNIQUE_ID_BASE_CAT3456;
58 break;
59 }
60
61 if (!uid_base) {
62 /* We don't know the address for this device. Hang here to help debugging. */
64 }
65
66 /* yes, careful with offsets here */
67 result[0] = uid_base[5];
68 result[1] = uid_base[1];
69 result[2] = uid_base[0];
70}
#define DBGMCU_IDCODE_DEV_ID_MASK
Definition: dbgmcu.h:37
#define DBGMCU_IDCODE
Definition: dbgmcu.h:29
void desig_get_unique_id(uint32_t *result)
Read the full 96 bit unique identifier Note: ST specifies that bits 31..16 are also reserved for futu...
Definition: desig.c:45
uint16_t desig_get_flash_size(void)
Read the on board flash size.
Definition: desig.c:24
#define cm3_assert_not_reached()
Check if unreachable code is reached.
Definition: assert.h:102
#define DESIG_UNIQUE_ID_BASE_CAT12
#define DESIG_FLASH_SIZE_BASE_CAT12
#define DESIG_FLASH_SIZE_BASE_CAT3456
#define DESIG_UNIQUE_ID_BASE_CAT3456