HOWTO: Flashing with ST-Link v2

User avatar
ZooKeeper
Posts: 507
Joined: Mon Mar 30, 2020 10:23 pm
Location: USA

Re: HOWTO: Flashing with ST-Link v2

Post by ZooKeeper »

post deleted
Huebner VCU controlling a Gen2 Prius Inverter powering an MGR
"Talent is equally distributed but opportunity is not." - Leila Janah
User avatar
ZooKeeper
Posts: 507
Joined: Mon Mar 30, 2020 10:23 pm
Location: USA

Re: HOWTO: Flashing with ST-Link v2

Post by ZooKeeper »

post deleted
Huebner VCU controlling a Gen2 Prius Inverter powering an MGR
"Talent is equally distributed but opportunity is not." - Leila Janah
RetroZero
Posts: 702
Joined: Tue Oct 29, 2019 2:48 pm
Location: France
Has thanked: 311 times
Been thanked: 38 times
Contact:

Re: HOWTO: Flashing with ST-Link v2

Post by RetroZero »

Well, it seems I am in your shoes Damian.io. I think my STM is blocked too.
Since it's the new adapter board for Gen2 , it's not exactly like the V3 boards, but connection is similar.
Ground, 3.3V, SWCLK and SWDIO
I tried .hex and .bin files with ST Nucleo, but I keep getting error messages when comparing after programming.
In LiveUpdates, I notice CoreState Blocked/Halted
Being my 2nd board, I would like to get to the bottom of this and not "replace STM" via programming..
When I execute the programming sequence, the connection is interupted and requires Restart before being able to re-connect.
Any ideas?
User avatar
Kevin Sharpe
Posts: 1345
Joined: Fri Dec 14, 2018 9:24 pm
Location: Ireland and US
Been thanked: 4 times

Re: HOWTO: Flashing with ST-Link v2

Post by Kevin Sharpe »

RetroZero wrote: Tue Aug 25, 2020 7:53 am Any ideas?
Can I suggest you hire an electronics engineer for a few days? I don't want to minify your efforts but you seem to be stuck in a world of pain and maybe some expertise would help move your project forward?
This is a personal post and I disclaim all responsibility for any loss or damage which any person may suffer from reliance on the information and material in this post or any opinion, conclusion or recommendation in the information and material.
RetroZero
Posts: 702
Joined: Tue Oct 29, 2019 2:48 pm
Location: France
Has thanked: 311 times
Been thanked: 38 times
Contact:

Re: HOWTO: Flashing with ST-Link v2

Post by RetroZero »

Thanks Kevin, I didn't think it was this complicated. I had a motor spinning in manual mode before the very slippery slope downhill.
Might have to rethink my project..But will persist for now with trying to reprogramme the adapter board. Zookeeper is keeping the flame burning with his motor in FOC mode!!
I thought, 4 wires, a ST Link, how hard can it be?
User avatar
Bassmobile
Posts: 94
Joined: Sat Apr 25, 2020 5:51 am
Location: USA
Has thanked: 7 times

Re: HOWTO: Flashing with ST-Link v2 and OpenOCD (Open On-Chip Debugger)

Post by Bassmobile »

I find the most painless way to flash these boards is with an ST-LINK V2, and a few other open-source command line tools.
My personal preference is a macOS environment, but most any *nix / Linux distribution will work, even the Linux subsystem in Winblows will do.
First connect the hardware with 3.3v, GND, DIO and CLK to the appropriate 4 pins on on both your STLINK-v2 dongle and the V3 board.

On macOS, Homebrew is my package manager of choice. I will use it's `brew install` in the examples below for getting the software needed for the flashing procedures. All of these tools are available for other subsystems, this same processes will apply to many other GNU/Linux based systems such as Arch, Debian, etc.

The software I'm recommending you use is OpenOCD (Open On-Chip Debugger) and telnet. They need to be installed for this process.

