2024-12-28 01:39 AM
Hello ST Community,
I am working on a custom bootloader for the STM32G473CCU6 microcontroller to enable firmware updates via the USB DFU interface. I am using the STM32CubeProgrammer API v2.17.0 | Windows-64Bits.
The microcontroller has 256 KB of flash memory in dual banks, which is 128 sectors of 2 KB.
Flags: BFB2 = 0, DBANK = 1.
I need to erase sectors 1...125 and not erase sectors 0, 126, 127.
I am trying to do this with the following function:
int sectorErase(unsigned int sectors[],unsigned int sectorNbr, char* sFlashMemName = nullptr);
But only 64 sectors (0...63) from bank 1 can be erased. Sectors from bank 2 are not erased.
I tried using indexes (64...127) and (65280...65343)
DisplayCallbacks output when erasing sectors 1, 2:
Info: [INFO]: "\nFlash sector erase ... \n"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "Status: 0, State: 5"
Info: [UNKNOWN]: "sending a page erase request @: 0x08000800"
Info: [UNKNOWN]: "data: 4100080008"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 4 : dfuDNBUSY"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "erasing sector 0001 @: 0x08000800 done"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "Status: 0, State: 5"
Info: [UNKNOWN]: "sending a page erase request @: 0x08001000"
Info: [UNKNOWN]: "data: 4100100008"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 4 : dfuDNBUSY"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "erasing sector 0002 @: 0x08001000 done"
Info: [ERROR]: "Flash page/sector erase command correctly executed.\nNote: if flash sector is protected, it will not be erased."
DisplayCallbacks output when erasing sectors 64, 65:
Info: [INFO]: "\nFlash sector erase ... \n"
Info: [UNKNOWN]: "Error: Sector 0064 does not exist"
Info: [UNKNOWN]: "Error: Sector 0065 does not exist"
Info: [UNKNOWN]: "Error: No sectors selected to be erased"
DisplayCallbacks output when erasing sectors 65280, 65281
Info: [INFO]: "\nFlash sector erase ... \n"
Info: [INFO]: "sector 65280 does not exist"
Info: [INFO]: "sector 65281 does not exist"
Info: [ERROR]: "Flash page/sector erase command correctly executed.\nNote: if flash sector is protected, it will not be erased."
The output says that "erase command correctly executed", but in fact no sectors are erased.
Does anyone know how to erase sectors from bank 2 using STM32CubeProgrammer API function sectorErase()?
Thank you!
Solved! Go to Solution.
2025-01-02 02:11 AM
I tested it with STM32_Programmer_CLI v2.18.0 and it works correctly.
So, it was the v2.17.0 bug.
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin>STM32_Programmer_CLI.exe --connect port=USB1 -e 64
-------------------------------------------------------------------
STM32CubeProgrammer v2.18.0
-------------------------------------------------------------------
USB speed : Full Speed (12MBit/s)
Manuf. ID : STMicroelectronics
Product ID : DFU in FS Mode
SN : 207B336D5130
DFU protocol: 1.1
Board : --
Device ID : 0x0469
Device name : STM32G47x/G48x/G414
Flash size : 256 KBytes
Device type : MCU
Revision ID : --
Device CPU : Cortex-M4
Warning: Sector index for second bank in some DUAL bank devices can differ from Reference manual since the tool rely on unique index for sectors: second bank sectors increment starting from last index in bank 1
Erase sector(s) ...
Flash page/sector erase command correctly executed.
Note: if flash sector is protected, it will not be erased.
2025-01-02 12:36 AM
Hello @azaliya66
Could you test using STM32_Programmer_CLI instead of the API ? Can you erase in that case ?
If you attach the logs from this test using STM32CubeProgrammer v2.17.0 and v2.18.0 that could be helpful.
Also more importantly, are you able to erase using the system bootloader ?
Thanks,
Aziz
2025-01-02 01:48 AM
Hello Aziz,
I tested using STM32_Programmer_CLI instead of API.
It is possible to erase sectors above 64 using SWD interface and NOT possible using USB interface.
Below you will find the logs of erasing sectors 64 and 65280 using SWD interface and USB interface.
Thank you
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin>STM32_Programmer_CLI.exe --connect port=SWD -e 64
-------------------------------------------------------------------
STM32CubeProgrammer v2.17.0
-------------------------------------------------------------------
ST-LINK SN : 002400423433510737363934
ST-LINK FW : V3J15M6
Board : STLINK-V3MINIE
Voltage : 3.26V
SWD freq : 8000 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x469
Revision ID : Rev X
Device name : STM32G47x/G48x
Flash size : 256 KBytes
Device type : MCU
Device CPU : Cortex-M4
BL Version : 0xD5
Debug in Low Power mode enabled
Warning: If you are using [0->127]or[0->63]or[0->31] indexs of 512/256/128 KB flash size and DBANK=1 the existing specified sectors of Bank1 are erased, Protected sectors and [0->127]or[0->63]or[0->31] sectors of Bank2 are not erased .
For 512 KB flash size, to erase correctly sectors [0->127] of Bank 2 you must use [65280->65407].
For 256 KB flash size, to erase correctly sectors [0->63] of Bank 2 you must use [65280->65343].
For 128 KB flash size, to erase correctly sectors [0->31] of Bank 2 you must use [65280->65311].
Erase sector(s) ...
Error: Sector 0064 does not exist
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin>STM32_Programmer_CLI.exe --connect port=SWD -e 65280
-------------------------------------------------------------------
STM32CubeProgrammer v2.17.0
-------------------------------------------------------------------
ST-LINK SN : 002400423433510737363934
ST-LINK FW : V3J15M6
Board : STLINK-V3MINIE
Voltage : 3.26V
SWD freq : 8000 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x469
Revision ID : Rev X
Device name : STM32G47x/G48x
Flash size : 256 KBytes
Device type : MCU
Device CPU : Cortex-M4
BL Version : 0xD5
Debug in Low Power mode enabled
Warning: If you are using [0->127]or[0->63]or[0->31] indexs of 512/256/128 KB flash size and DBANK=1 the existing specified sectors of Bank1 are erased, Protected sectors and [0->127]or[0->63]or[0->31] sectors of Bank2 are not erased .
For 512 KB flash size, to erase correctly sectors [0->127] of Bank 2 you must use [65280->65407].
For 256 KB flash size, to erase correctly sectors [0->63] of Bank 2 you must use [65280->65343].
For 128 KB flash size, to erase correctly sectors [0->31] of Bank 2 you must use [65280->65311].
Erase sector(s) ...
Existing specified sectors are erased successfully
Protected sectors are not erased
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin>STM32_Programmer_CLI.exe --connect port=USB1 -e 65280
-------------------------------------------------------------------
STM32CubeProgrammer v2.17.0
-------------------------------------------------------------------
USB speed : Full Speed (12MBit/s)
Manuf. ID : STMicroelectronics
Product ID : DFU in FS Mode
SN : 207B336D5130
DFU protocol: 1.1
Board : --
Device ID : 0x0469
Device name : STM32G47x/G48x
Flash size : 512 KBytes (default)
Device type : MCU
Revision ID : --
Device CPU : Cortex-M4
Warning: If you are using [0->127]or[0->63]or[0->31] indexs of 512/256/128 KB flash size and DBANK=1 the existing specified sectors of Bank1 are erased, Protected sectors and [0->127]or[0->63]or[0->31] sectors of Bank2 are not erased .
For 512 KB flash size, to erase correctly sectors [0->127] of Bank 2 you must use [65280->65407].
For 256 KB flash size, to erase correctly sectors [0->63] of Bank 2 you must use [65280->65343].
For 128 KB flash size, to erase correctly sectors [0->31] of Bank 2 you must use [65280->65311].
Erase sector(s) ...
sector 65280 does not exist
Flash page/sector erase command correctly executed.
Note: if flash sector is protected, it will not be erased.
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin>STM32_Programmer_CLI.exe --connect port=USB1 -e 64
-------------------------------------------------------------------
STM32CubeProgrammer v2.17.0
-------------------------------------------------------------------
USB speed : Full Speed (12MBit/s)
Manuf. ID : STMicroelectronics
Product ID : DFU in FS Mode
SN : 207B336D5130
DFU protocol: 1.1
Board : --
Device ID : 0x0469
Device name : STM32G47x/G48x
Flash size : 512 KBytes (default)
Device type : MCU
Revision ID : --
Device CPU : Cortex-M4
Warning: If you are using [0->127]or[0->63]or[0->31] indexs of 512/256/128 KB flash size and DBANK=1 the existing specified sectors of Bank1 are erased, Protected sectors and [0->127]or[0->63]or[0->31] sectors of Bank2 are not erased .
For 512 KB flash size, to erase correctly sectors [0->127] of Bank 2 you must use [65280->65407].
For 256 KB flash size, to erase correctly sectors [0->63] of Bank 2 you must use [65280->65343].
For 128 KB flash size, to erase correctly sectors [0->31] of Bank 2 you must use [65280->65311].
Erase sector(s) ...
Error: Sector 0064 does not exist
2025-01-02 02:11 AM
I tested it with STM32_Programmer_CLI v2.18.0 and it works correctly.
So, it was the v2.17.0 bug.
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin>STM32_Programmer_CLI.exe --connect port=USB1 -e 64
-------------------------------------------------------------------
STM32CubeProgrammer v2.18.0
-------------------------------------------------------------------
USB speed : Full Speed (12MBit/s)
Manuf. ID : STMicroelectronics
Product ID : DFU in FS Mode
SN : 207B336D5130
DFU protocol: 1.1
Board : --
Device ID : 0x0469
Device name : STM32G47x/G48x/G414
Flash size : 256 KBytes
Device type : MCU
Revision ID : --
Device CPU : Cortex-M4
Warning: Sector index for second bank in some DUAL bank devices can differ from Reference manual since the tool rely on unique index for sectors: second bank sectors increment starting from last index in bank 1
Erase sector(s) ...
Flash page/sector erase command correctly executed.
Note: if flash sector is protected, it will not be erased.