ch32f1: Fixed the probe routine distrubing state for other parts wrt `t->idcode`

The CH32F1 routine now reads the IDCode into a local.
If the part number matches and appears to be the chip (based on Flash locking), it only then writes the IDCode into `t->idcode`, which is at the point we can only `return true` from the probe routine anyway.
This commit is contained in:
dragonmux 2022-06-22 14:26:04 -04:00 committed by Piotr Esden-Tempski
parent 08a8988462
commit fbc87cc518
1 changed files with 3 additions and 3 deletions

View File

@ -157,9 +157,8 @@ static int ch32f1_flash_lock(target *t)
*/
bool ch32f1_probe(target *t)
{
t->idcode = target_mem_read32(t, DBGMCU_IDCODE) & 0xfff;
if ((t->cpuid & CPUID_PARTNO_MASK) != CORTEX_M3 || t->idcode != 0x410) // only ch32f103
const uint32_t idcode = target_mem_read32(t, DBGMCU_IDCODE) & 0xfff;
if ((t->cpuid & CPUID_PARTNO_MASK) != CORTEX_M3 || idcode != 0x410) // only ch32f103
return false;
// try to flock
@ -168,6 +167,7 @@ bool ch32f1_probe(target *t)
if (ch32f1_flash_unlock(t))
return false;
t->idcode = idcode;
uint32_t signature = target_mem_read32(t, FLASHSIZE);
uint32_t flashSize = signature & 0xFFFF;