stm32: desig: refactor to allow targets to have different addresses
In this commit, support for the different base addresses for different F7 parts is added, but the mechanism is now in place for L1 and others. Reviewed-by: Karl Palsson <karlp@tweak.net.au> (whitespace fixed, commit msg reworded)
This commit is contained in:
committed by
Karl Palsson
parent
f1b4a4dfff
commit
97688b913e
@@ -19,50 +19,40 @@
|
||||
|
||||
#include <libopencm3/stm32/desig.h>
|
||||
|
||||
uint16_t desig_get_flash_size(void)
|
||||
{
|
||||
return DESIG_FLASH_SIZE;
|
||||
}
|
||||
|
||||
void desig_get_unique_id(uint32_t *result)
|
||||
{
|
||||
*result++ = DESIG_UNIQUE_ID2;
|
||||
*result++ = DESIG_UNIQUE_ID1;
|
||||
*result = DESIG_UNIQUE_ID0;
|
||||
}
|
||||
|
||||
void desig_get_unique_id_as_string(char *string,
|
||||
unsigned int string_len)
|
||||
void desig_get_unique_id_as_string(char *string, unsigned int string_len)
|
||||
{
|
||||
int i, len;
|
||||
uint32_t dev_id_buf[3];
|
||||
uint8_t *device_id = (uint8_t *)dev_id_buf;
|
||||
uint32_t uid_buf[3];
|
||||
uint8_t *uid = (uint8_t *)uid_buf;
|
||||
const char chars[] = "0123456789ABCDEF";
|
||||
|
||||
desig_get_unique_id(dev_id_buf);
|
||||
desig_get_unique_id(uid_buf);
|
||||
|
||||
/* Each byte produces two characters */
|
||||
len = (2 * sizeof(dev_id_buf) < string_len) ?
|
||||
2 * sizeof(dev_id_buf) : string_len - 1;
|
||||
len = (2 * sizeof(uid_buf) < string_len) ?
|
||||
2 * sizeof(uid_buf) : string_len - 1;
|
||||
|
||||
for (i = 0; i < len; i += 2) {
|
||||
string[i] = chars[(device_id[i / 2] >> 4) & 0x0F];
|
||||
string[i + 1] = chars[(device_id[i / 2] >> 0) & 0x0F];
|
||||
string[i] = chars[(uid[i / 2] >> 4) & 0x0F];
|
||||
string[i + 1] = chars[(uid[i / 2] >> 0) & 0x0F];
|
||||
}
|
||||
|
||||
string[len] = '\0';
|
||||
}
|
||||
|
||||
void desig_get_unique_id_as_dfu(char *string) {
|
||||
uint8_t *id = (uint8_t *)DESIG_UNIQUE_ID_BASE;
|
||||
uint32_t uid_buf[3];
|
||||
uint8_t *uid = (uint8_t *)uid_buf;
|
||||
|
||||
desig_get_unique_id(uid_buf);
|
||||
|
||||
uint8_t serial[6];
|
||||
serial[0] = id[11];
|
||||
serial[1] = id[10] + id[2];
|
||||
serial[2] = id[9];
|
||||
serial[3] = id[8] + id[0];
|
||||
serial[4] = id[7];
|
||||
serial[5] = id[6];
|
||||
serial[0] = uid[11];
|
||||
serial[1] = uid[10] + uid[2];
|
||||
serial[2] = uid[9];
|
||||
serial[3] = uid[8] + uid[0];
|
||||
serial[4] = uid[7];
|
||||
serial[5] = uid[6];
|
||||
|
||||
uint8_t *ser = &serial[0];
|
||||
uint8_t *end = &serial[6];
|
||||
32
lib/stm32/common/desig_common_v1.c
Normal file
32
lib/stm32/common/desig_common_v1.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2012 Karl Palsson <karlp@ŧweak.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/stm32/desig.h>
|
||||
|
||||
uint16_t desig_get_flash_size(void)
|
||||
{
|
||||
return *((uint32_t*)DESIG_FLASH_SIZE_BASE);
|
||||
}
|
||||
|
||||
void desig_get_unique_id(uint32_t *result)
|
||||
{
|
||||
*result++ = DESIG_UNIQUE_ID2;
|
||||
*result++ = DESIG_UNIQUE_ID1;
|
||||
*result = DESIG_UNIQUE_ID0;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ OBJS += comparator.o
|
||||
OBJS += crc_common_all.o crc_v2.o
|
||||
OBJS += crs_common_all.o
|
||||
OBJS += dac_common_all.o
|
||||
OBJS += desig.o
|
||||
OBJS += desig_common_all.o desig_common_v1.o
|
||||
OBJS += dma_common_l1f013.o dma_common_csel.o
|
||||
OBJS += exti_common_all.o
|
||||
OBJS += flash.o flash_common_all.o flash_common_f.o flash_common_f01.o
|
||||
|
||||
@@ -38,7 +38,7 @@ OBJS += adc.o adc_common_v1.o
|
||||
OBJS += can.o
|
||||
OBJS += crc_common_all.o
|
||||
OBJS += dac_common_all.o
|
||||
OBJS += desig.o
|
||||
OBJS += desig_common_all.o desig_common_v1.o
|
||||
OBJS += dma_common_l1f013.o
|
||||
OBJS += exti_common_all.o
|
||||
OBJS += flash.o flash_common_all.o flash_common_f.o flash_common_f01.o
|
||||
|
||||
@@ -97,7 +97,7 @@ It is locked by default on reset.
|
||||
|
||||
void flash_unlock_upper(void)
|
||||
{
|
||||
if (DESIG_FLASH_SIZE > 512) {
|
||||
if (desig_get_flash_size() > 512) {
|
||||
|
||||
/* Clear the unlock state. */
|
||||
FLASH_CR2 |= FLASH_CR_LOCK;
|
||||
@@ -126,7 +126,7 @@ void flash_lock_upper(void)
|
||||
|
||||
void flash_clear_pgerr_flag_upper(void)
|
||||
{
|
||||
if (DESIG_FLASH_SIZE > 512) {
|
||||
if (desig_get_flash_size() > 512) {
|
||||
FLASH_SR2 |= FLASH_SR_PGERR;
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ void flash_clear_pgerr_flag_upper(void)
|
||||
|
||||
void flash_clear_eop_flag_upper(void)
|
||||
{
|
||||
if (DESIG_FLASH_SIZE > 512) {
|
||||
if (desig_get_flash_size() > 512) {
|
||||
FLASH_SR2 |= FLASH_SR_EOP;
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ void flash_clear_eop_flag_upper(void)
|
||||
|
||||
void flash_clear_wrprterr_flag_upper(void)
|
||||
{
|
||||
if (DESIG_FLASH_SIZE > 512) {
|
||||
if (desig_get_flash_size() > 512) {
|
||||
FLASH_SR2 |= FLASH_SR_WRPRTERR;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ void flash_clear_status_flags(void)
|
||||
flash_clear_pgerr_flag();
|
||||
flash_clear_eop_flag();
|
||||
flash_clear_wrprterr_flag();
|
||||
if (DESIG_FLASH_SIZE > 512) {
|
||||
if (desig_get_flash_size() > 512) {
|
||||
flash_clear_pgerr_flag_upper();
|
||||
flash_clear_eop_flag_upper();
|
||||
flash_clear_wrprterr_flag_upper();
|
||||
@@ -192,7 +192,7 @@ uint32_t flash_get_status_flags(void)
|
||||
FLASH_SR_EOP |
|
||||
FLASH_SR_WRPRTERR |
|
||||
FLASH_SR_BSY));
|
||||
if (DESIG_FLASH_SIZE > 512) {
|
||||
if (desig_get_flash_size() > 512) {
|
||||
flags |= (FLASH_SR2 & (FLASH_SR_PGERR |
|
||||
FLASH_SR_EOP |
|
||||
FLASH_SR_WRPRTERR |
|
||||
@@ -219,7 +219,7 @@ void flash_program_half_word(uint32_t address, uint16_t data)
|
||||
{
|
||||
flash_wait_for_last_operation();
|
||||
|
||||
if ((DESIG_FLASH_SIZE > 512) && (address >= FLASH_BASE+0x00080000)) {
|
||||
if ((desig_get_flash_size() > 512) && (address >= FLASH_BASE+0x00080000)) {
|
||||
FLASH_CR2 |= FLASH_CR_PG;
|
||||
} else {
|
||||
FLASH_CR |= FLASH_CR_PG;
|
||||
@@ -229,7 +229,7 @@ void flash_program_half_word(uint32_t address, uint16_t data)
|
||||
|
||||
flash_wait_for_last_operation();
|
||||
|
||||
if ((DESIG_FLASH_SIZE > 512) && (address >= FLASH_BASE+0x00080000)) {
|
||||
if ((desig_get_flash_size() > 512) && (address >= FLASH_BASE+0x00080000)) {
|
||||
FLASH_CR2 &= ~FLASH_CR_PG;
|
||||
} else {
|
||||
FLASH_CR &= ~FLASH_CR_PG;
|
||||
@@ -253,7 +253,7 @@ void flash_erase_page(uint32_t page_address)
|
||||
{
|
||||
flash_wait_for_last_operation();
|
||||
|
||||
if ((DESIG_FLASH_SIZE > 512)
|
||||
if ((desig_get_flash_size() > 512)
|
||||
&& (page_address >= FLASH_BASE+0x00080000)) {
|
||||
FLASH_CR2 |= FLASH_CR_PER;
|
||||
FLASH_AR2 = page_address;
|
||||
@@ -266,7 +266,7 @@ void flash_erase_page(uint32_t page_address)
|
||||
|
||||
flash_wait_for_last_operation();
|
||||
|
||||
if ((DESIG_FLASH_SIZE > 512)
|
||||
if ((desig_get_flash_size() > 512)
|
||||
&& (page_address >= FLASH_BASE+0x00080000)) {
|
||||
FLASH_CR2 &= ~FLASH_CR_PER;
|
||||
} else {
|
||||
|
||||
@@ -37,7 +37,7 @@ ARFLAGS = rcs
|
||||
OBJS += crc_common_all.o
|
||||
OBJS += crypto_common_f24.o
|
||||
OBJS += dac_common_all.o
|
||||
OBJS += desig.o
|
||||
OBJS += desig_common_all.o desig_common_v1.o
|
||||
OBJS += dma_common_f24.o
|
||||
OBJS += exti_common_all.o
|
||||
OBJS += flash.o flash_common_all.o flash_common_f.o flash_common_f24.o flash_common_idcache.o
|
||||
|
||||
@@ -39,7 +39,7 @@ OBJS += adc.o adc_common_v2.o adc_common_v2_multi.o
|
||||
OBJS += can.o
|
||||
OBJS += crc_common_all.o crc_v2.o
|
||||
OBJS += dac_common_all.o
|
||||
OBJS += desig.o
|
||||
OBJS += desig_common_all.o desig_common_v1.o
|
||||
OBJS += dma_common_l1f013.o
|
||||
OBJS += exti_common_all.o
|
||||
OBJS += flash.o flash_common_all.o flash_common_f.o
|
||||
|
||||
@@ -42,7 +42,7 @@ OBJS += can.o
|
||||
OBJS += crc_common_all.o
|
||||
OBJS += crypto_common_f24.o crypto.o
|
||||
OBJS += dac_common_all.o
|
||||
OBJS += desig.o
|
||||
OBJS += desig_common_all.o desig_common_v1.o
|
||||
OBJS += dma_common_f24.o
|
||||
OBJS += dma2d_common_f47.o
|
||||
OBJS += dsi_common_f47.o
|
||||
|
||||
@@ -44,7 +44,7 @@ OBJS += adc_common_v1.o adc_common_v1_multi.o adc_common_f47.o
|
||||
OBJS += can.o
|
||||
OBJS += crc_common_all.o crc_v2.o
|
||||
OBJS += dac_common_all.o
|
||||
OBJS += desig.o
|
||||
OBJS += desig_common_all.o desig.o
|
||||
OBJS += dma_common_f24.o
|
||||
OBJS += dma2d_common_f47.o
|
||||
OBJS += dsi_common_f47.o
|
||||
|
||||
72
lib/stm32/f7/desig.c
Normal file
72
lib/stm32/f7/desig.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2019 Matthew Lai <m@matthewlai.ca>
|
||||
*
|
||||
* 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;
|
||||
uint32_t* flash_size_base = 0;
|
||||
switch (device_id) {
|
||||
case 0x0449:
|
||||
flash_size_base = (uint32_t*) DESIG_FLASH_SIZE_BASE_449;
|
||||
break;
|
||||
case 0x0451:
|
||||
flash_size_base = (uint32_t*) DESIG_FLASH_SIZE_BASE_451;
|
||||
break;
|
||||
case 0x0452:
|
||||
flash_size_base = (uint32_t*) DESIG_FLASH_SIZE_BASE_452;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!flash_size_base) {
|
||||
/* We don't know the address for this device. Hang here to help debugging. */
|
||||
cm3_assert_not_reached();
|
||||
}
|
||||
|
||||
return *flash_size_base;
|
||||
}
|
||||
|
||||
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 0x0449:
|
||||
uid_base = (uint32_t*) DESIG_UNIQUE_ID_BASE_449;
|
||||
break;
|
||||
case 0x0451:
|
||||
uid_base = (uint32_t*) DESIG_UNIQUE_ID_BASE_451;
|
||||
break;
|
||||
case 0x0452:
|
||||
uid_base = (uint32_t*) DESIG_UNIQUE_ID_BASE_452;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!uid_base) {
|
||||
/* We don't know the address for this device. Hang here to help debugging. */
|
||||
cm3_assert_not_reached();
|
||||
}
|
||||
|
||||
result[0] = uid_base[2];
|
||||
result[1] = uid_base[1];
|
||||
result[2] = uid_base[0];
|
||||
}
|
||||
@@ -37,7 +37,7 @@ ARFLAGS = rcs
|
||||
OBJS += adc_common_v2.o
|
||||
OBJS += crc_common_all.o crc_v2.o
|
||||
OBJS += crs_common_all.o
|
||||
OBJS += desig.o
|
||||
OBJS += desig_common_all.o desig_common_v1.o
|
||||
OBJS += dma_common_l1f013.o dma_common_csel.o
|
||||
OBJS += exti_common_all.o
|
||||
OBJS += flash_common_all.o flash_common_l01.o
|
||||
|
||||
@@ -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.o
|
||||
OBJS += desig_common_all.o desig_common_v1.o
|
||||
OBJS += dma_common_l1f013.o
|
||||
OBJS += exti_common_all.o
|
||||
OBJS += flash_common_all.o flash_common_l01.o
|
||||
|
||||
Reference in New Issue
Block a user