Skip to content

Commit c579a11

Browse files
committed
feat(dap): Add swd host support
The swd host moves some host operations to the device side to speed up the related swd operations. Port from DAPLink project: 8f4e9e40cf1a ("Remove unused USB_CONNECT_DELAY macro.")
1 parent 9a808da commit c579a11

File tree

6 files changed

+1772
-0
lines changed

6 files changed

+1772
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* @file target_config.h
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#ifndef TARGET_CONFIG_H
23+
#define TARGET_CONFIG_H
24+
25+
#include <stddef.h>
26+
#include <stdint.h>
27+
28+
#include "flash_blob.h"
29+
#include "util.h"
30+
31+
//! @brief Current target configuration version.
32+
//!
33+
//! - Version 1: Initial version.
34+
enum _target_config_version {
35+
kTargetConfigVersion = 1, //!< The current board info version.
36+
};
37+
38+
//! This can vary from target to target and should be in the structure or flash blob
39+
#define TARGET_AUTO_INCREMENT_PAGE_SIZE (1024)
40+
41+
//! Additional flash and ram regions
42+
#define MAX_REGIONS (10)
43+
44+
//! @brief Option flags for memory regions.
45+
enum _region_flags {
46+
kRegionIsDefault = (1 << 0), /*!< Out of bounds regions will use the same flash algo if this is set */
47+
kRegionIsSecure = (1 << 1), /*!< The region can only be accessed from the secure world. Only applies for TrustZone-enabled targets. */
48+
};
49+
50+
/*!
51+
* @brief Details of a target flash or RAM memory region.
52+
*/
53+
typedef struct __attribute__((__packed__)) region_info {
54+
uint32_t start; /*!< Region start address. */
55+
uint32_t end; /*!< Region end address. */
56+
uint32_t flags; /*!< Flags for this region from the #_region_flags enumeration. */
57+
uint32_t alias_index; /*!< Use with flags; will point to a different index if there is an alias region */
58+
program_target_t *flash_algo; /*!< A pointer to the flash algorithm structure */
59+
} region_info_t;
60+
61+
/*!
62+
* @brief Information required to program target flash.
63+
*/
64+
typedef struct __attribute__((__packed__)) target_cfg {
65+
uint32_t version; /*!< Target configuration version */
66+
const sector_info_t* sectors_info; /*!< Sector start and length list */
67+
uint32_t sector_info_length; /*!< Number of entries in the sectors_info array */
68+
region_info_t flash_regions[MAX_REGIONS]; /*!< Flash regions */
69+
region_info_t ram_regions[MAX_REGIONS]; /*!< RAM regions */
70+
const char *rt_board_id; /*!< If assigned, this is a flexible board ID */
71+
uint16_t rt_family_id; /*!< If assigned, this is a flexible family ID */
72+
uint8_t erase_reset; /*!< Reset after performing an erase */
73+
uint8_t pad;
74+
75+
//! @name CMSIS-DAP v2.1 target strings
76+
//@{
77+
char *target_vendor; /*!< Must match the Dvendor attribute value of the CMSIS DFP, excluding the
78+
colon and vendor code suffix when present. Maximum 60 characters including
79+
terminal NULL. */
80+
char *target_part_number; /*!< Part number of the target device. Must match the Dname attribute value
81+
of the device's CMSIS DFP. Maximum 60 characters including terminal NULL. */
82+
//@}
83+
} target_cfg_t;
84+
85+
extern target_cfg_t target_device;
86+
87+
88+
#endif

