Pyocd not auto-detecting target with STLink/V2 probe

457 views Asked by At

pyocd list command returns:

  #   Probe/Board    Unique ID                  Target  
--------------------------------------------------------
  0   STM32 STLink   34FF72063048553717451543   n/a     

Even though this should be a probe that supports auto-detection of target. STM32CubeProgrammer detects everything just fine on probe connection. My targets are STM32G071GBU6N and STM32L552VET6. I have installed the correct packs:

  Part             Vendor               Pack                 Version   Installed  
----------------------------------------------------------------------------------
  STM32G071GBUxN   STMicroelectronics   Keil.STM32G0xx_DFP   1.4.0     True       

  Part             Vendor               Pack                 Version   Installed  
----------------------------------------------------------------------------------
  STM32L552VETx    STMicroelectronics   Keil.STM32L5xx_DFP   1.4.0     True       
  STM32L552VETxQ   STMicroelectronics   Keil.STM32L5xx_DFP   1.4.0     True      

I cannot flash with the generic cortex_m target. If I manually set the Session() object's options to the correct target via target_override, I can flash just fine. However, I need to programmatically detect when my STLink/V2 is connected to the L5 or the G0 and flash with the correct firmware. I cannot figure out a way to detect which MCU I am connected to in order to programmatically set the correct target and flash the correct firmware file.

  • PyOCD version = 0.35.1
  • STLink/V2 firmware = V2J40S7

I purchased the STLink/V2 from a reputable supplier, so there's a reasonable probability the probe is not counterfeit.

The documentation suggests I should be able to auto-detect with the STM32 STLink Probe/Board: image

Note that, unlike other posts, I detect the debug probe just fine, and the probe can connect to the MCU, I just cannot figure out a way to determine which MCU it is connected to. Perhaps I can manually set the target_override and check some feature that the L5 has and the G0 does not (or vice versa) and run if found or catch an exception if not found.

I do not have enough reputation to create the pyocd tag. Perhaps someone else wants to?

1

There are 1 answers

0
jacob On

I upgraded to a STLink/V3 and the issue still persists. The answer is that PyOCD only auto-detects with development boards where board specific firmware provides this feature. This fact does not seem to be reflected in the documentation at this time. See this issue response:

Are you using your own boards or STM32 dev boards? As @hagibr says, auto detection only works with on-board probes, where a board-specific probe firmware build tells pyocd that target type.

For custom boards or when using standalone probes, you'll need to have a config file that maps the probe unique ID to target type.

It sounds like there is no programmatic way to detect what target the probe is connected to at any given time. One may be able to find the register that STM32CubeProgrammer is reading and perform a target.memory_read() on said register and interpret the result. This approach requires significant knowledge about the MCU in question.