Skip to main content
DAlbe.3
Associate III
June 17, 2023
Question

STM32CubeProgrammer 2.13.0 miscalculates flash sectors to erase

  • June 17, 2023
  • 8 replies
  • 3884 views

When loading a .hex file into flash, the STM32CubeProgrammer (v 2.13.0) miscalculates which sectors to erase and as a result, the download often fails unless the region being loaded has been previously erased or happens to contain the same values.

For example (see attached image), when loading an image that is 0x23B74 bytes (142.86KB) bytes to address 0x08004000 in an STM32L471 (256 x 2K sectors), it erases sectors 4..39. 

The start sector for address 0x08004000 should be 8 (8 x 2048 = 0x4000) and the end sector (0x08004000+0x23B74=0x08027B74) should be 0x4F (79 decimal)

stm32cubeprogrammer_erase_error.jpg

If I'm doing something wrong, suggestions would be appreciated!

This topic has been closed for replies.

8 replies

Tesla DeLorean
Guru
July 11, 2023

Check https://community.st.com/t5/stm32cubeprogrammer-mcu/stm32cubeprogrammer-2-14-0-released/td-p/573439

If still an issue, will flag for additional review / analysis

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
DAlbe.3
DAlbe.3Author
Associate III
July 17, 2023

Unfortunately, no change with 2.14.0.  It recognizes the device type (it is an STM32L471 - see below) but is not calculating sectors properly (the STM32L471 uses 2K sectors).  So loading a file to 0x08004000 (16K offset into flash) should start at sector 8, not 4.

DAlbe3_0-1689623507793.png

DAlbe3_1-1689623533110.png

From the reference manual (RM0351):
The Flash memory is divided in two banks. Each bank is organized as follows:
• A main memory block containing 256 pages of 2 Kbyte. Each page is made of 8 rows of
256 bytes.

DAlbe.3
DAlbe.3Author
Associate III
July 17, 2023

It's pretty clear that the STM32CubeProgrammer simply isn't correctly recognizing the flash layout of the STM32L471.  It clearly thinks it has 4K sectors.  Any chance we can get a beta fix for this?

DAlbe3_0-1689624664599.png

 

Tesla DeLorean
Guru
July 17, 2023

@Imen.D @Nawres GHARBI Please add this to the open issues list if not already on there.

We also really need to fix the user finding tool on the forum, 5 names, no scrolling / no employee filtering ?? You've got a forum with ~62K users

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Pavel A.
Super User
July 18, 2023

@Tesla DeLorean you have disabled sending private messages in your profile. Is this intentional?

ST Employee
July 18, 2023

Hello @DAlbe.3 ,

Thanks for your feedback,

This issue is under investigation, I will get back to you with more details as soon as possible.

Sara.

DAlbe.3
DAlbe.3Author
Associate III
July 19, 2023

In case it helps, this problem seems to be specific to the STM32L471.  I have some early prototypes that use the STM32L476 and the sectors are calculated correctly for them.

DAlbe.3
DAlbe.3Author
Associate III
July 18, 2023

Thank you Sara! 
I am hoping (and expect) that it is just a wrong sector size entry in a table that maps processor ID to flash layout.

ST Employee
July 26, 2023

Hello @DAlbe.3 ,

Sorry for the late reply,

After further investigation, we figured that the erase is not working properly on this device. This led to a failure during the download. The sector size issue is also confirmed.

These issues are reported to the development team and will be fixed in the upcoming release. I'll keep you posted.

Internal ticket number: 157508 (This is an internal tracking number and is not accessible or usable by customers).

Thanks for your contribution,

Sara.

DAlbe.3
DAlbe.3Author
Associate III
July 26, 2023

Thank you Sara.

It may be stating the obvious, but the bug is in STM32_Prog_DB_0x415.xml.  In my case, I am using the 512K single bank configuration so line 148 should read:
<Parameters address="0x08000000" name="sector0" occurrence="0x100" size="0x800"/>

For anyone else with this issue who needs a fix before the next update, replacing line 148 in the above-mentioned file does indeed fix the problem.  For windows users, the file is in C:/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/Data_Base

Senior III
July 27, 2023

Good find !! Thanks !

Explorer
July 26, 2023

I'm experiencing the same issue. Will downgrading the STM32CubeProgrammer work or is it also in prior versions?

Associate III
July 27, 2023

I think I'm experiencing a similar issue with an NUCLEO-WB15CC. Also can't flash two seperate programs without erasing flash first. I also get these "Data mismatch" errors all the time..

I am running STM32CubeProgrammer v2.14.0 but also tested with v2.8.0 and 2.8.10, where I experienced the same issues.

DAlbe.3
DAlbe.3Author
Associate III
July 27, 2023

Hi tester, that board uses an STM32WB55RG processor with 1MB Flash; it is handled by the database file STM32_Prog_DB_0x495.xml and the Embedded Flash description looks correct there:
<Parameters address="0x08000000" name="sector0" occurrence="0x100" size="0x1000"/>
Since that part has 4KB sectors.

I believe it is a single-bank only part (i.e. you can't split Flash into two 512K segments).  Can you share specifically how you are loading the programs?  Are you loading one program and then trying to overwrite it with the next and getting errors?  On the Erasing & Programming page, is "Skip flash erase before programming checked"?

Associate III
July 27, 2023

I am pretty sure the NUCLEO-WB15CC uses an STM32WB15CC, with 320kB Flash, right? At least thats the target information I'm getting. So it should be ID 0x494. That's what's currently in that line: 

 

<Parameters address="0x08000000" name="sector0" occurrence="0xA0" size="0x800"/>

 

But I am unsure what to change here.

I am currently trying to load the OTA application and my "user application" separately and everytime I uploaded my code from the CudeIDE, the OTA Applicaiton was overriden, eventhough I changed the linker script. The OTA application should only be flashed from 0x08000000 to 0x08007000 and the user application starting from 0x08007000, right?

My solution for right now is using a powershell script with STM32_Programmer_CLI which erases flash, and then flashes the user code first and finally the OTA application