From 00e23112c7fbc8c4262ffe62eeeebc4884702af8 Mon Sep 17 00:00:00 2001 From: ALTracer <11005378+ALTracer@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:17:51 +0300 Subject: [PATCH] at32f43x: Use a different ID on read-protected devices --- src/target/at32f43x.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/target/at32f43x.c b/src/target/at32f43x.c index a5a781eda1d..3b1fdc9c3c8 100644 --- a/src/target/at32f43x.c +++ b/src/target/at32f43x.c @@ -375,9 +375,15 @@ bool at32f43x_probe(target_s *target) const uint32_t series = idcode & AT32F4x_IDCODE_SERIES_MASK; const uint16_t part_id = idcode & AT32F4x_IDCODE_PART_MASK; // ... and highest byte of UID - const uint8_t project_id = target_mem32_read8(target, AT32F4x_PROJECT_ID); + const uint8_t uid_byte = target_mem32_read8(target, AT32F4x_PROJECT_ID); const uint32_t debug_ser_id = target_mem32_read32(target, AT32F43x_DBGMCU_SER_ID); + const uint32_t flash_usd = target_mem32_read32(target, AT32F43x_FLASH_USD); + const bool read_protected = (flash_usd & AT32F43x_FLASH_USD_RDP) == AT32F43x_FLASH_USD_RDP; + if (read_protected) + DEBUG_TARGET("%s: Flash Access Protection enabled, UID reads as 0x%02x\n", __func__, uid_byte); + const uint8_t project_id = !read_protected ? uid_byte : (debug_ser_id >> 8U) & 0xffU; + DEBUG_TARGET("%s: idcode = %08" PRIx32 ", project_id = %02x, debug_ser_id = %08" PRIx32 "\n", __func__, idcode, project_id, debug_ser_id);