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

Only do bank calculation on STM32L4 devices with dual banked flash / Added chip ID 0x464 for STM32L41xxx/L42xxx devices #751

Merged
merged 2 commits into from
Dec 14, 2018
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
2 changes: 2 additions & 0 deletions include/stlink/chipid.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ enum stlink_stm32_chipids {
* 0x435 covers STM32L43xxx and STM32L44xxx devices
* 0x461 covers STM32L496xx and STM32L4A6xx devices
* 0x462 covers STM32L45xxx and STM32L46xxx devices
* 0x464 covers STM32L41xxx and STM32L42xxx devices
*/
STLINK_CHIPID_STM32_L43X = 0x435,
STLINK_CHIPID_STM32_L496X = 0x461,
STLINK_CHIPID_STM32_L46X = 0x462,
STLINK_CHIPID_STM32_L41X = 0x464,
/*
* 0x436 is actually assigned to some L1 chips that are called "Medium-Plus"
* and some that are called "High". 0x427 is assigned to the other "Medium-
Expand Down
16 changes: 11 additions & 5 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,13 +1436,19 @@ uint32_t calculate_L4_page(stlink_t *sl, uint32_t flashaddr) {
uint32_t flashopt;
stlink_read_debug32(sl, STM32L4_FLASH_OPTR, &flashopt);
flashaddr -= STM32_FLASH_BASE;
if (flashopt & (1lu << STM32L4_FLASH_OPTR_DUALBANK)) {
uint32_t banksize = (uint32_t) sl->flash_size / 2;
if (flashaddr >= banksize) {
flashaddr -= banksize;
bker = 0x100;
if (sl->chip_id == STLINK_CHIPID_STM32_L4 ||
sl->chip_id == STLINK_CHIPID_STM32_L496X ||
sl->chip_id == STLINK_CHIPID_STM32_L4RX) {
// This chip use dual banked flash
if (flashopt & (1lu << STM32L4_FLASH_OPTR_DUALBANK)) {
uint32_t banksize = (uint32_t) sl->flash_size / 2;
if (flashaddr >= banksize) {
flashaddr -= banksize;
bker = 0x100;
}
}
}

// For 1MB chips without the dual-bank option set, the page address will
// overflow into the BKER bit, which gives us the correct bank:page value.
return bker | flashaddr/sl->flash_pgsz;
Expand Down