pyocd / pyOCD

Open source Python library for programming and debugging Arm Cortex-M microcontrollers
https://pyocd.io
Apache License 2.0
1.12k stars 481 forks source link

STLink error (16): AP wait with NUCLEO-L452RE board #1329

Open steprat opened 2 years ago

steprat commented 2 years ago

Hello,

when I try to flash a NUCLEO-L452RE board with pyOCD i get a STLink error (16): AP wait When I compile the same mbed blinky project for an STM32L152 pyOCD flashes a NUCLEO-L152RE Board without a problem.

Command

pyocd flash --target stm32l452retx --erase=chip -0 connect_mode=under-reset mbed-20220208-2.bin

This is the terminal output:

0002880:ERROR:ap:Transfer error while reading AHB-AP#0 ROM table: STLink error (16): AP wait
Traceback (most recent call last):
  File ".../pyocd/coresight/ap.py", line 740, in find_components
    cmpid.read_id_registers()
  File ".../pyocd/coresight/rom_table.py", line 114, in read_id_registers
    regs = self.ap.read_memory_block32(self.top_address + self.IDR_READ_START, self.IDR_READ_COUNT)
  File ".../pyocd/probe/stlink_probe.py", line 270, in read_memory_block32
    return conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, size * 4, self._apsel))
  File ".../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 ".../pyocd/probe/stlink/stlink.py", line 345, in _read_mem
    raise self._ERROR_CLASSES[status](error_message)
pyocd.core.exceptions.TransferTimeoutError: STLink error (16): AP wait
0002883:CRITICAL:__main__:No cores were discovered!
Traceback (most recent call last):
  File ".../pyocd/__main__.py", line 150, in run
    status = cmd.invoke()
  File ".../pyocd/subcommands/load_cmd.py", line 96, in invoke
    with session:
  File ".../pyocd/core/session.py", line 341, in __enter__
    self.open()
  File ".../pyocd/core/session.py", line 459, in open
    self._board.init()
  File ".../pyocd/board/board.py", line 99, in init
    self.target.init()
  File ".../pyocd/core/soc_target.py", line 117, in init
    seq.invoke()
  File ".../pyocd/utility/sequencer.py", line 208, in invoke
    resultSequence = call()
  File ".../pyocd/coresight/coresight_target.py", line 247, in check_for_cores
    raise exceptions.DebugError("No cores were discovered!")
pyocd.core.exceptions.DebugError: No cores were discovered!

I also looked at #1147 but a power down problem can not be related to mine. Board is running/idle not power down.

Any pointers to what I could check or test would be appreciated.

Stephen

flit commented 2 years ago

Hi @steprat, sorry for the slow reply, I was moving to a new house this past week.

Is the pyocd command line in your description correct? It has -0 connect_mode=under-reset, with a zero instead of "capital oh". This probably won't work, but is worth checking.

Mbed OS automatically places the device in low power modes when CPU idles (like most modern IoT oriented RTOSes), so this is almost certainly related to low power modes. (The "AP wait" error occurs almost exclusively with low power related issues on STM32.)

Could you please try pyocd v0.33.1 (latest as of this writing)?

I'm not very familiar with the STM32L452/152 differences compared to other STM32 devices, so I'll need to read up on them before suggesting anything else.