pyOCD icon indicating copy to clipboard operation
pyOCD copied to clipboard

Fail to program big files on stm32h743

Open nvincent-vossloh opened this issue 2 years ago • 11 comments

Hello,

I'm trying to load a firmware on a nucleo_h743zi using pyocd. When the firmware size is small (blinky, hello world, ~20kB) everything is fine: my firmware is downloaded onto target and runs smoothly. However, if the firmware gets big (tried with 256k), pyocd says that it programmed the file correctly, however the firmware does not run or crash (fault trace from zephyr OS).

I dumped the content of my flash and saw that some portions of the flash was left unprogrammed (0xff) or set to 0.

When using openocd or STM32_Programmer I do not have that issue.

I tried to increase the size of an hello-world by adding random data at the end and tried programming it with STM32_Programmer_CLI (it works) and with pyocd (does not work).

Here are the various command line used:

  • Grow small binary file (hello.bin):
head -c 200k < /dev/urandom > random.bin
cat hello.bin random.bin >> big_hello.bin
  • programming firmware:
pyocd flash -e sector -a 0x8000000 -t stm32h743zitx -O reset_type=hw  --pack Keil.STM32H7xx_DFP.2.7.0.pack big_hello.bin 
STM32_Programmer_CLI -c port=SWD -d big_hello.bin 0x08000000 -rst
  • Dumping memory content:
pyocd commander -c "savemem 0x08000000 220712 dump_with_cmder.bin"
STM32_Programmer_CLI -c port=SWD  -u 0x08000000 220712 dump_from_stm32prog.bin

Memory read from the devices is always the same regardless of the method. Memory written to the device is not correct when using pyocd.

Let me know if you need additional information.

Thanks. ps: by now, I also get errors when programming small firmwares.

nvincent-vossloh avatar Aug 23 '21 15:08 nvincent-vossloh

Thanks for the detailed report!

I don't have an H743, but will try to replicate on my H747.

flit avatar Aug 23 '21 16:08 flit

I went ahead and got a Nucleo-H743 😄, and can reproduce the problem now even for small images. For testing, I'm using a build of Zephyr samples/basic/blinky (attached).

It looks like valid data stops being programmed at some offset.

