cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 DFU and STM32CubeProgrammer - Problem to load a new program - Not Erase memory

GAJOBAR
Associate II

Hello!


I'm trying to use a firmware DFU with the STM32F407 and Emulated EEPROM to change into DFU / App or App / DFU. The DFU address is in 0x08000000, the Emulated EEPROM address is in 0x08008000 and the Application address, on 0x0800C000.

 

All this steps works fine, the DFU connect with USB to the STM32CubeProgrammer and I can load a first code. Then it jump right to the Application, run it good, and I can go back to the DFU without problems. The problems comes when a trying to load another program after the first load previously.

 

I could find in the code of DFU, the function MEM_If_Erase_HS is never called so, it can't load a new program. The other functions, some are called like MEM_If_Write_HS (because load the first time the program) and MEM_If_Read_HS (because the verification is right). So, I don't understand or I can't find why is not called the function to erase the memory and program another code.

On the STM32CubeProgrammer, I have the error menssage:

12:10:04 : Memory Programming ...
12:10:04 : Opening and parsing file: Main_QB_STM_DFUFreeRTOS.bin
12:10:04 : File : Main_QB_STM_DFUFreeRTOS.bin
12:10:04 : Size : 39.74 KB
12:10:04 : Address : 0x0800C000
12:10:04 : Erasing memory corresponding to segment 0:
12:10:04 : Error: failed to erase memory

 

Has anyone had this or a similar problem to help me?

19 REPLIES 19
AScha.3
Chief

Hi,

maybe you (your cpu) have some write protection on , check in  STM32CubeProgrammer :

AScha3_0-1714925116568.png

 

Check: erase is on:

AScha3_1-1714925285512.png

 

And try full chip erase , if still wrong.

If you feel a post has answered your question, please click "Accept as Solution".

Hi AScha.3

The first option, where I an find? The second option, I using in that way and I can found de error with that option. When I debug the code, it's never call the function MEM_If_Erase_HS so, it can't write the new code because it need all memory erased.

Sorry, i dont understand now. 

Your problem found/solved ? Then mark solution.

If you do something with write protection, its another question (i assume : Emulated EEPROM is doing something..)

But if you program with CubeProgrammer , you can set/reset flash (as i do also); whats wrong then ?

If you feel a post has answered your question, please click "Accept as Solution".

No, is not solved.

The memory don't have the write protection, because I can write one program. When a go to write again or another program with the DFU, I have this messages on STM32CubeProgrammer:

 

12:10:04 : Memory Programming ...
12:10:04 : Opening and parsing file: Main_QB_STM_DFUFreeRTOS.bin
12:10:04 : File : Main_QB_STM_DFUFreeRTOS.bin
12:10:04 : Size : 39.74 KB
12:10:04 : Address : 0x0800C000
12:10:04 : Erasing memory corresponding to segment 0:
12:10:04 : Error: failed to erase memory

 

OK, now, when a try to debug I found the reason why don't let me write again (or at least I think so). The DFU never call the function MEM_If_Erase_HS even though the STM32CubeProgrammer tells you to do it. So, I don't know what to do or how I can find the reason about call this function (the memory need to be erased to write a neew program), without forcing it in the code.

So when using the "usual" way, program-compile-debug in IDE , its working as it should ?

+

If connecting in CubeProgrammer with st-link and download program - also ?

If you feel a post has answered your question, please click "Accept as Solution".

Yes, all that work fine and I use the ST-LINK v2. But the problem is when I use the DFU firmware, connecting my board with the USB and the STM32CubeProgrammer.

The problem is in some place when it must to call the function MEM_If_Erase_HS in the DFU, but I don't know why, because the other functions work fine. The DFU code is not my code, is code of STM.

Ahh, ok.

So make a new program (to check, whats wrong):

in IDE -> new stm32 project (for your cpu type) -> set clock tree, debug and systick , and pin with LED (if you have);

generate code, compile, debug : should work.

Then mod something, set LED toggle and HAL delay in main; compile...and try to load with the bootloader + CubeProgrammer (DFU).

Working ?

If you feel a post has answered your question, please click "Accept as Solution".

That works too. The problem es when I need to re-program with the DFU. The first program work fine, the second program, fail. The memory is not erased.

>That works too. 

What now?  New mini-test-program can be loaded with DFU mode ?

And then load this program  again with DFU mode - works or not ?

If you feel a post has answered your question, please click "Accept as Solution".