jsnyder / stm32loader

Python script to load firmware using STM32 bootloader
324 stars 238 forks source link

Unable to load firmware to Blue Pill. #18

Open fadedbee opened 4 years ago

fadedbee commented 4 years ago

I'm following the instructions on https://medium.com/@paramaggarwal/converting-an-stm32f103-board-to-a-black-magic-probe-c013cf2cc38c to use stm32loader to flash the blackmagic firmware onto Blue Pill boards.

I have tried four separate boards, ordered on two different occasions.

The error I get is most often:

fadedbee@cyan:~/blackmagic/src$ python ../../stm32loader/stm32loader.py -p /dev/ttyUSB0 -e -w -v blackmagic_dfu.bin
Bootloader version 22
Chip id: 0x410 (STM32 Medium-density)
Write 256 bytes at 0x8000000
Write 256 bytes at 0x8000100
Write 256 bytes at 0x8000200
Write 256 bytes at 0x8000300
Write 256 bytes at 0x8000400
Write 256 bytes at 0x8000500
Write 256 bytes at 0x8000600
Write 256 bytes at 0x8000700
Write 256 bytes at 0x8000800
Write 256 bytes at 0x8000900
Write 256 bytes at 0x8000A00
Write 256 bytes at 0x8000B00
Write 256 bytes at 0x8000C00
Write 256 bytes at 0x8000D00
Write 256 bytes at 0x8000E00
Write 256 bytes at 0x8000F00
Write 256 bytes at 0x8001000
Write 256 bytes at 0x8001100
Write 256 bytes at 0x8001200
Write 256 bytes at 0x8001300
Write 256 bytes at 0x8001400
Write 256 bytes at 0x8001500
Write 256 bytes at 0x8001600
Write 256 bytes at 0x8001700
Write 256 bytes at 0x8001800
Write 256 bytes at 0x8001900
Write 256 bytes at 0x8001A00
Write 256 bytes at 0x8001B00
Write 256 bytes at 0x8001C00
Read 256 bytes at 0x8000000
Read 256 bytes at 0x8000100
Read 256 bytes at 0x8000200
Read 256 bytes at 0x8000300
Read 256 bytes at 0x8000400
Read 256 bytes at 0x8000500
Read 256 bytes at 0x8000600
Read 256 bytes at 0x8000700
Read 256 bytes at 0x8000800
Read 256 bytes at 0x8000900
Read 256 bytes at 0x8000A00
Read 256 bytes at 0x8000B00
Read 256 bytes at 0x8000C00
Read 256 bytes at 0x8000D00
Read 256 bytes at 0x8000E00
Read 256 bytes at 0x8000F00
Read 256 bytes at 0x8001000
Read 256 bytes at 0x8001100
Read 256 bytes at 0x8001200
Read 256 bytes at 0x8001300
Read 256 bytes at 0x8001400
Read 256 bytes at 0x8001500
Read 256 bytes at 0x8001600
Read 256 bytes at 0x8001700
Read 256 bytes at 0x8001800
Read 256 bytes at 0x8001900
Read 256 bytes at 0x8001A00
Read 256 bytes at 0x8001B00
Read 256 bytes at 0x8001C00
Verification FAILED
7348 vs 7348
0xe0: 0xbf vs 0xff
0x14c: 0xbf vs 0xff
0x156: 0x70 vs 0xb9
0x157: 0x47 vs 0x23
0x158: 0x10 vs 0x88
0x159: 0xb5 vs 0xda
0x15a: 0xf vs 0x7
0x15b: 0x4c vs 0x26
0x15c: 0x22 vs 0x11
0x15d: 0x68 vs 0xb4
0x15e: 0xa3 vs 0x51
0x15f: 0x88 vs 0x44
0x160: 0x2a vs 0x95
0x161: 0xb9 vs 0xdc
0x162: 0xbd vs 0x5e
0x163: 0xe8 vs 0x74
0x164: 0x10 vs 0x8
0x165: 0x40 vs 0xa0
0x166: 0x19 vs 0xc
0x167: 0x46 vs 0x23
0x168: 0xc vs 0x6
0x169: 0x48 vs 0x24
0x16b: 0xf0 vs 0x78
0x16c: 0xe2 vs 0xf1
0x16d: 0xbb vs 0x5d
0x16e: 0xa2 vs 0x51
0x16f: 0x68 vs 0x34
0x170: 0x12 vs 0x9
0x171: 0xf0 vs 0xf8
0x172: 0x1 vs 0x0
0x173: 0x2 vs 0x81
0x174: 0xb vs 0x5
0x175: 0xd0 vs 0x68
0x177: 0x22 vs 0x11
0x178: 0x2 vs 0x81
0x179: 0x21 vs 0x10
0x17a: 0x8 vs 0x84
0xb16: 0xff vs 0xbf
0xc80: 0xcb vs 0xcf
0xd7e: 0x13 vs 0x11
0xd90: 0xff vs 0xbf
0x122c: 0x1f vs 0x3f
0x122d: 0xfa vs 0x7d
0x122e: 0x8a vs 0xc5
0x122f: 0xf9 vs 0x7c
0x1230: 0x4a vs 0x25
0x1231: 0x46 vs 0x23
0x1233: 0xf0 vs 0xf8
0x1234: 0x45 vs 0x22
0x1235: 0xfc vs 0x7e
0x1236: 0x0 vs 0x80
0x1237: 0x9b vs 0x4d
0x1238: 0xa4 vs 0xd2
0x1239: 0xeb vs 0xf5
0x123a: 0x9 vs 0x4
0x123b: 0x4 vs 0x82
0x123c: 0xd3 vs 0xe9
0x1781: 0xbf vs 0xff

