STM32F407VGT6 programming issues

Post here first, or if you can't find a relevant section!
Post Reply
dekip
Posts: 4
Joined: Wed Apr 06, 2022 5:32 pm

STM32F407VGT6 programming issues

Post by dekip »

I have a problem programming the MCU from the title.

I tried to find a solution here (https://github.com/orgs/stm32duino/discussions/2302), but no luck.

The thing is, I can not upload a sketch using Arduino IDE.

UART adapter
While using the UART adapter I can not upload a sketch as it says it is not in a bootloader mode. The same goes when I try to connect to the MCU over the STM32CubeProgrammer.

SWD adapter
While using the SWD, I can not upload. I get this error:
Erasing memory corresponding to segment 0:
Erasing internal memory sector 0
Error: failed to erase memory


Error: failed to erase memory
Error: failed to erase memory

I can connect MCU to the STM32CubeProgrammer using SWD. RDP option byte is set to AA. I tried to erase the chip and got the message that the flash was protected. The core is locked up.

However, while using MikroElektronika's CodeGrip and Necto Studio I can upload whatever I want. I can use CodeGrip Suite to detect the chip, erase the flash, and upload the HEX file. Moreover, I can upload a HEX file compiled by the Arduino IDE.

Weird.

So the question is, what can I do to unlock the MCU, so I can use it with ArduinoIDE? I am all ears.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32F407VGT6 programming issues

Post by ag123 »

one thing to try is to press and hold reset when you flash the sketch over st-link, this is called 'connect under reset'. If the tool chain is properly installed, sometimes that will override the write protection.

flash a simple sketch such as to blink the led, so that you know if after all it is working.
dekip
Posts: 4
Joined: Wed Apr 06, 2022 5:32 pm

Re: STM32F407VGT6 programming issues

Post by dekip »

Tried to hold on reset

Arduino IDE

ST-LINK SN : 48FF6F064982565039210787
ST-LINK FW : V2J38S7
Board : --
Voltage : 3.25V
Error: ST-LINK error (DEV_TARGET_HELD_UNDER_RESET)
Error: ST-LINK error (DEV_TARGET_HELD_UNDER_RESET)

STM32CubeProgrammer - tried to upload precompiled HEX

09:11:19 : Memory Programming ...
09:11:19 : Opening and parsing file: Blink.ino.hex
09:11:19 : File : Blink.ino.hex
09:11:19 : Size : 13.58 KB
09:11:19 : Address : 0x08000000
09:11:19 : Erasing memory corresponding to segment 0:
09:11:19 : Erasing internal memory sector 0
09:11:21 : Error: failed to erase memory
09:11:21 : Error: failed to erase memory
09:11:21 : RUNNING Program ...
09:11:21 : Address: : 0x08000000
09:11:23 : Warning: failed to run application!
09:11:23 : Warning: The core is kept under Reset!
09:11:23 : Error: Start operation failed

BTW, the CodeGrip settings are:
Connection: Under reset
Reset Type: System reset
Speed: 4MHz
Halt on Connect: Enabled
And it works
dekip
Posts: 4
Joined: Wed Apr 06, 2022 5:32 pm

Re: STM32F407VGT6 programming issues

Post by dekip »

UPDATE!

I tried several times to change RDP to BB and back to AA, and today after several tries I made it. But even with this, it is the same. I can not upload a sketch over the Arduino IDE, I can not upload HEX over the STM32CubeProgrammer, but I can by using MikroE tools.

This is all new to me and makes me leave STM32 for good. I don't have time to chase ghosts.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32F407VGT6 programming issues

Post by ag123 »

I found this article from a google search
https://community.st.com/t5/stm32-mcus- ... d-p/257858
If i set the ST-LINK configuration to:

Mode: Normal
Reset Mode: Software Reset
Then, I can successfully connect if I:

Press and hold the reset button on the board
Click the Connect button in the cube programmer
Release the reset button
there are apparently some settings to be done (in stm32cubeprogrammer) if you are connecting under reset

in openocd, this extra configuration is needed

Code: Select all

# use hardware reset, connect under reset
reset_config srst_only srst_nogate
ref: https://forum.sparkfun.com/viewtopic.php?t=35249

hence, it may be necessary to set the same thing in stm32cubeprogrammer if you are connecting under reset.
The only purpose of that is to override the write protection. If the chip is not write protected, this isn't necessary.
All it takes is simply program away normally.

one should also check not to enable write protect flags in the programmer configs when flashing firmware.
if the chip is write protected, then you need all these special procedures to override that.
Post Reply

Return to “General discussion”