Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit bcdaa30

Browse files
committed
at32f43x: Drop bank_split field
* This value was only used to detect second bank in _mass_erase * Target Flash API already guarantees no cross-bank ops * Rely on non-null flash->next instead
1 parent 50140ef commit bcdaa30

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

src/target/at32f43x.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,11 @@ static bool at32f43_mass_erase(target_s *target);
131131

132132
typedef struct at32f43_flash {
133133
target_flash_s target_flash;
134-
target_addr_t bank_split; /* Address of first page of bank 2 */
135134
uint32_t bank_reg_offset; /* Flash register offset for this bank */
136135
} at32f43_flash_s;
137136

138137
static void at32f43_add_flash(target_s *const target, const target_addr_t addr, const size_t length,
139-
const size_t pagesize, const target_addr_t bank_split, const uint32_t bank_reg_offset)
138+
const size_t pagesize, const uint32_t bank_reg_offset)
140139
{
141140
if (length == 0)
142141
return;
@@ -157,7 +156,6 @@ static void at32f43_add_flash(target_s *const target, const target_addr_t addr,
157156
target_flash->done = at32f43_flash_done;
158157
target_flash->writesize = 1024U;
159158
target_flash->erased = 0xffU;
160-
flash->bank_split = bank_split;
161159
flash->bank_reg_offset = bank_reg_offset;
162160
target_add_flash(target, target_flash);
163161
}
@@ -273,14 +271,10 @@ static bool at32f43_detect(target_s *target, const uint16_t part_id)
273271
* Block erase operates on 64 KB at once for all parts.
274272
* Using here only sector erase (page erase) for compatibility.
275273
*/
276-
if (flash_size_bank2 > 0) {
277-
const uint32_t bank_split = 0x08000000 + flash_size_bank1;
274+
at32f43_add_flash(target, 0x08000000, flash_size_bank1, sector_size, AT32F43x_FLASH_BANK1_REG_OFFSET);
275+
if (flash_size_bank2 > 0)
278276
at32f43_add_flash(
279-
target, 0x08000000, flash_size_bank1, sector_size, bank_split, AT32F43x_FLASH_BANK1_REG_OFFSET);
280-
at32f43_add_flash(
281-
target, bank_split, flash_size_bank2, sector_size, bank_split, AT32F43x_FLASH_BANK2_REG_OFFSET);
282-
} else
283-
at32f43_add_flash(target, 0x08000000, flash_size_bank1, sector_size, 0, AT32F43x_FLASH_BANK1_REG_OFFSET);
277+
target, 0x08000000 + flash_size_bank1, flash_size_bank2, sector_size, AT32F43x_FLASH_BANK2_REG_OFFSET);
284278

285279
// SRAM1 (64KB) can be remapped to 0x10000000.
286280
target_add_ram32(target, 0x20000000, 64U * 1024U);
@@ -314,7 +308,7 @@ static bool at32f405_detect(target_s *target, const uint32_t series)
314308
*/
315309
const uint16_t flash_size = target_mem32_read16(target, AT32F4x_FLASHSIZE);
316310
const uint16_t sector_size = series == AT32F405_SERIES_128KB ? 1024U : 2048U;
317-
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, 0, AT32F43x_FLASH_BANK1_REG_OFFSET);
311+
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, AT32F43x_FLASH_BANK1_REG_OFFSET);
318312

319313
/*
320314
* Either 96 or 102 KiB of SRAM, depending on USD bit 7 nRAM_PRT_CHK:
@@ -346,7 +340,7 @@ static bool at32f423_detect(target_s *target, const uint32_t series)
346340
*/
347341
const uint16_t flash_size = target_mem32_read16(target, AT32F4x_FLASHSIZE);
348342
const uint16_t sector_size = series == AT32F423_SERIES_256KB ? 2048U : 1024U;
349-
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, 0, AT32F43x_FLASH_BANK1_REG_OFFSET);
343+
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, AT32F43x_FLASH_BANK1_REG_OFFSET);
350344

351345
target_add_ram32(target, 0x20000000, 48U * 1024U);
352346
target->driver = "AT32F423";
@@ -548,8 +542,7 @@ static bool at32f43_mass_erase(target_s *target)
548542
return false;
549543

550544
/* For dual-bank targets, mass erase bank 2 as well */
551-
const at32f43_flash_s *const flash = (at32f43_flash_s *)target->flash;
552-
if (flash->bank_split)
545+
if (target->flash->next)
553546
return at32f43_mass_erase_bank(target, AT32F43x_FLASH_BANK2_REG_OFFSET, &timeout);
554547
return true;
555548
}

0 commit comments

Comments
 (0)