pyocd> rw 0x08002d60 0x40
08002d60:  001ff1c0 e92d4770 688641f0 4604460d    |.....-Gph.A.F.F.|
08002d70:  ffc8f7ff 4f00f5b6 d3014601 d0332801    |....O.....F..3(.|
08002d80:  ffffffff ffffffff ffffffff ffffffff    |................|
08002d90:  ffffffff ffffffff ffffffff ffffffff    |................|

Then in this case it picks up again at offset 0x3000 and the rest of the file is programmed correctly.

The failures seem random. In another test with the same file, ranges 0x900-0xC00 and 0x3080-0x3400 were not programmed. The sizes of the unprogrammed regions can differ, but successfully programmed data always seems to restart at a page boundary (this flash has 0x400 byte pages and 128 kB sectors).

Will continue investigating. I need to compare with Keil MDK since both it and pyocd use the same flash algo from the Keil.STM32H7xx_DFP CMSIS-Pack.

flit avatar Sep 01 '21 21:09 flit

Can confirm I see this too on a Nucleo-H743ZI2. Identical behavior.

JackNewman12 avatar Sep 05 '21 22:09 JackNewman12

Hi Make sure you are using the latest ST Link FW: https://www.st.com/en/development-tools/stsw-link007.html

jeromecoutant avatar Sep 06 '21 08:09 jeromecoutant

Hi Make sure you are using the latest ST Link FW: https://www.st.com/en/development-tools/stsw-link007.html

Hi, I'm using V3J7M2 version of ST Link firmware. upgrade tool list it as the latest.

nvincent-vossloh avatar Sep 06 '21 08:09 nvincent-vossloh

Hi, I'm using V3J7M2 version of ST Link firmware. upgrade tool list it as the latest.

Please upgrade firmware to the version V3J8M3

jeromecoutant avatar Sep 06 '21 08:09 jeromecoutant

Ok done (I needed to first upgrade stsw-link007 software to be able to see latest firmware...), and I have the same behavior of unwritten datas, and as @flit mentionned, data restart at a page boundary.

nvincent-vossloh avatar Sep 06 '21 08:09 nvincent-vossloh

Hello, quick update:

I tested with latest Keil.STM32H7xx_DFP.3.0.0.pack and I'm still having the same issue.

I tried to have a look into pyocd code to see what was going on (did not went very far, this level of code is beyond my knowledge), I could verify that what is written in memory with write_memory_block8 in load_page_buffer seems to be properly written into memory since I could call read_memory_block8 and compare read data versus written.

If you have some pointers for me to look in the "good" direction I may have some time to spent on this issue.

Thanks

nvincent-vossloh avatar Apr 07 '22 21:04 nvincent-vossloh

Thanks for the update, and for the willingness to help out. This one has been on my priority list for too long.

I've been working on a script to fully validate an FLM-type flash algo, without the complexity of the full pyocd flash programming system. This should help narrow down the problem, at least.

https://github.com/flit/pyOCD/blob/feature/test_flash_algo_script/scripts/test_flash_algo.py

Right now it's mostly focused on verifying erases, but does check page programming incidentally. It also doesn't use double-buffered programming (writing the next page to RAM whilst another page is being programmed to flash by the target's CPU).

An initial test just now against the H743 passed all tests. Interesting, but not conclusive. 😄

Another thing that would be helpful if you have time is to compare against MDK-Community. Pyocd uses the same CMSIS-Pack flash algos, so it will be another good comparison to narrow down the cause.

Also, if you have a failing firmware image you could attach or send via email (see my GH profile) or Slack (see the links on pyocd.io), that would be very useful.

Thanks!

flit avatar Apr 21 '22 21:04 flit

Blinky_MDK.tar.gz Here is a Blinky in various formats (axf, hex, bin) generated from uVision (MDK/KEIL). With MDK I had no issue programming onto the target. With pyocd it fails to program properly the firmware.

If you need me to run test_flash_algo.py could you please provide a valid command line ?

Thanks :slightly_smiling_face:

nvincent-vossloh avatar Apr 29 '22 09:04 nvincent-vossloh

@nvincent-vossloh Thank you for the test files!

I've run test_flash_algo.py and it passes. However, it doesn't directly test programming yet, it currently does that as a side effect of testing sector erases. If you would like to run it, you need to extract the STM32H7xx CMSIS-Pack as a zip file (download from here, change extension to .zip and extract). The flash algo to use is CMSIS/Flash/STM32H7x_2048.FLM. Pass the path to this FLM to test_flash_algo.py as a positional arg. For the H7xx you need to set --ram=0x24000000 to use a large enough RAM.

I talked with the Keil MDK team, and they don't have any reports of H7xx flash programming issues.

All that, and your testing with MDK (thanks!) suggest that the issue can be fixed in pyocd itself. Which is good, since this means it's under our direct control.

flit avatar Apr 29 '22 14:04 flit

have similar issue:

impossible to program or debug, I'm just first time with Mbed and get fun with this application.

while i looking for solution I found incorrect memory settings for the NUCLEO-H743ZI2 and try to fix in targets.json "mbed_rom_start": "0x08000000", "mbed_rom_size": "0x200000", "mbed_ram_start": "0x24000000", "mbed_ram_size": "0x80000", but that rise other interesting problem ;) [Warning] @0,0: L3912W: Option 'legacyalign' is deprecated. [Error] @0,0: L6221E: Execution region RW_m_crash_data with Execution range [0x24000298,0x24000398) overlaps with Execution region RW_IRAM1 with Execution range [0x24000000,0x240064b4). Warning: L3912W: Option 'legacyalign' is deprecated.

not yet solution founded right now.

Mbed Studio: 1.4.4 Windows 10

about stlink 12:29:48 : STM32CubeProgrammer API v2.12.0 | Windows-64Bits 12:29:50 : ST-LINK SN : 002000313438511734313939 12:29:50 : ST-LINK FW : V3J10M3 12:29:50 : Board : NUCLEO-H743ZI 12:29:50 : Voltage : 3.27V 12:29:50 : SWD freq : 24000 KHz 12:29:50 : Connect mode: Under Reset 12:29:50 : Reset mode : Software reset 12:29:50 : Device ID : 0x450 12:29:50 : Revision ID : Rev V

"request","command":"initialize","arguments":{"clientID":"Theia","clientName":"Theia IDE","adapterID":"cmsis-debug","locale":"en-US","linesStartAt1":true,"columnsStartAt1":true,"pathFormat":"path","supportsVariableType":false,"supportsVariablePaging":false,"supportsRunInTerminalRequest":true}} "response","request_seq":1,"command":"initialize","success":true,"body":{"supportsConfigurationDoneRequest":true,"supportsSetVariable":true,"supportsConditionalBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsLogPoints":true,"supportsFunctionBreakpoints":true,"supportsDisassembleRequest":true}} "request","command":"launch","arguments":{"name":"Mbed Debug","type":"cmsis-debug","request":"launch","runToMain":true,"verbose":false,"program":"c:/Users/zeltr/Mbed Programs/mbed-os-example-for-google-iot-cloud/BUILD/NUCLEO_H743ZI2/ARMC6/mbed-os-example-for-google-iot-cloud_application.elf","gdb":"c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\gcc\bin\arm-none-eabi-gdb.exe","objdump":"c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\gcc\bin\arm-none-eabi-objdump.exe","gdbCore":0,"gdbServerArguments":["c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\Scripts\pyocd-script.py","gdbserver","--uid","002000313438511734313939","--target","STM32H743ZITx","--erase=chip","--frequency","1800000","--pack","c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\cmsis-packs\Keil.STM32H7xx_DFP.2.7.0-small.pack","-O","connect_mode=under-reset"],"gdbServer":"c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\python.exe","gdbArguments":["-nh"]}} "event","event":"output","body":{"category":"console","output":"Selected port 50000 for debugging"}} "Starting Debugger" 0000518:INFO:board:Target type is stm32h743zitx 0000628:INFO:coresight_target:Asserting reset prior to connect 0000755:INFO:dap:DP IDR = 0x6ba02477 (v2 rev6) 0000790:INFO:ap:AHB-AP#0 IDR = 0x84770001 (AHB-AP var0 rev8) 0000791:INFO:ap:AHB-AP#1 IDR = 0x84770001 (AHB-AP var0 rev8) 0000792:INFO:ap:APB-AP#2 IDR = 0x54770002 (APB-AP var0 rev5) 0000795:INFO:rom_table:AHB-AP#0 Class 0x1 ROM table #0 @ 0xe00fe000 (designer=020 part=450) 0000796:INFO:rom_table:[0]<e00ff000:ROM class=1 designer=43b part=4c7> 0000796:INFO:rom_table: AHB-AP#0 Class 0x1 ROM table #1 @ 0xe00ff000 (designer=43b part=4c7) 0000798:ERROR:rom_table:Error attempting to probe CoreSight component referenced by ROM table entry #0: Memory transfer fault (read) @ 0xe000efbc-0xe000f043\r\nTraceback (most recent call last): File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\rom_table.py", line 358, in _read_table self._handle_table_entry(entry, entryNumber) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\rom_table.py", line 408, in _handle_table_entry cmpid.read_id_registers() File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\rom_table.py", line 113, in read_id_registers regs = self.ap.read_memory_block32(self.top_address + self.IDR_READ_START, self.IDR_READ_COUNT) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 271, in read_memory_block32 return conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, size * 4, self._apsel)) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 385, in read_mem32 return self._read_mem(addr, size, Commands.JTAG_READMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 343, in _read_mem raise exc\r\npyocd.core.exceptions.TransferFaultError: Memory transfer fault (read) @ 0xe000efbc-0xe000f043 0000799:INFO:rom_table: [1]<e0001000:DWT class=14 designer=43b part=002> 0000799:INFO:rom_table: [2]<e0002000:FPB class=14 designer=43b part=00e> 0000800:INFO:rom_table: [3]<e0000000:ITM class=14 designer=43b part=001> 0000801:INFO:rom_table:[1]<e0041000:ETM-M7 class=9 designer=43b part=975 devtype=13 archid=4a13 devid=0:0:0> 0000801:INFO:rom_table:[2]<e0043000:CTI class=9 designer=43b part=906 devtype=14 archid=0000 devid=40800:0:0> 0000802:INFO:rom_table:APB-AP#2 Class 0x1 ROM table #0 @ 0xe00e0000 (designer=020 part=450) 0000803:WARNING:rom_table:Invalid coresight component, cidr=0x0 0000803:INFO:rom_table:[2]<e00e3000: cidr=0, pidr=0, component invalid> 0000804:WARNING:rom_table:Invalid coresight component, cidr=0x0 0000804:INFO:rom_table:[3]<e00e4000: cidr=0, pidr=0, component invalid> 0000804:INFO:rom_table:[4]<e00e5000:TSGEN class=15 designer=43b part=101> 0000805:ERROR:rom_table:Error attempting to probe CoreSight component referenced by ROM table entry #5: Memory transfer fault (read) @ 0xe00f0fbc-0xe00f1043\r\nTraceback (most recent call last): File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\rom_table.py", line 358, in _read_table self._handle_table_entry(entry, entryNumber) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\rom_table.py", line 408, in _handle_table_entry cmpid.read_id_registers() File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\rom_table.py", line 113, in read_id_registers regs = self.ap.read_memory_block32(self.top_address + self.IDR_READ_START, self.IDR_READ_COUNT) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 271, in read_memory_block32 return conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, size * 4, self._apsel)) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 385, in read_mem32 return self._read_mem(addr, size, Commands.JTAG_READMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel) File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 343, in _read_mem raise exc\r\npyocd.core.exceptions.TransferFaultError: Memory transfer fault (read) @ 0xe00f0fbc-0xe00f1043 0000806:INFO:dwt:4 hardware watchpoints 0000808:INFO:fpb:8 hardware breakpoints, 1 literal comparators 0000813:CRITICAL:main:No cores were discovered!\r\nTraceback (most recent call last): File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\main.py", line 402, in run self._COMMANDSself._args.cmd File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\main.py", line 746, in do_gdbserver with session: File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\session.py", line 339, in enter self.open() File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\session.py", line 457, in open self._board.init() File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\board\board.py", line 85, in init self.target.init() File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\soc_target.py", line 117, in init seq.invoke() File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\utility\sequencer.py", line 208, in invoke resultSequence = call() File "c:\Users\zeltr\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\coresight_target.py", line 214, in check_for_cores raise exceptions.DebugError("No cores were discovered!")\r\npyocd.core.exceptions.DebugError: No cores were discovered!

Zeltrex avatar Jan 11 '23 12:01 Zeltrex