diff options
author | Andreas Fritiofson <andreas.fritiofson@gmail.com> | 2013-07-09 21:49:07 +0200 |
---|---|---|
committer | Spencer Oliver <spen@spen-soft.co.uk> | 2013-07-15 09:55:49 +0000 |
commit | 0ce2ca748b502d09acf878c338fe23776cf6d8e2 (patch) | |
tree | 3e3cab66f62a0868f9add7909c4780be1b8bb264 /src/flash/nor/stm32f2x.c | |
parent | 3646e86c974948fdae4bd0771377e1910966bc8e (diff) |
flash/stm32*: Rewrite info functions
Factor out common bit masking and printing code and use intermediate
strings to avoid buffer size handling.
Change-Id: I7d8c12df11ade6cdca8c917b5524372daa498bf4
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1496
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src/flash/nor/stm32f2x.c')
-rw-r--r-- | src/flash/nor/stm32f2x.c | 92 |
1 files changed, 47 insertions, 45 deletions
diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c index 1922a8c9..0593bfdd 100644 --- a/src/flash/nor/stm32f2x.c +++ b/src/flash/nor/stm32f2x.c @@ -857,68 +857,70 @@ static int stm32x_auto_probe(struct flash_bank *bank) static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size) { - uint32_t device_id; - int printed; + uint32_t dbgmcu_idcode; /* read stm32 device id register */ - int retval = stm32x_get_device_id(bank, &device_id); + int retval = stm32x_get_device_id(bank, &dbgmcu_idcode); if (retval != ERROR_OK) return retval; - if ((device_id & 0xfff) == 0x411) { - printed = snprintf(buf, buf_size, "stm32f2x - 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 0x411: + device_str = "stm32f2x"; - case 0x2000: - snprintf(buf, buf_size, "B"); - break; + switch (rev_id) { + case 0x1000: + rev_str = "A"; + break; - case 0x1001: - snprintf(buf, buf_size, "Z"); - break; + case 0x2000: + rev_str = "B"; + break; - case 0x2001: - snprintf(buf, buf_size, "Y"); - break; + case 0x1001: + rev_str = "Z"; + break; - case 0x2003: - snprintf(buf, buf_size, "X"); - break; + case 0x2001: + rev_str = "Y"; + break; - default: - snprintf(buf, buf_size, "unknown"); - break; + case 0x2003: + rev_str = "X"; + break; } - } else if (((device_id & 0xfff) == 0x413) || - ((device_id & 0xfff) == 0x419)) { - printed = snprintf(buf, buf_size, "stm32f4x - Rev: "); - buf += printed; - buf_size -= printed; - - switch (device_id >> 16) { - case 0x1000: - snprintf(buf, buf_size, "A"); - break; - - case 0x1001: - snprintf(buf, buf_size, "Z"); - break; - - default: - snprintf(buf, buf_size, "unknown"); - break; + break; + + case 0x413: + case 0x419: + device_str = "stm32f4x"; + + switch (rev_id) { + case 0x1000: + rev_str = "A"; + break; + + case 0x1001: + rev_str = "Z"; + break; } - } else { + break; + + default: snprintf(buf, buf_size, "Cannot identify target as a stm32x\n"); 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; } |