From 101821ae318597d934fe5f9b8723d032f05a5a5b Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Sun, 12 Jul 2015 17:30:18 +0100 Subject: [Bugfix] stm32f1_probe would always return true, breaking support for all other targets The intention of `if (t->driver)` conditional was to test if any of the cases in the preceeding switch/case were met. However t->driver was previously set to point to a default value in cortexm.c:200 and therefore this would always evaluate to true. I've replaced the broken if statement with a duplicate of the switch/case run above. It looks like this was introduced in 09544bc7101981f2688e0a678138dc4580ea3f76 (PR #92) but 492d6c9cf8f735eea5478c99aee43608549218d7 maybe contributes to the confusion in this instance. --- src/stm32f1.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stm32f1.c b/src/stm32f1.c index fecebdf..f8a2d94 100644 --- a/src/stm32f1.c +++ b/src/stm32f1.c @@ -162,7 +162,12 @@ bool stm32f1_probe(target *t) block_size = 0x800; break; } - if (t->driver) { + switch(t->idcode) { + case 0x444: /* STM32F03 RM0091 Rev.7 */ + case 0x445: /* STM32F04 RM0091 Rev.7 */ + case 0x440: /* STM32F05 RM0091 Rev.7 */ + case 0x448: /* STM32F07 RM0091 Rev.7 */ + case 0x442: /* STM32F09 RM0091 Rev.7 */ flash_size = (target_mem_read32(t, FLASHSIZE_F0) & 0xffff) *0x400; gdb_outf("flash size %d block_size %d\n", flash_size, block_size); target_add_ram(t, 0x20000000, 0x5000); @@ -353,4 +358,3 @@ static bool stm32f1_cmd_option(target *t, int argc, char *argv[]) } return true; } - -- cgit v1.2.3 From beacf9c85c5707d20465a5e1c5a8b55bd77914dd Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Thu, 30 Jul 2015 07:58:55 +0100 Subject: Refactor stm32f1_probe --- src/stm32f1.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/stm32f1.c b/src/stm32f1.c index f8a2d94..68d4b51 100644 --- a/src/stm32f1.c +++ b/src/stm32f1.c @@ -161,22 +161,16 @@ bool stm32f1_probe(target *t) t->driver = "STM32F09"; block_size = 0x800; break; - } - switch(t->idcode) { - case 0x444: /* STM32F03 RM0091 Rev.7 */ - case 0x445: /* STM32F04 RM0091 Rev.7 */ - case 0x440: /* STM32F05 RM0091 Rev.7 */ - case 0x448: /* STM32F07 RM0091 Rev.7 */ - case 0x442: /* STM32F09 RM0091 Rev.7 */ - flash_size = (target_mem_read32(t, FLASHSIZE_F0) & 0xffff) *0x400; - gdb_outf("flash size %d block_size %d\n", flash_size, block_size); - target_add_ram(t, 0x20000000, 0x5000); - stm32f1_add_flash(t, 0x8000000, flash_size, block_size); - target_add_commands(t, stm32f1_cmd_list, "STM32F0"); - return true; + default: /* NONE */ + return false; } - return false; + flash_size = (target_mem_read32(t, FLASHSIZE_F0) & 0xffff) *0x400; + gdb_outf("flash size %d block_size %d\n", flash_size, block_size); + target_add_ram(t, 0x20000000, 0x5000); + stm32f1_add_flash(t, 0x8000000, flash_size, block_size); + target_add_commands(t, stm32f1_cmd_list, "STM32F0"); + return true; } static void stm32f1_flash_unlock(target *t) -- cgit v1.2.3