but sometimes:

fadedbee@cyan:~/blackmagic/src$ python ../../stm32loader/stm32loader.py -p /dev/ttyUSB0 -e -w -v blackmagic_dfu.bin
Bootloader version 22
Chip id: 0x410 (STM32 Medium-density)
Write 256 bytes at 0x8000000
Write 256 bytes at 0x8000100
Write 256 bytes at 0x8000200
Write 256 bytes at 0x8000300
Write 256 bytes at 0x8000400
Write 256 bytes at 0x8000500
Write 256 bytes at 0x8000600
Write 256 bytes at 0x8000700
Write 256 bytes at 0x8000800
Write 256 bytes at 0x8000900
Write 256 bytes at 0x8000A00
Write 256 bytes at 0x8000B00
Write 256 bytes at 0x8000C00
Write 256 bytes at 0x8000D00
Write 256 bytes at 0x8000E00
Write 256 bytes at 0x8000F00
Write 256 bytes at 0x8001000
Write 256 bytes at 0x8001100
Write 256 bytes at 0x8001200
Write 256 bytes at 0x8001300
Write 256 bytes at 0x8001400
Write 256 bytes at 0x8001500
Write 256 bytes at 0x8001600
Write 256 bytes at 0x8001700
Write 256 bytes at 0x8001800
Write 256 bytes at 0x8001900
Write 256 bytes at 0x8001A00
Write 256 bytes at 0x8001B00
Write 256 bytes at 0x8001C00
Traceback (most recent call last):
  File "../../stm32loader/stm32loader.py", line 455, in <module>
    cmd.writeMemory(conf['address'], data)
  File "../../stm32loader/stm32loader.py", line 337, in writeMemory
    self.cmdWriteMemory(addr, data[offs:offs+lng] + ([0xFF] * (256-lng)) )
  File "../../stm32loader/stm32loader.py", line 204, in cmdWriteMemory
    self._wait_for_ask("0x31 programming failed")
  File "../../stm32loader/stm32loader.py", line 80, in _wait_for_ask
    raise CmdException("Can't read port or timeout")
__main__.CmdException: Can't read port or timeout

Is there any further investigation I can do?

fadedbee commented 4 years ago

I can fix it for one occasion with a mass-erase: st-flash erase.

florisla commented 4 years ago

This could be caused by bad cabling, power instability or shady hardware (blue pill or uart adapter). It's definitely not an issue in the flash tool.

Things you can try: