From 530894f508874f4cb3db644ca9ca679ed704f964 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 12 May 2014 22:55:38 -0700 Subject: [PATCH] altos/stm: Figure out available flash space based on chip id registers Look at the flash size and the device id registers to figure out how much flash is available. Signed-off-by: Keith Packard --- src/stm/ao_interrupt.c | 32 ++++++++++++++++++++++++++++++++ src/stm/registers.ld | 5 +++++ src/stm/stm32l.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/src/stm/ao_interrupt.c b/src/stm/ao_interrupt.c index 969e6a0f..56cce0c0 100644 --- a/src/stm/ao_interrupt.c +++ b/src/stm/ao_interrupt.c @@ -39,6 +39,38 @@ void stm_ignore_isr(void) const void *stm_interrupt_vector[]; +uint32_t +stm_flash_size(void) { + uint16_t dev_id = stm_dev_id(); + uint16_t kbytes = 0; + + switch (dev_id) { + case 0x416: /* cat 1 */ + kbytes = stm_flash_size_medium.f_size; + break; + case 0x429: /* cat 2 */ + kbytes = stm_flash_size_medium.f_size & 0xff; + break; + case 0x427: /* cat 3 */ + kbytes = stm_flash_size_large.f_size; + break; + case 0x436: /* cat 4 */ + switch (stm_flash_size_large.f_size) { + case 0: + kbytes = 256; + break; + case 1: + kbytes = 384; + break; + } + break; + case 0x437: /* cat 5 */ + kbytes = stm_flash_size_large.f_size; + break; + } + return (uint32_t) kbytes * 1024; +} + void start(void) { #ifdef AO_BOOT_CHAIN diff --git a/src/stm/registers.ld b/src/stm/registers.ld index 8318c75a..d40fd90f 100644 --- a/src/stm/registers.ld +++ b/src/stm/registers.ld @@ -52,5 +52,10 @@ stm_scb = 0xe000ed00; stm_mpu = 0xe000ed90; +stm_dbg_mcu = 0xe0042000; + /* calibration data in system memory */ stm_temp_cal = 0x1ff80078; +stm_flash_size_medium = 0x1ff8004c; +stm_flash_size_large = 0x1ff800cc; +stm_device_id = 0x1ff80050; diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h index 302f4d24..9226e9cb 100644 --- a/src/stm/stm32l.h +++ b/src/stm/stm32l.h @@ -1492,6 +1492,36 @@ extern struct stm_temp_cal stm_temp_cal; #define stm_temp_cal_cold 25 #define stm_temp_cal_hot 110 +struct stm_dbg_mcu { + uint32_t idcode; +}; + +extern struct stm_dbg_mcu stm_dbg_mcu; + +static inline uint16_t +stm_dev_id(void) { + return stm_dbg_mcu.idcode & 0xfff; +} + +struct stm_flash_size { + uint16_t f_size; +}; + +extern struct stm_flash_size stm_flash_size_medium; +extern struct stm_flash_size stm_flash_size_large; + +/* Returns flash size in bytes */ +extern uint32_t +stm_flash_size(void); + +struct stm_device_id { + uint32_t u_id0; + uint32_t u_id1; + uint32_t u_id2; +}; + +extern struct stm_device_id stm_device_id; + #define STM_NUM_I2C 2 #define STM_I2C_INDEX(channel) ((channel) - 1) -- 2.30.2