Can not define DHCSR_Addr under tag<debugvars> in pyOCD v0.44.0
The following debug sequence failed:
<family Dfamily="SAML11" Dvendor="Microchip:3">
<debugvars>
__var AIRCR_Addr = 0xE000ED0C;
__var DHCSR_Addr = 0xE000EDF0;
__var DEMCR_Addr = 0xE000EDFC;
__var DCRSR_Addr = 0xE000EDF4;
__var DCRDR_Addr = 0xE000EDF8;
</debugvars>
<sequences>
.................................
</sequences>
..........
Error message:
raise RuntimeError("attempt to modify read-only variable '%s'" % name)
RuntimeError: attempt to modify read-only variable 'DHCSR_Addr'
The same debug sequence works fine in v0.43.0. It seems defining variables related to ARM registers are not allowed in
Hi @erichying, Could you share the command used to invoke pyOCD, along with its debug log and the CMSIS-Pack in use? This will help us diagnose the issue.
Hi @TeoMahnic , Here is the DFP Microchip.SAML11_DFP.4.5.268_modified.zip I used for debugging. This DFP is derived from the DFP on Keil website SAML11_DFP
The difference is the definition of DHCSR_Addr is moved from individual <sequence/> section to global section <debugvars/>. The modified DFP works in pyocd 0.43.0, but it failed in 0.44.0. Here is the command I used and output from command line.
(.venv) PS C:\Users\M19XXX\Developer\PythonProject\PyOCD> pyocd erase --chip -t ATSAML11E16A --pack=C:/Users/M19XXX/Downloads/Microchip.SAML11_DFP.4.5.268_modified.pack --verbose
0000955 I Target type is atsaml11e16a [board]
0001039 I debugvar 'BOCOR_BOOT_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_BOOT_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_BOOT_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_BOOT_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_BOOT_Keyword4' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_BOOT_Keyword5' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_BOOT_Keyword6' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_BOOT_Keyword7' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_CE0_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001040 I debugvar 'BOCOR_CE0_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE0_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE0_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE1_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE1_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE1_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE1_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE2_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE2_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE2_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CE2_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CRC_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CRC_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001041 I debugvar 'BOCOR_CRC_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'BOCOR_CRC_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'BOCOR_Config0' = 0xa0000000 (2684354560) [pack_target]
0001042 I debugvar 'BOCOR_Config1' = 0x30000 (196608) [pack_target]
0001042 I debugvar 'BOCOR_Program' = 0x0 (0) [pack_target]
0001042 I debugvar 'BOCOR_ROMVersion' = 0x3a (58) [pack_target]
0001042 I debugvar 'CE0_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE0_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE0_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE0_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE1_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE1_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE1_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE1_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE2_Keyword0' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE2_Keyword1' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE2_Keyword2' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE2_Keyword3' = 0xffffffff (4294967295) [pack_target]
0001042 I debugvar 'CE_Select' = 0x2 (2) [pack_target]
0001042 I debugvar 'DHCSR_Addr' = 0xe000ed0c (3758157068) [pack_target]
0001043 I debugvar 'ProgramDebugAccessLevel' = 0x2 (2) [pack_target]
0001043 I debugvar 'UROW_Config0' = 0xe03f (57407) [pack_target]
0001043 I debugvar 'UROW_Config1' = 0x1800 (6144) [pack_target]
0001043 I debugvar 'UROW_Config2' = 0x7f0800ff (2131230975) [pack_target]
0001043 I debugvar 'UROW_Config3' = 0x1 (1) [pack_target]
0001043 I debugvar 'UROW_NONSECA' = 0x0 (0) [pack_target]
0001043 I debugvar 'UROW_NONSECB' = 0x0 (0) [pack_target]
0001043 I debugvar 'UROW_NONSECC' = 0x0 (0) [pack_target]
0001043 I debugvar 'UROW_Program' = 0x0 (0) [pack_target]
0001050 I DP IDR = 0x0bf11477 (v1 MINDP rev0) [dap]
0001080 I AHB5-AP#0 IDR = 0x04770025 (AHB5-AP var2 rev0) [discovery]
0001091 I AHB5-AP#0 Class 0x1 ROM table #0 @ 0x41003000 (designer=01f part=cd0) [rom_table]
0001100 I [0]<e00ff000:ROM class=1 designer=43b:Arm part=4cb> [rom_table]
0001100 I AHB5-AP#0 Class 0x1 ROM table #1 @ 0xe00ff000 (designer=43b:Arm part=4cb) [rom_table]
0001111 I [0]<e000e000:SCS M23 class=9 designer=43b:Arm part=d20 devtype=00 archid=2a04 devid=0:0:0> [rom_table]
0001120 I [1]<e0001000:DWT M23 class=9 designer=43b:Arm part=d20 devtype=00 archid=1a02 devid=0:0:0> [rom_table]
0001128 I [2]<e0002000:BPU M23 class=9 designer=43b:Arm part=d20 devtype=00 archid=1a03 devid=0:0:0> [rom_table]
0001130 C Error: attempt to modify read-only variable 'DHCSR_Addr' [__main__]
Thanks for providing the details.
The error occurs during execution of the DebugCoreStart debug sequence. Starting with v0.44.0, a default set of predefined debug access sequences was introduced, as defined by the Open-CMSIS-Pack specification.
According to the debugvars specification, user-defined debug access variables are read-only within debug access sequences. In the modified SAML11 pack, the DHCSR_Addr variable is defined as a global debug variable, but is then reassigned during execution of the predefined DebugCoreStart sequence. This violates the specification and results in the observed error.
Consider using a different variable name that does not overlap with those used by the predefined debug sequences, or avoiding defining the variable in the global scope. In general, modifying a pack is discouraged, as packs are intended to be used as provided by the vendor. If changes are required, they should be made with care.
Thanks for the answer from @TeoMahnic .
Unfortunately, I didn't find that DHCSR_Addr is in the predefined variables. It's either the documentation is old or DHCSR_Addr is a predefined variable for pyocd >= 0.44.0.
That explains why it used to work for pyocd <= 0.43.0
About "reassign": The debug sequence included in the Microchip.SAML11_DFP.4.5.268_modified.zip has only one assign for variable DHCSR_Addr, and it's in line 61, the following debug sequences just uses the value, and no reassign happen.
I think we understand the problem now. The new predefined debug sequences added in https://github.com/pyocd/pyOCD/pull/1939/commits use DHCSR_ADDR as a variable, whereas Microchip debug sequences use it as a constant. When a given sequence is not defined by Microchip , the default gets picked, creating a conflict.
@erichying , I am afraid you are hitting a nasty caveat in the debug description specification.
Variables declared locally in default sequences like DebugCoreStart haven't been considered as special so far. They are not "predefined variables" as by the definition here.
What happens is that you declare DHCSR_Addr in the <debugvars> in the modified pack. Which makes it a global, read-only, and it's intended to be only changed by a user in a dbgconf file. This also disallows re-declaring it locally in a sequence, including the default sequences like DebugCoreStart. Hence, the clash you see. Unfortunately, the spec isn't very clear about it.
Such problem unfortunately didn't show with uVision because it didn't execute default sequences through the debug sequence engine like newer implementations in Arm DS and now in pyOCD.
I've created https://github.com/Open-CMSIS-Pack/Open-CMSIS-Pack-Spec/issues/392 to fix this by introducing a naming convention for variable names in default sequences, i.e. variable names a user shouldn't use for a "debugvar". We hope this improves the situation. Please feel free to comment on that issue if you still see a caveat with it.
We plan to apply the changes in the next pyOCD release. Until then, I am afraid you have to rename variables you declare in the
@erichying, pyOCD v0.44.1 has been released and includes an update to the naming scheme for local variables in the default debug sequence implementations. These variables now use a __ prefix, which should resolve the issue you encountered.
The reported issue should be resolved.