Skip to content

Commit

Permalink
at32f43x: Use a different ID on read-protected devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Oct 24, 2024
1 parent 8c621c1 commit 00e2311
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/target/at32f43x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 00e2311

Please sign in to comment.