altos/stm: Figure out available flash space based on chip id registers
authorKeith Packard <keithp@keithp.com>
Tue, 13 May 2014 05:55:38 +0000 (22:55 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 13 May 2014 05:55:38 +0000 (22:55 -0700)
Look at the flash size and the device id registers to figure out how
much flash is available.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/stm/ao_interrupt.c
src/stm/registers.ld
src/stm/stm32l.h

index 969e6a0f7b6a23a7433785f114c76765005509bb..56cce0c02ff90af23fac42ee05af44783b59626c 100644 (file)
@@ -39,6 +39,38 @@ void stm_ignore_isr(void)
 
 const void *stm_interrupt_vector[];
 
 
 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
 void start(void)
 {
 #ifdef AO_BOOT_CHAIN
index 8318c75a87a6330634b08ec6c3a71a5d3e778e97..d40fd90f1e04f3339e55a1a89d1db2f377e3dfb5 100644 (file)
@@ -52,5 +52,10 @@ stm_scb    = 0xe000ed00;
 
 stm_mpu    = 0xe000ed90;
 
 
 stm_mpu    = 0xe000ed90;
 
+stm_dbg_mcu = 0xe0042000;
+
 /* calibration data in system memory */
 stm_temp_cal = 0x1ff80078;
 /* calibration data in system memory */
 stm_temp_cal = 0x1ff80078;
+stm_flash_size_medium = 0x1ff8004c;
+stm_flash_size_large = 0x1ff800cc;
+stm_device_id = 0x1ff80050;
index 302f4d2451bf6fd762a544b257ab38cc0c93b7df..9226e9cb0f39a4ea6d1ffc27986000ce94a5100a 100644 (file)
@@ -1492,6 +1492,36 @@ extern struct stm_temp_cal       stm_temp_cal;
 #define stm_temp_cal_cold      25
 #define stm_temp_cal_hot       110
 
 #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)
 #define STM_NUM_I2C    2
 
 #define STM_I2C_INDEX(channel) ((channel) - 1)