pyOCD: FlashEraseFailure on STM32G431KB Nucleo

When trying to flash images onto the STM32G431KB Nucleo board through the builtin ST-Link V3, PyOCD fails with a flash erase sector failure (result code 0x1).

The behavior is reproducible both from the shell and through the Python API.

~/src/py-aeric cli ❯ pyocd flash --erase sector --base-address 0x0800a800 --target stm32g431kbtx ../g4-nucleo/build/G4-Nucleo.bin
0000755 I Loading /home/lasse/src/g4-nucleo/build/G4-Nucleo.bin at 0x0800a800 [load_cmd]
[===                                               ]   7%
0006354 C flash erase sector failure (address 0x08010000; result code 0x1) [__main__]

Traceback (most recent call last):
  File "/home/lasse/.local/share/virtualenvs/py-aeric-xfOJeMmh/lib/python3.9/site-packages/pyocd/__main__.py", line 161, in run
    status = cmd.invoke()
  File "/home/lasse/.local/share/virtualenvs/py-aeric-xfOJeMmh/lib/python3.9/site-packages/pyocd/subcommands/load_cmd.py", line 117, in invoke
    programmer.program(filename,
  File "/home/lasse/.local/share/virtualenvs/py-aeric-xfOJeMmh/lib/python3.9/site-packages/pyocd/flash/file_programmer.py", line 170, in program
    self._loader.commit()
  File "/home/lasse/.local/share/virtualenvs/py-aeric-xfOJeMmh/lib/python3.9/site-packages/pyocd/flash/loader.py", line 289, in commit
    perf = builder.program(chip_erase=chipErase,
  File "/home/lasse/.local/share/virtualenvs/py-aeric-xfOJeMmh/lib/python3.9/site-packages/pyocd/flash/builder.py", line 509, in program
    flash_operation = self._sector_erase_program_double_buffer(progress_cb)
  File "/home/lasse/.local/share/virtualenvs/py-aeric-xfOJeMmh/lib/python3.9/site-packages/pyocd/flash/builder.py", line 911, in _sector_erase_program_double_buffer
    self.flash.erase_sector(sector.addr)
  File "/home/lasse/.local/share/virtualenvs/py-aeric-xfOJeMmh/lib/python3.9/site-packages/pyocd/flash/flash.py", line 371, in erase_sector
    raise FlashEraseFailure('flash erase sector failure', address=address, result_code=result)
pyocd.core.exceptions.FlashEraseFailure: flash erase sector failure (address 0x08010000; result code 0x1)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Alright, after rebuilding the algo from the 1.4.0 using the included MDK project, everything checks out. No further errors.

I wrote a script that runs a specified flash algo through a test sequence to verify that it can erase all sectors, and only the requested sector is erased. Eventually this script will be added to the pyocd repo under scripts/. Hopefully this script will make things a lot faster and simpler next time there’s buggy flash algo!

Tomorrow I’ll report the issue to the Keil team. Until a fixed version of the pack is released, you’ll have to manually override the flash algo (using either method from earlier in this issue). The working .flm file is attached here.

Thanks for sticking with me! 😄 And thanks again for sending the board. Sorry the issue isn’t one that I can simply fix myself in pyocd—this is unfortunate side of the CMSIS-Pack story.

STM32G43x-4x_128.zip

Update (now that I have a board thanks for @Finwood! 😄): I can produce the erase failure. Interestingly, version 1.2.0 of the STM32G4xx_DFP pack does work. Good suggestion @elfmimi!

Unfortunately the flash driver was nearly rewritten in 1.3.0 (also combining all variants into a single driver with config by macro), so diff’ing produces too many changes to be helpful.

Continuing debug…

Thanks, I’ll be able to take a look on Tuesday (Europe) and will come back to you then. Keep up the good work!