Skip to content

Commit

Permalink
stm32f1: Add detection by part IDs for AT32F421
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Nov 9, 2024
1 parent dd9dca1 commit a274cc2
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/target/stm32f1.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
#define AT32F4x_IDCODE_PART_MASK 0x00000fffU
#define AT32F41_SERIES 0x70030000U
#define AT32F40_SERIES 0x70050000U
#define AT32F421_SERIES_16KB 0x50010000U
#define AT32F421_SERIES 0x50020000U
#define AT32F4x_PROJECT_ID 0x1ffff7f3U

#define STM32F1_OB_COUNT 8U
Expand Down Expand Up @@ -557,6 +559,58 @@ static bool at32f413_detect(target_s *target, const uint16_t part_id)
return stm32f1_configure_dbgmcu(target, STM32F1_DBGMCU_CONFIG);
}

static bool at32f421_detect(target_s *target, const uint16_t part_id)
{
// Extra part: AT32F4212C8T7 with dual Op-Amp? (16/64, LQFP48)
switch (part_id) {
case 0x0100U: // AT32F421C8T7 / LQFP48
case 0x0101U: // AT32F421K8T7 / LQFP32
case 0x0102U: // AT32F421K8U7 / QFN32_5x5
case 0x0103U: // AT32F421K8U7-4 / QFN32_4x4
case 0x0104U: // AT32F421F8U7 / QFN20
case 0x0105U: // AT32F421F8P7 / TSSOP20
case 0x0112U: // AT32F421G8U7 / QFN28
case 0x0115U: // AT32F421PF8P7 / TSSOP20 (AN0016)
// Flash (8): 64 KiB / 1 KiB per block
stm32f1_add_flash(target, 0x08000000, 64U * 1024U, 1U * 1024U);
target_add_ram32(target, 0x20000000, 16U * 1024U);
break;
case 0x0086U: // LQFP48
case 0x0087U: // LQFP32
case 0x0088U: // QFN32_5x5
case 0x0089U: // QFN32_4x4
case 0x008aU: // QFN20
case 0x008bU: // TSSOP20
case 0x0093U: // QFN28
// Flash (6): 32 KiB / 1 KiB per block
stm32f1_add_flash(target, 0x08000000, 32U * 1024U, 1U * 1024U);
target_add_ram32(target, 0x20000000, 16U * 1024U);
break;
case 0x000cU: // LQFP48
case 0x000dU: // LQFP32
case 0x000eU: // QFN32_5x5
case 0x000fU: // QFN32_4x4
case 0x0010U: // QFN20
case 0x0011U: // AT32F421F4P7 / TSSOP20
case 0x0014U: // QFN28
case 0x0016U: // AT32F421PF4P7 / TSSOP20 (AN0016)
// Flash (4): 16 KiB / 1 KiB per block
stm32f1_add_flash(target, 0x08000000, 16U * 1024U, 1U * 1024U);
target_add_ram32(target, 0x20000000, 8U * 1024U);
break;
// Unknown/undocumented
default:
return false;
}

target->driver = "AT32F421";
target->part_id = part_id;
target->target_options |= STM32F1_TOPT_32BIT_WRITES;
target->mass_erase = stm32f1_mass_erase;
// TODO: AT32F421 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 Down Expand Up @@ -595,6 +649,13 @@ bool at32f40x_probe(target_s *target)
if (project_id == 0xffU)
return false;
}
/* Value line. 0x09: F421 (Basic) */
if (series == AT32F421_SERIES || series == AT32F421_SERIES_16KB) {
if (project_id == 9U)
return at32f421_detect(target, part_id);
if (project_id == 0xffU)
return false;
}

return false;
}
Expand Down

0 comments on commit a274cc2

Please sign in to comment.