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) 2019 Matthew Lai <m@matthewlai.ca>
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 device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK;
27 uint32_t* flash_size_base = 0;
28 switch (device_id) {
29 case 0x0449:
30 flash_size_base = (uint32_t*) DESIG_FLASH_SIZE_BASE_449;
31 break;
32 case 0x0451:
33 flash_size_base = (uint32_t*) DESIG_FLASH_SIZE_BASE_451;
34 break;
35 case 0x0452:
36 flash_size_base = (uint32_t*) DESIG_FLASH_SIZE_BASE_452;
37 break;
38 }
39
40 if (!flash_size_base) {
41 /* We don't know the address for this device. Hang here to help debugging. */
43 }
44
45 return *flash_size_base;
46}
47
48void desig_get_unique_id(uint32_t *result)
49{
50 uint32_t device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK;
51 uint32_t* uid_base = 0;
52 switch (device_id) {
53 case 0x0449:
54 uid_base = (uint32_t*) DESIG_UNIQUE_ID_BASE_449;
55 break;
56 case 0x0451:
57 uid_base = (uint32_t*) DESIG_UNIQUE_ID_BASE_451;
58 break;
59 case 0x0452:
60 uid_base = (uint32_t*) DESIG_UNIQUE_ID_BASE_452;
61 break;
62 }
63
64 if (!uid_base) {
65 /* We don't know the address for this device. Hang here to help debugging. */
67 }
68
69 result[0] = uid_base[2];
70 result[1] = uid_base[1];
71 result[2] = uid_base[0];
72}
#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:48
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_FLASH_SIZE_BASE_449
#define DESIG_FLASH_SIZE_BASE_452
#define DESIG_UNIQUE_ID_BASE_452
#define DESIG_UNIQUE_ID_BASE_451
#define DESIG_FLASH_SIZE_BASE_451
#define DESIG_UNIQUE_ID_BASE_449