pyocd / pyOCD

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

pyOCD picks wrong flash algorithm for STM32L4R5 with Keil.STM32L4xx_DFP.2.6.2.pack #1628

Open csamrn opened 1 year ago

csamrn commented 1 year ago

ST has updated the Keil.STM32L4xx_DFP package to 2.6.2 in June 2023. They have introduced a second flash algorithm for the STM32L4R5 family in the Keil.STM32L4xx_DFP.pdsc file:

<!-- ***** Device 'STM32L4R5ZITx' ***** -->
<device Dname="STM32L4R5ZITx">
  <memory name="Main_Flash" access="rx"                   start="0x08000000" size="0x00200000" default="1" startup="1"/>
  <algorithm name="CMSIS/Flash/STM32L4Rx_2048_Dual.FLM"   start="0x08000000" size="0x00200000" RAMstart="0x20000000" RAMsize="0x8000" default="1"/>
  <algorithm name="CMSIS/Flash/STM32L4Rx_2048_Single.FLM" start="0x08000000" size="0x00200000" RAMstart="0x20000000" RAMsize="0x8000" default="0"/>
  <feature type="QFP" n="144"/>
</device>

The pervious one (2.6.1) looked like this:

<!-- ***** Device 'STM32L4R5ZIYx' ***** -->
<device Dname="STM32L4R5ZIYx">
  <memory name="Main_Flash" access="rx"                 start="0x08000000" size="0x00200000" default="1" startup="1"/>
  <algorithm name="CMSIS/Flash/STM32L4Rx_2048_Dual.FLM" start="0x08000000" size="0x00200000" RAMstart="0x20000000" RAMsize="0x8000" default="1"/>
  <feature type="CSP" n="144"/>
</device>

The issue with this is that now the STM32L4Rx_2048_Single.FLM algorithm gets picked instead of STM32L4Rx_2048_Dual.FLM as it is the second one in the list overwriting the first one: https://github.com/pyocd/pyOCD/blob/fba00fb7d7ab84f04478c0c5d57a9b25d82bb9e4/pyocd/target/pack/cmsis_pack.py#L500C16-L500C16

This leads to the following issue: The sector size is set to 0x2000 instead of 0x1000 (board.target.memory_map._regions[0]._flm.flash_info.sector_info_list). When erasing using -e sector this erases memory from other "original sized" pages than the ones intended. E.g. when using different hex files with subsequent address ranges aligned to 0x1000 page size, parts of the other hex file tend to get erased when the absolutely shouldn't.

Is there a way to specify which algorithm to choose without modifying the .pack file? Is there a way to choose which .pack file version to install via pyocd pack install?

hagibr commented 12 months ago

I don't know if you can specify which version to install, but you can still call pyOCD specifying the .pack file to use with the --pack option, something like this:

pyocd <other options> --pack /path/to/pack/folder/Keil.STM32L4xx_DFP.2.6.1.pack

PS: I'm just a user like you.