 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Can you please share the source code. Actually i'm trying to build SWD using GPIOs.
You can get the source to CMSIS-DAP here: CMSIS/CMSIS/DAP/Firmware/Source at master · ARM-software/CMSIS · GitHub
Thanks for your reply. I will go through the link.
 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		| This command must be executed before executing "Copy RAM to Flash" or "Erase Sector(s)" command. Successful execution of the "Copy RAM to Flash" or "Erase Sector(s)" command causes relevant sectors to be protected again. To prepare a single sector use the same "Start" and "End" sector numbers. | 
 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		| tmp = 0xFFFFFFFF; for (p = start, n = wordCount; n--; ) tmp &= *p++; return(tmp == 0xFFFFFFFF? good: ohPooh); | 
| ;-----------------------------------------------------------------------!
; Erase Flash!
;-----------------------------------------------------------------------!
; r0 = start sector, r1 = sector count
fn FLZap
push{r7,lr};
ldrr7, =cmdBuff;
strr0, [r7, 1*4]; stash first sector
addsr0, r1; calc last sector
subsr0, 1; first+count-1
strr0, [r7, 2*4]; stash last sector
ldrr0, =clkKHz; get   clock speed
strr0, [r7, 3*4]; stash clock speed
;---------------------------------------;
movsr0, 53; blank check
strr0, [r7];
movsr0, r7; 'in'  parameters
addsr1, r7,  5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
cbzr0, 9f; skip erase if blank
;---------------------------------------;
movsr0, 50; prepare
strr0, [r7];
movsr0, r7; 'in'  parameters
addsr1, r7,  5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
cbnzr0, 9f; OOPS -- IAP failed
movsr0, 52; erase
strr0, [r7];
movsr0, r7; 'in'  parameters
addsr1, r7,  5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
cmpr0, 11; is it lying about being 'busy'?
bne9f; nope
;---------------------------------------;
movsr0, 53; yup -- is it actually blank?
strr0, [r7];
movsr0, r7; 'in'  parameters
addsr1, r7,  5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
;cbnzr0, 9f; OOPS -- IAP failed
;---------------------------------------;
9:pop{r7,pc}; return (zero == success)
fe FLZap
;-----------------------------------------------------------------------!
; IAP Invoke Wrapper!
;-----------------------------------------------------------------------!
fn GoIAP
push{lr};
ldrr12, =IAP; get abs entry point
cpsidi; let's try disabling interrupts
blxr12; go IAP
cpsiei; and re-enable
pop{pc}; return
fe GoIAP
 | 
 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		| Initializing SWD. The SWD protocol allows full control of an LPC microcontroller. Because of this, it is critical that the port be insensitive to noise under a wide range of design conditions. To make the SWD port insensitive to noise, an unlock or connection sequence must be executed before the port can be used. The unlock sequence consists of several different steps. SWD Unlock Sequence Steps step numberdescription 1The Host needs to switch the target from JTAG to SWD mode by clocking 0xE79E onto SWDCLK/SWDIO 2SWD connection sequence- clock out more than 50 binary 1s 3Must read the Debug Port IDCODE register (address 0) 4Turn on Debug Port by settings bits 28 and 30 at DP address 4 5Write AP select (debug port address 8) to 0xF0 (to prep for AP read of 0xFC) 6Unlock Access Port by reading AP ID register (AP address 0xFC) | 
 
					
				
		
 lpcware
		
			lpcware
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		