Skip to content

Commit 509d60e

Browse files
Merge pull request #1355 from marcelobarrosufu/develop
Fixed support for STM32U5 chips.
2 parents e212349 + ed558c9 commit 509d60e

File tree

6 files changed

+58
-9
lines changed

6 files changed

+58
-9
lines changed

config/chips/U535_U545.chip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Chip-ID file for STM32U535 / STM32U545 device
2+
#
3+
dev_type STM32U535_U545
4+
ref_manual_id 0456
5+
chip_id 0x455 // STM32U535/545
6+
flash_type L5_U5_H5
7+
flash_size_reg 0x0bfa07a0
8+
flash_pagesize 0x2000 // 8 KB
9+
sram_size 0x44800 // 274 KB
10+
bootrom_base 0x0bf90000
11+
bootrom_size 0x8000 // 32 KB
12+
option_base 0x0
13+
option_size 0x0
14+
flags swo dualbank

config/chips/U55Fx_U5Gx.chip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Chip-ID file for STM32U5Fx / STM32U5Gx device
2+
#
3+
dev_type STM32U5Fx_U5Gx
4+
ref_manual_id 0456
5+
chip_id 0x476 // STM32U5Fx5/5Gx
6+
flash_type L5_U5_H5
7+
flash_size_reg 0x0bfa07a0
8+
flash_pagesize 0x2000 // 8 KB
9+
sram_size 0x2f4800 // 3026 KB
10+
bootrom_base 0x0bf90000
11+
bootrom_size 0x8000 // 32 KB
12+
option_base 0x0
13+
option_size 0x0
14+
flags swo dualbank
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Chip-ID file for STM32U5x5 device
1+
# Chip-ID file for STM32U575 / STM32U585 device
22
#
3-
dev_type STM32U5x5
3+
dev_type STM32U575_U585
44
ref_manual_id 0456
5-
chip_id 0x482 // STM32_CHIPID_U5x5
5+
chip_id 0x482 // STM32U575/585
66
flash_type L5_U5_H5
77
flash_size_reg 0x0bfa07a0
88
flash_pagesize 0x2000 // 8 KB
@@ -11,4 +11,4 @@ bootrom_base 0x0bf90000
1111
bootrom_size 0x10000 // 64 KB
1212
option_base 0x0
1313
option_size 0x0
14-
flags none
14+
flags swo dualbank

config/chips/U59x_U5Ax.chip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Chip-ID file for STM32U59x / STM32U5Ax device
2+
#
3+
dev_type STM32U59x_U5Ax
4+
ref_manual_id 0456
5+
chip_id 0x481 // STM32U59x/5Ax
6+
flash_type L5_U5_H5
7+
flash_size_reg 0x0bfa07a0
8+
flash_pagesize 0x2000 // 8 KB
9+
sram_size 0x274800 // 2514 KB
10+
bootrom_base 0x0bf90000
11+
bootrom_size 0x8000 // 32 KB
12+
option_base 0x0
13+
option_size 0x0
14+
flags swo dualbank

inc/stm32.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ enum stm32_chipids {
114114
STM32_CHIPID_F76xxx = 0x451,
115115
STM32_CHIPID_F72xxx = 0x452, /* Nucleo F722ZE board */
116116
STM32_CHIPID_C031xx = 0x453, /* RM0490 (revision 3), section 26.10.1 "DBG device ID code register (DBG_IDCODE)" */
117+
STM32_CHIPID_U535_U545 = 0x455, /* RM0456, p.3604 */
117118
STM32_CHIPID_G0_CAT4 = 0x456, /* G051/G061 */
118119
STM32_CHIPID_L0_CAT1 = 0x457,
119120
STM32_CHIPID_F410 = 0x458,
@@ -129,9 +130,11 @@ enum stm32_chipids {
129130
STM32_CHIPID_L4Rx = 0x470, /* RM0432, p.2247, found on the STM32L4R9I-DISCO board */
130131
STM32_CHIPID_L4PX = 0x471, /* RM0432, p.2247 */
131132
STM32_CHIPID_L5x2xx = 0x472, /* RM0438, p.2157 */
133+
STM32_CHIPID_U5Fx_U5Gx = 0x476, /* RM0456, p.3604 */
132134
STM32_CHIPID_G4_CAT4 = 0x479,
133135
STM32_CHIPID_H7Ax = 0x480, /* RM0455, p.2863 */
134-
STM32_CHIPID_U5x5 = 0x482, /* RM0456, p.2991 */
136+
STM32_CHIPID_U59x_U5Ax = 0x481, /* RM0456, p.3604 */
137+
STM32_CHIPID_U575_U585 = 0x482, /* RM0456, p.3604 */
135138
STM32_CHIPID_H72x = 0x483, /* RM0468, p.3199 */
136139
STM32_CHIPID_H5xx = 0x484, /* RM0481, p.3085 */
137140
STM32_CHIPID_WB55 = 0x495,

src/stlink-lib/common_flash.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,10 +1132,12 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
11321132
val &= ~(0x7F << 3);
11331133
val |= ((flash_page & 0x7F) << 3) | (1 << FLASH_CR_PER);
11341134
stlink_write_debug32(sl, FLASH_Gx_CR, val);
1135+
// STM32L5x2xx has two banks with 2k pages or single with 4k pages
1136+
// STM32H5xx, STM32U535, STM32U545, STM32U575 or STM32U585 have 2 banks with 8k pages
11351137
} else if (sl->flash_type == STM32_FLASH_TYPE_L5_U5_H5) {
11361138
uint32_t flash_page;
11371139
stlink_read_debug32(sl, FLASH_L5_NSCR, &val);
1138-
if (sl->flash_pgsz == 0x800 && (flashaddr - STM32_FLASH_BASE) >= sl->flash_size/2) {
1140+
if ((sl->flash_pgsz == 0x800 || sl->flash_pgsz == 0x2000) && (flashaddr - STM32_FLASH_BASE) >= sl->flash_size/2) {
11391141
flash_page = (flashaddr - STM32_FLASH_BASE - sl->flash_size/2) / sl->flash_pgsz;
11401142
// set bank 2 for erasure
11411143
val |= (1 << FLASH_L5_NSCR_NSBKER);
@@ -1144,9 +1146,11 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
11441146
// set bank 1 for erasure
11451147
val &= ~(1 << FLASH_L5_NSCR_NSBKER);
11461148
}
1147-
// sec 6.9.9
1148-
val &= ~(0x7F << 3);
1149-
val |= ((flash_page & 0x7F) << 3) | (1 << FLASH_CR_PER);
1149+
// sec 7.9.9 for U5, 6.9.9 for L5 (for L7 we have 7 bits instead 8 bits for U5 but
1150+
// the bit position for 8th bit reserved.
1151+
// Maybe the best solution is to handle each one separately.
1152+
val &= ~(0xFF << 3);
1153+
val |= ((flash_page & 0xFF) << 3) | (1 << FLASH_CR_PER);
11501154
stlink_write_debug32(sl, FLASH_L5_NSCR, val);
11511155
} else if (sl->flash_type == STM32_FLASH_TYPE_WB_WL) {
11521156
uint32_t flash_page = ((flashaddr - STM32_FLASH_BASE) / sl->flash_pgsz);

0 commit comments

Comments
 (0)