X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fstm32lx.c;h=70414cdcde504205973cae9e96fab7e05cd52f72;hp=ec696d2b376a1314be506dc64fc5a66612412c27;hb=8f444e22473746710112b68eb4d923ce2f45040d;hpb=3646e86c974948fdae4bd0771377e1910966bc8e diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c index ec696d2b37..70414cdcde 100644 --- a/src/flash/nor/stm32lx.c +++ b/src/flash/nor/stm32lx.c @@ -88,6 +88,7 @@ /* other registers */ #define DBGMCU_IDCODE 0xE0042000 #define F_SIZE 0x1FF8004C +#define F_SIZE_MP 0x1FF800CC /* on 0x427 Medium+ and 0x436 HD devices */ /* Constants */ #define FLASH_PAGE_SIZE 256 @@ -554,8 +555,23 @@ static int stm32lx_probe(struct flash_bank *bank) return ERROR_FAIL; } - /* Get the flash size from target. */ - retval = target_read_u16(target, F_SIZE, &flash_size_in_kb); + /* Get the flash size from target. 0x427 and 0x436 devices use a + * different location for the Flash Size register, please see RM0038 r8 or + * newer. */ + if ((device_id & 0xfff) == 0x427 || (device_id & 0xfff) == 0x436) + retval = target_read_u16(target, F_SIZE_MP, &flash_size_in_kb); + else + retval = target_read_u16(target, F_SIZE, &flash_size_in_kb); + + /* 0x436 devices report their flash size as a 0 or 1 code indicating 384K + * or 256K, respectively. Please see RM0038 r8 or newer and refer to + * section 30.1.1. */ + if (retval == ERROR_OK && (device_id & 0xfff) == 0x436) { + if (flash_size_in_kb == 0) + flash_size_in_kb = 384; + else if (flash_size_in_kb == 1) + flash_size_in_kb = 256; + } /* Failed reading flash size or flash size invalid (early silicon), * default to max target family */ @@ -695,73 +711,83 @@ static int stm32lx_get_info(struct flash_bank *bank, char *buf, int buf_size) { /* This method must return a string displaying information about the bank */ - struct target *target = bank->target; - uint32_t device_id; - int printed; + uint32_t dbgmcu_idcode; /* read stm32 device id register */ - int retval = target_read_u32(target, DBGMCU_IDCODE, &device_id); + int retval = target_read_u32(bank->target, DBGMCU_IDCODE, &dbgmcu_idcode); if (retval != ERROR_OK) return retval; - if ((device_id & 0xfff) == 0x416) { - printed = snprintf(buf, buf_size, "stm32lx - Rev: "); - buf += printed; - buf_size -= printed; + uint16_t device_id = dbgmcu_idcode & 0xfff; + uint16_t rev_id = dbgmcu_idcode >> 16; + const char *device_str; + const char *rev_str = NULL; - switch (device_id >> 16) { - case 0x1000: - snprintf(buf, buf_size, "A"); - break; + switch (device_id) { + case 0x416: + device_str = "STM32L1xx (Low/Medium Density)"; - case 0x1008: - snprintf(buf, buf_size, "Y"); - break; + switch (rev_id) { + case 0x1000: + rev_str = "A"; + break; - case 0x1018: - snprintf(buf, buf_size, "X"); - break; + case 0x1008: + rev_str = "Y"; + break; - case 0x1038: - snprintf(buf, buf_size, "W"); - break; + case 0x1018: + rev_str = "X"; + break; - case 0x1078: - snprintf(buf, buf_size, "V"); - break; + case 0x1038: + rev_str = "W"; + break; - default: - snprintf(buf, buf_size, "unknown"); - break; + case 0x1078: + rev_str = "V"; + break; } - } else if (((device_id & 0xfff) == 0x436) || - ((device_id & 0xfff) == 0x427)) { - printed = snprintf(buf, buf_size, "stm32lx (HD) - Rev: "); - buf += printed; - buf_size -= printed; - - switch (device_id >> 16) { - case 0x1000: - snprintf(buf, buf_size, "A"); - break; + break; - case 0x1008: - snprintf(buf, buf_size, "Z"); - break; + case 0x427: + device_str = "STM32L1xx (Medium+ Density)"; - case 0x1018: - snprintf(buf, buf_size, "Y"); - break; + switch (rev_id) { + case 0x1018: + rev_str = "A"; + break; + } + break; - default: - snprintf(buf, buf_size, "unknown"); - break; + case 0x436: + device_str = "STM32L1xx (Medium+/High Density)"; + + switch (rev_id) { + case 0x1000: + rev_str = "A"; + break; + + case 0x1008: + rev_str = "Z"; + break; + + case 0x1018: + rev_str = "Y"; + break; } - } else { - snprintf(buf, buf_size, "Cannot identify target as a stm32lx"); + break; + + default: + snprintf(buf, buf_size, "Cannot identify target as a STM32L1"); return ERROR_FAIL; } + if (rev_str != NULL) + snprintf(buf, buf_size, "%s - Rev: %s", device_str, rev_str); + else + snprintf(buf, buf_size, "%s - Rev: unknown (0x%04x)", device_str, rev_id); + return ERROR_OK; }