diff --git a/include/libopencm3/stm32/l1/memorymap.h b/include/libopencm3/stm32/l1/memorymap.h index 1b9cd10e..88974e2b 100644 --- a/include/libopencm3/stm32/l1/memorymap.h +++ b/include/libopencm3/stm32/l1/memorymap.h @@ -107,11 +107,10 @@ #define AES_BASE (PERIPH_BASE + 0x10000000) /* Device Electronic Signature */ -#define DESIG_FLASH_SIZE_BASE (INFO_BASE + 0x8004C) -#define DESIG_UNIQUE_ID_BASE (INFO_BASE + 0x80050) -#define DESIG_UNIQUE_ID0 MMIO32(DESIG_UNIQUE_ID_BASE) -#define DESIG_UNIQUE_ID1 MMIO32(DESIG_UNIQUE_ID_BASE + 4) -#define DESIG_UNIQUE_ID2 MMIO32(DESIG_UNIQUE_ID_BASE + 0x14) +#define DESIG_FLASH_SIZE_BASE_CAT12 (INFO_BASE + 0x8004C) +#define DESIG_FLASH_SIZE_BASE_CAT3456 (INFO_BASE + 0x800CC) +#define DESIG_UNIQUE_ID_BASE_CAT12 (INFO_BASE + 0x80050) +#define DESIG_UNIQUE_ID_BASE_CAT3456 (INFO_BASE + 0x800D0) /* ST provided factory calibration values @ 3.0V */ #define ST_VREFINT_CAL MMIO16(0x1FF80078) diff --git a/lib/stm32/l1/Makefile b/lib/stm32/l1/Makefile index 00d76fd2..6d616342 100644 --- a/lib/stm32/l1/Makefile +++ b/lib/stm32/l1/Makefile @@ -37,7 +37,7 @@ OBJS += adc.o adc_common_v1.o adc_common_v1_multi.o OBJS += flash.o OBJS += crc_common_all.o OBJS += dac_common_all.o -OBJS += desig_common_all.o desig_common_v1.o +OBJS += desig_common_all.o desig.o OBJS += dma_common_l1f013.o OBJS += exti_common_all.o OBJS += flash_common_all.o flash_common_l01.o diff --git a/lib/stm32/l1/desig.c b/lib/stm32/l1/desig.c new file mode 100644 index 00000000..0bdf98b4 --- /dev/null +++ b/lib/stm32/l1/desig.c @@ -0,0 +1,65 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2020 Karl Palsson + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include +#include +#include + +uint16_t desig_get_flash_size(void) +{ + uint32_t device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK; + switch (device_id) { + case 0x416: + case 0x429: + return *(uint32_t*)DESIG_FLASH_SIZE_BASE_CAT12; + case 0x427: + case 0x436: + case 0x437: + return *(uint32_t*)DESIG_FLASH_SIZE_BASE_CAT3456; + } + + cm3_assert_not_reached(); +} + +void desig_get_unique_id(uint32_t *result) +{ + uint32_t device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK; + uint32_t* uid_base = 0; + switch (device_id) { + case 0x416: + case 0x429: + uid_base = (uint32_t*)DESIG_UNIQUE_ID_BASE_CAT12; + break; + case 0x427: + case 0x436: + case 0x437: + uid_base = (uint32_t*)DESIG_UNIQUE_ID_BASE_CAT3456; + break; + } + + if (!uid_base) { + /* We don't know the address for this device. Hang here to help debugging. */ + cm3_assert_not_reached(); + } + + /* yes, careful with offsets here */ + result[0] = uid_base[5]; + result[1] = uid_base[1]; + result[2] = uid_base[0]; +}