Skip to content

Commit

Permalink
stm32f1: Add simplified probe for AT32F425 and part IDs for F423
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Sep 29, 2024
1 parent 9cfa5f3 commit 525eeef
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/target/stm32f1.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
#define AT32F40_SERIES 0x70050000U
#define AT32F421_SERIES_16KB 0x50010000U
#define AT32F421_SERIES 0x50020000U
#define AT32F425_SERIES 0x50092000U
#define AT32F423_SERIES_256KB 0x700a3000U
#define AT32F423_SERIES_128KB 0x700a2000U
#define AT32F423_SERIES_64KB 0x70032000U
#define AT32F405_SERIES 0x70053000U
#define AT32F402_SERIES 0x70042000U
#define AT32F4x_PROJECT_ID 0x1ffff7f3U
Expand Down Expand Up @@ -559,6 +563,20 @@ static bool at32f421_detect(target_s *target, const uint16_t part_id)
return stm32f1_configure_dbgmcu(target, STM32F1_DBGMCU_CONFIG);
}

static bool at32f425_detect(target_s *target, const uint16_t part_id)
{
const uint16_t flash_size = target_mem32_read16(target, AT32F4x_FLASHSIZE);
stm32f1_add_flash(target, 0x08000000, flash_size * 1024U, 1U * 1024U);
// All parts have 20 KiB SRAM
target_add_ram32(target, 0x20000000, 20U * 1024U);
target->driver = "AT32F425";
target->part_id = part_id;
target->target_options |= STM32F1_TOPT_32BIT_WRITES;
target->mass_erase = stm32f1_mass_erase;
// TODO: AT32F425 have 512 bytes of User System Data
return stm32f1_configure_dbgmcu(target, STM32F1_DBGMCU_CONFIG);
}

/* Identify AT32F40x "Mainstream" line devices (Cortex-M4) */
bool at32f40x_probe(target_s *target)
{
Expand All @@ -570,6 +588,7 @@ bool at32f40x_probe(target_s *target)
const uint32_t idcode = target_mem32_read32(target, STM32F1_DBGMCU_IDCODE);
const uint32_t series = idcode & AT32F4x_IDCODE_SERIES_MASK;
const uint16_t part_id = idcode & AT32F4x_IDCODE_PART_MASK;
// ... and first byte of UID
const uint32_t project_id = target_mem32_read8(target, AT32F4x_PROJECT_ID);

if (series == AT32F40_SERIES) {
Expand All @@ -587,6 +606,15 @@ bool at32f40x_probe(target_s *target)
// Value line
if ((series == AT32F421_SERIES || series == AT32F421_SERIES_16KB) && (project_id == 9U))
return at32f421_detect(target, part_id);

if (series == AT32F425_SERIES && project_id == 0x0fU)
return at32f425_detect(target, part_id);
if ((series == AT32F423_SERIES_256KB || series == AT32F423_SERIES_128KB || series == AT32F423_SERIES_64KB) &&
(project_id == 0x12U))
return false;
if ((series == AT32F405_SERIES && project_id == 0x13U) || (series == AT32F402_SERIES && project_id == 0x14U))
return false;

return false;
}

Expand Down

0 comments on commit 525eeef

Please sign in to comment.