components/DAP/include/debug_cm.h

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/**
2+
* @file debug_cm.h
3+
* @brief Access to ARM DAP (Cortex-M) using CMSIS-DAP protocol
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#ifndef DEBUG_CM_H
23+
#define DEBUG_CM_H
24+
25+
#include "DAP.h"
26+
27+
// SWD register access
28+
#define SWD_REG_AP (1)
29+
#define SWD_REG_DP (0)
30+
#define SWD_REG_R (1<<1)
31+
#define SWD_REG_W (0<<1)
32+
#define SWD_REG_ADR(a) (a & 0x0c)
33+
34+
// Abort Register definitions
35+
#define DAPABORT 0x00000001 // DAP Abort
36+
#define STKCMPCLR 0x00000002 // Clear STICKYCMP Flag (SW Only)
37+
#define STKERRCLR 0x00000004 // Clear STICKYERR Flag (SW Only)
38+
#define WDERRCLR 0x00000008 // Clear WDATAERR Flag (SW Only)
39+
#define ORUNERRCLR 0x00000010 // Clear STICKYORUN Flag (SW Only)
40+
41+
// Debug Control and Status definitions
42+
#define ORUNDETECT 0x00000001 // Overrun Detect
43+
#define STICKYORUN 0x00000002 // Sticky Overrun
44+
#define TRNMODE 0x0000000C // Transfer Mode Mask
45+
#define TRNNORMAL 0x00000000 // Transfer Mode: Normal
46+
#define TRNVERIFY 0x00000004 // Transfer Mode: Pushed Verify
47+
#define TRNCOMPARE 0x00000008 // Transfer Mode: Pushed Compare
48+
#define STICKYCMP 0x00000010 // Sticky Compare
49+
#define STICKYERR 0x00000020 // Sticky Error
50+
#define READOK 0x00000040 // Read OK (SW Only)
51+
#define WDATAERR 0x00000080 // Write Data Error (SW Only)
52+
#define MASKLANE 0x00000F00 // Mask Lane Mask
53+
#define MASKLANE0 0x00000100 // Mask Lane 0
54+
#define MASKLANE1 0x00000200 // Mask Lane 1
55+
#define MASKLANE2 0x00000400 // Mask Lane 2
56+
#define MASKLANE3 0x00000800 // Mask Lane 3
57+
#define TRNCNT 0x001FF000 // Transaction Counter Mask
58+
#define CDBGRSTREQ 0x04000000 // Debug Reset Request
59+
#define CDBGRSTACK 0x08000000 // Debug Reset Acknowledge
60+
#define CDBGPWRUPREQ 0x10000000 // Debug Power-up Request
61+
#define CDBGPWRUPACK 0x20000000 // Debug Power-up Acknowledge
62+
#define CSYSPWRUPREQ 0x40000000 // System Power-up Request
63+
#define CSYSPWRUPACK 0x80000000 // System Power-up Acknowledge
64+
65+
// Debug Select Register definitions
66+
#define CTRLSEL 0x00000001 // CTRLSEL (SW Only)
67+
#define APBANKSEL 0x000000F0 // APBANKSEL Mask
68+
#define APSEL 0xFF000000 // APSEL Mask
69+
70+
// Access Port Register Addresses
71+
#define AP_CSW 0x00 // Control and Status Word
72+
#define AP_TAR 0x04 // Transfer Address
73+
#define AP_DRW 0x0C // Data Read/Write
74+
#define AP_BD0 0x10 // Banked Data 0
75+
#define AP_BD1 0x14 // Banked Data 1
76+
#define AP_BD2 0x18 // Banked Data 2
77+
#define AP_BD3 0x1C // Banked Data 3
78+
#define AP_ROM 0xF8 // Debug ROM Address
79+
#define AP_IDR 0xFC // Identification Register
80+
81+
// AP Control and Status Word definitions
82+
#define CSW_SIZE 0x00000007 // Access Size: Selection Mask
83+
#define CSW_SIZE8 0x00000000 // Access Size: 8-bit
84+
#define CSW_SIZE16 0x00000001 // Access Size: 16-bit
85+
#define CSW_SIZE32 0x00000002 // Access Size: 32-bit
86+
#define CSW_ADDRINC 0x00000030 // Auto Address Increment Mask
87+
#define CSW_NADDRINC 0x00000000 // No Address Increment
88+
#define CSW_SADDRINC 0x00000010 // Single Address Increment
89+
#define CSW_PADDRINC 0x00000020 // Packed Address Increment
90+
#define CSW_DBGSTAT 0x00000040 // Debug Status
91+
#define CSW_TINPROG 0x00000080 // Transfer in progress
92+
#define CSW_HPROT 0x02000000 // User/Privilege Control
93+
#define CSW_MSTRTYPE 0x20000000 // Master Type Mask
94+
#define CSW_MSTRCORE 0x00000000 // Master Type: Core
95+
#define CSW_MSTRDBG 0x20000000 // Master Type: Debug
96+
#define CSW_RESERVED 0x01000000 // Reserved Value
97+
#define CSW_SPROT 0x40000000 // SProt
98+
99+
// Core Debug Register Address Offsets
100+
#define DBG_OFS 0x0DF0 // Debug Register Offset inside NVIC
101+
#define DBG_HCSR_OFS 0x00 // Debug Halting Control & Status Register
102+
#define DBG_CRSR_OFS 0x04 // Debug Core Register Selector Register
103+
#define DBG_CRDR_OFS 0x08 // Debug Core Register Data Register
104+
#define DBG_EMCR_OFS 0x0C // Debug Exception & Monitor Control Register
105+
106+
// Core Debug Register Addresses
107+
#define DBG_HCSR (DBG_Addr + DBG_HCSR_OFS)
108+
#define DBG_CRSR (DBG_Addr + DBG_CRSR_OFS)
109+
#define DBG_CRDR (DBG_Addr + DBG_CRDR_OFS)
110+
#define DBG_EMCR (DBG_Addr + DBG_EMCR_OFS)
111+
112+
// Debug Halting Control and Status Register definitions
113+
#define C_DEBUGEN 0x00000001 // Debug Enable
114+
#define C_HALT 0x00000002 // Halt
115+
#define C_STEP 0x00000004 // Step
116+
#define C_MASKINTS 0x00000008 // Mask Interrupts
117+
#define C_SNAPSTALL 0x00000020 // Snap Stall
118+
#define S_REGRDY 0x00010000 // Register R/W Ready Flag
119+
#define S_HALT 0x00020000 // Halt Flag
120+
#define S_SLEEP 0x00040000 // Sleep Flag
121+
#define S_LOCKUP 0x00080000 // Lockup Flag
122+
#define S_RETIRE_ST 0x01000000 // Sticky Retire Flag
123+
#define S_RESET_ST 0x02000000 // Sticky Reset Flag
124+
#define DBGKEY 0xA05F0000 // Debug Key
125+
126+
// Debug Exception and Monitor Control Register definitions
127+
#define VC_CORERESET 0x00000001 // Reset Vector Catch
128+
#define VC_MMERR 0x00000010 // Debug Trap on MMU Fault
129+
#define VC_NOCPERR 0x00000020 // Debug Trap on No Coprocessor Fault
130+
#define VC_CHKERR 0x00000040 // Debug Trap on Checking Error Fault
131+
#define VC_STATERR 0x00000080 // Debug Trap on State Error Fault
132+
#define VC_BUSERR 0x00000100 // Debug Trap on Bus Error Fault
133+
#define VC_INTERR 0x00000200 // Debug Trap on Interrupt Error Fault
134+
#define VC_HARDERR 0x00000400 // Debug Trap on Hard Fault
135+
#define MON_EN 0x00010000 // Monitor Enable
136+
#define MON_PEND 0x00020000 // Monitor Pend
137+
#define MON_STEP 0x00040000 // Monitor Step
138+
#define MON_REQ 0x00080000 // Monitor Request
139+
#define TRCENA 0x01000000 // Trace Enable (DWT, ITM, ETM, TPIU)
140+
141+
// NVIC: Interrupt Controller Type Register
142+
#define NVIC_ICT (NVIC_Addr + 0x0004)
143+
#define INTLINESNUM 0x0000001F // Interrupt Line Numbers
144+
145+
// NVIC: CPUID Base Register
146+
#define NVIC_CPUID (NVIC_Addr + 0x0D00)
147+
#define CPUID_PARTNO 0x0000FFF0 // Part Number Mask
148+
#define CPUID_REVISION 0x0000000F // Revision Mask
149+
#define CPUID_VARIANT 0x00F00000 // Variant Mask
150+
151+
// NVIC: Application Interrupt/Reset Control Register
152+
#define NVIC_AIRCR (NVIC_Addr + 0x0D0C)
153+
#define VECTRESET 0x00000001 // Reset Cortex-M (except Debug)
154+
#define VECTCLRACTIVE 0x00000002 // Clear Active Vector Bit
155+
#define SYSRESETREQ 0x00000004 // Reset System (except Debug)
156+
#define VECTKEY 0x05FA0000 // Write Key
157+
158+
// NVIC: Debug Fault Status Register
159+
#define NVIC_DFSR (NVIC_Addr + 0x0D30)
160+
#define HALTED 0x00000001 // Halt Flag
161+
#define BKPT 0x00000002 // BKPT Flag
162+
#define DWTTRAP 0x00000004 // DWT Match
163+
#define VCATCH 0x00000008 // Vector Catch Flag
164+
#define EXTERNAL 0x00000010 // External Debug Request
165+
166+
// Data Watchpoint and Trace unit
167+
#define DWT_PCSR 0xe000101c // DWT PC Sampling Register
168+
169+
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @file flash_blob.h
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright 2019, Cypress Semiconductor Corporation
8+
* or a subsidiary of Cypress Semiconductor Corporation.
9+
* SPDX-License-Identifier: Apache-2.0
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
12+
* not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
24+
#ifndef FLASH_BLOB_H
25+
#define FLASH_BLOB_H
26+
27+
#include <stdint.h>
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
// Flags for program_target
34+
enum {
35+
kAlgoVerifyReturnsAddress = (1u << 0u), /*!< Verify function returns address if bit set */
36+
kAlgoSingleInitType = (1u << 1u), /*!< The init function ignores the function code. */
37+
kAlgoSkipChipErase = (1u << 2u), /*!< Skip region when erase.act action triggers. */
38+
};
39+
40+
typedef struct __attribute__((__packed__)) {
41+
uint32_t breakpoint;
42+
uint32_t static_base;
43+
uint32_t stack_pointer;
44+
} program_syscall_t;
45+
46+
typedef struct __attribute__((__packed__)) {
47+
const uint32_t init;
48+
const uint32_t uninit;
49+
const uint32_t erase_chip;
50+
const uint32_t erase_sector;
51+
const uint32_t program_page;
52+
const uint32_t verify;
53+
const program_syscall_t sys_call_s;
54+
const uint32_t program_buffer;
55+
const uint32_t algo_start;
56+
const uint32_t algo_size;
57+
const uint32_t *algo_blob;
58+
const uint32_t program_buffer_size;
59+
const uint32_t algo_flags; /*!< Combination of kAlgoVerifyReturnsAddress, kAlgoSingleInitType and kAlgoSkipChipErase*/
60+
} program_target_t;
61+
62+
typedef struct __attribute__((__packed__)) {
63+
const uint32_t start;
64+
const uint32_t size;
65+
} sector_info_t;
66+
67+
#ifdef __cplusplus
68+
}
69+
#endif
70+
71+
#endif

0 commit comments

Comments
 (0)