Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: AT32F43x cleanup #1996

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/target/at32f43x.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "stm32_common.h"

static bool at32f43_cmd_option(target_s *target, int argc, const char **argv);
static bool at32f43_cmd_uid(target_s *target, int argc, const char **argv);

const command_s at32f43_cmd_list[] = {
{"option", at32f43_cmd_option, "Manipulate option bytes"},
{"uid", at32f43_cmd_uid, "Print unique device ID"},
{NULL, NULL, NULL},
};

Expand Down Expand Up @@ -126,17 +129,18 @@ static bool at32f43_mass_erase(target_s *target);
#define AT32F423_SERIES_256KB 0x700a3000U
#define AT32F423_SERIES_128KB 0x700a2000U
#define AT32F423_SERIES_64KB 0x70032000U
#define AT32F4x_PROJECT_ID 0x1ffff7f3U
#define AT32F4x_FLASHSIZE 0x1ffff7e0U

#define AT32F4x_UID_BASE 0x1ffff7e8U
#define AT32F4x_PROJECT_ID 0x1ffff7f3U
#define AT32F4x_FLASHSIZE 0x1ffff7e0U

typedef struct at32f43_flash {
target_flash_s target_flash;
target_addr_t bank_split; /* Address of first page of bank 2 */
uint32_t bank_reg_offset; /* Flash register offset for this bank */
} at32f43_flash_s;

static void at32f43_add_flash(target_s *const target, const target_addr_t addr, const size_t length,
const size_t pagesize, const target_addr_t bank_split, const uint32_t bank_reg_offset)
const size_t pagesize, const uint32_t bank_reg_offset)
{
if (length == 0)
return;
Expand All @@ -157,7 +161,6 @@ static void at32f43_add_flash(target_s *const target, const target_addr_t addr,
target_flash->done = at32f43_flash_done;
target_flash->writesize = 1024U;
target_flash->erased = 0xffU;
flash->bank_split = bank_split;
flash->bank_reg_offset = bank_reg_offset;
target_add_flash(target, target_flash);
}
Expand Down Expand Up @@ -273,14 +276,10 @@ static bool at32f43_detect(target_s *target, const uint16_t part_id)
* Block erase operates on 64 KB at once for all parts.
* Using here only sector erase (page erase) for compatibility.
*/
if (flash_size_bank2 > 0) {
const uint32_t bank_split = 0x08000000 + flash_size_bank1;
at32f43_add_flash(
target, 0x08000000, flash_size_bank1, sector_size, bank_split, AT32F43x_FLASH_BANK1_REG_OFFSET);
at32f43_add_flash(target, 0x08000000, flash_size_bank1, sector_size, AT32F43x_FLASH_BANK1_REG_OFFSET);
if (flash_size_bank2 > 0)
at32f43_add_flash(
target, bank_split, flash_size_bank2, sector_size, bank_split, AT32F43x_FLASH_BANK2_REG_OFFSET);
} else
at32f43_add_flash(target, 0x08000000, flash_size_bank1, sector_size, 0, AT32F43x_FLASH_BANK1_REG_OFFSET);
target, 0x08000000 + flash_size_bank1, flash_size_bank2, sector_size, AT32F43x_FLASH_BANK2_REG_OFFSET);

// SRAM1 (64KB) can be remapped to 0x10000000.
target_add_ram32(target, 0x20000000, 64U * 1024U);
Expand Down Expand Up @@ -314,7 +313,7 @@ static bool at32f405_detect(target_s *target, const uint32_t series)
*/
const uint16_t flash_size = target_mem32_read16(target, AT32F4x_FLASHSIZE);
const uint16_t sector_size = series == AT32F405_SERIES_128KB ? 1024U : 2048U;
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, 0, AT32F43x_FLASH_BANK1_REG_OFFSET);
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, AT32F43x_FLASH_BANK1_REG_OFFSET);

/*
* Either 96 or 102 KiB of SRAM, depending on USD bit 7 nRAM_PRT_CHK:
Expand Down Expand Up @@ -346,7 +345,7 @@ static bool at32f423_detect(target_s *target, const uint32_t series)
*/
const uint16_t flash_size = target_mem32_read16(target, AT32F4x_FLASHSIZE);
const uint16_t sector_size = series == AT32F423_SERIES_256KB ? 2048U : 1024U;
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, 0, AT32F43x_FLASH_BANK1_REG_OFFSET);
at32f43_add_flash(target, 0x08000000, flash_size, sector_size, AT32F43x_FLASH_BANK1_REG_OFFSET);

target_add_ram32(target, 0x20000000, 48U * 1024U);
target->driver = "AT32F423";
Expand Down Expand Up @@ -548,8 +547,7 @@ static bool at32f43_mass_erase(target_s *target)
return false;

/* For dual-bank targets, mass erase bank 2 as well */
const at32f43_flash_s *const flash = (at32f43_flash_s *)target->flash;
if (flash->bank_split)
if (target->flash->next)
return at32f43_mass_erase_bank(target, AT32F43x_FLASH_BANK2_REG_OFFSET, &timeout);
return true;
}
Expand Down Expand Up @@ -715,3 +713,10 @@ static bool at32f43_cmd_option(target_s *target, int argc, const char **argv)

return true;
}

static bool at32f43_cmd_uid(target_s *target, int argc, const char **argv)
{
(void)argc;
(void)argv;
return stm32_uid(target, AT32F4x_UID_BASE);
}
2 changes: 1 addition & 1 deletion src/target/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ target_at32f4 = declare_dependency(
sources: files(
'at32f43x.c',
),
dependencies: target_cortexm,
dependencies: [target_cortexm, target_stm_common]
)

target_ti = declare_dependency(
Expand Down
Loading