|
| 1 | +# pyOCD debugger |
| 2 | +# Copyright (c) 2023 Arm Limited |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +from typing import Optional |
| 18 | +from ...coresight.coresight_target import CoreSightTarget |
| 19 | +from ...core.memory_map import (RamRegion, MemoryMap) |
| 20 | + |
| 21 | +from ...core.target import Target |
| 22 | + |
| 23 | +# see https://developer.arm.com/documentation/101104/0200/programmers-model/system-control-element/system-control-register-block |
| 24 | +SYSTEM_CONTROL = 0x50021000 |
| 25 | +RESET_MASK = SYSTEM_CONTROL + 0x104 |
| 26 | +RESET_MASK_SYSRSTREQ0_EN = 1 << 4 |
| 27 | +RESET_MASK_SYSRSTREQ1_EN = 1 << 5 |
| 28 | +CPU_WAIT = SYSTEM_CONTROL + 0x118 |
| 29 | +CPU_WAIT_CPU0 = 1 |
| 30 | +CPU_WAIT_CPU1 = 2 |
| 31 | + |
| 32 | +class AN521(CoreSightTarget): |
| 33 | + |
| 34 | + VENDOR = "Arm" |
| 35 | + |
| 36 | + MEMORY_MAP = MemoryMap( |
| 37 | + RamRegion( name='code_ns', start=0x00000000, length=0x08000000, access='rwx'), |
| 38 | + RamRegion( name='code_s', start=0x10000000, length=0x08000000, access='rwxs'), |
| 39 | + |
| 40 | + RamRegion( name='sram_ns', start=0x20000000, length=0x02000000, access='rwx'), |
| 41 | + RamRegion( name='mtb_ns', start=0x24000000, length=0x00004000, access='rwx'), |
| 42 | + RamRegion( name='sram2_ns', start=0x28000000, length=0x00200000, access='rwx'), |
| 43 | + RamRegion( name='sram3_ns', start=0x28200000, length=0x00200000, access='rwx'), |
| 44 | + |
| 45 | + RamRegion( name='sram_s', start=0x30000000, length=0x02000000, access='rwxs'), |
| 46 | + RamRegion( name='mtb_s', start=0x34000000, length=0x00004000, access='rwxs'), |
| 47 | + RamRegion( name='sram2_s', start=0x38000000, length=0x00200000, access='rwxs'), |
| 48 | + RamRegion( name='sram3_s', start=0x38200000, length=0x00200000, access='rwxs'), |
| 49 | + # External Parallel SRAM only mapped to non-secure |
| 50 | + RamRegion( name='psram_ns', start=0x80000000, length=0x01000000, access='rwx'), |
| 51 | + ) |
| 52 | + |
| 53 | + def __init__(self, session): |
| 54 | + super().__init__(session, self.MEMORY_MAP) |
| 55 | + |
| 56 | + def create_init_sequence(self): |
| 57 | + seq = super().create_init_sequence() |
| 58 | + |
| 59 | + seq.insert_before('halt_on_connect', |
| 60 | + ('enable_sysresetreq', self._enable_sysresetreq), |
| 61 | + ) |
| 62 | + |
| 63 | + return seq |
| 64 | + |
| 65 | + def _enable_sysresetreq(self): |
| 66 | + reset_mask = self.read32(RESET_MASK) |
| 67 | + reset_mask |= RESET_MASK_SYSRSTREQ0_EN |
| 68 | + self.write32(RESET_MASK, reset_mask) |
| 69 | + |
| 70 | + |
| 71 | + def reset_and_halt(self, reset_type: Optional[Target.ResetType] = None): |
| 72 | + self.write32(CPU_WAIT, CPU_WAIT_CPU1) |
| 73 | + super().reset_and_halt(reset_type) |
0 commit comments