Code: Select all

$ brew install openocd
$ brew install telnet  
or similar pattern

Code: Select all

`apt install`
on linux etc.

I make an alias `st-oocd` in my systems .profile for running the following command to make it quick and easier. The paths might differ slightly between different software system distributions, but it won't differ much!

Code: Select all

$ sudo /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg

you will be prompted for your password to perform the `sudo` operation

SUCCESS!

Code: Select all

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
  http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.225688
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections

Now OpenOCD has initiated a debug session to the STM32, leave this shell session running and in another shell session connect to the debug server with telnet

Code: Select all

$  telnet localhost 4444
OpenOCD will respond;

Code: Select all

Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
In the active telnet session issue this command

Code: Select all

> flash probe 0
If you have some blue-pill variant, or ??? may report back;

Code: Select all

device id = 0x20036410
STM32 flash size failed, probe inaccurate - assuming 128k flash
flash size = 128kbytes
Device Security Bit Set
flash 'stm32f1x' found at 0x08000000
In this case `Device Security Bit Set` requires the STM32 must first be unlocked to program. The device must be halted before you can issue the unlock commands, it is best to reset and immediatly halt the device, and OOCD supplies a simple way, issue the `reset halt` command over telnet:

Code: Select all

> reset halt

Code: Select all

target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
Now issue command;

Code: Select all

> stm32f1x unlock 0

Code: Select all

stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
So, we need to once again, soft reset and halt the stm32;

Code: Select all

> reset halt 
Now we you can continue programming! You will need to know the full pathname to the firmware files you wish to write.

Code: Select all

> flash write_image erase /path/to/files/stm32_loader.hex
> flash write_image /path/to/files/stm32_firmware.hex
Hex files include the offset address information.
Alternatively you may specify; to write with .bin binaries, but it will require that you include memory location offsets.

Code: Select all

> flash write_image erase /path/to/files/stm32_loader.bin 0x08000000 bin
> flash write_image /path/to/files/stm32_firmware.bin 0x08001000 bin
Keep in mind that you need to give specific paths to the firmware file(s).

We will issue on more soft reset;

Code: Select all

> reset 
At this point if all went well, we will see the 'ALIVE' led flashing it's little heartbeat.

Issue one last command over telnet to shutdown the connection.

Code: Select all

> shutdown 
8-)
toastednow
Posts: 4
Joined: Wed Jun 09, 2021 6:10 pm

Re: HOWTO: Flashing with ST-Link v2

Post by toastednow »

Hi! Latest mainboard has TC2030 programming interface and I bought TC2030-MCP-NL-10 for it but I am not sure about pinout for it. Could someone help me connect ST-link to it?
kay183
Posts: 8
Joined: Wed Sep 22, 2021 10:19 am

Re: HOWTO: Flashing with ST-Link v2

Post by kay183 »

Hi,the new boards use a new SWD connector. What type of connector should I use?
Attachments
IMG_20210215_212004.jpg
User avatar
EV_Builder
Posts: 1199
Joined: Tue Apr 28, 2020 3:50 pm
Location: The Netherlands
Has thanked: 16 times
Been thanked: 33 times
Contact:

Re: HOWTO: Flashing with ST-Link v2

Post by EV_Builder »

For the sake if it happens.
If you upload a empty project / overwrite the SWD pin config with something your chip/board can become in accesible.

To Solve:
- identify the reset pin on the device (chip)
- connect reset to GND
-Connect the ST-LINK and hit full erase in the application
- release the GND connection

The GUI will do a quick sweep and the chip is empty again.
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
chentron
Posts: 103
Joined: Mon Feb 22, 2021 3:25 pm
Location: Spain
Has thanked: 41 times
Been thanked: 4 times

Re: HOWTO: Flashing with ST-Link v2

Post by chentron »

flashed olimex from V2 board with android succesful with Zflash32 with arber instructions. Thanks
Post Reply