stm32l1: desig: use new mechanism to support different densities

Fixes: https://github.com/libopencm3/libopencm3/issues/234

uses the new mechanisms introduced to address a similar problem on F7.

Tested on a medium density part (0x429) that returns the same ids as
before, tested on a high density part that now _doesnt_, but that's now
correct :)
This commit is contained in:
Karl Palsson 2020-03-04 22:32:58 +00:00
parent 78c23ba5a0
commit 4a11e354a3
3 changed files with 70 additions and 6 deletions

View File

@ -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)

View File

@ -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

65
lib/stm32/l1/desig.c Normal file
View File

@ -0,0 +1,65 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2020 Karl Palsson <karlp@tweak.net.au>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/cm3/assert.h>
#include <libopencm3/stm32/dbgmcu.h>
#include <libopencm3/stm32/desig.h>
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];
}