JTAG / SWD Documentation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JTAG / SWD Documentation

15,057 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by v0ynich on Thu Nov 13 11:50:17 MST 2014
Hello,

I'm looking for documentation regarding JTAG or SWD for programming an LPC4337. I wish to program this device using another microcontroller. In my case, USART0 and USART3 are not available for IAP. If you could send me in the right direction I would appreciate.

Thank you
Labels (1)
0 Kudos
Reply
32 Replies

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Nov 24 07:25:49 MST 2014
Yes, you can read and write to RAM.

This sequence *may* work but it depends on how you are going to trap the return from the IAP routine(s). You are going to need a stack setup (and therefore the SP) and push a return address so that the IAP can return to something.

You may find it easier to download a small piece of ram-based code that actually makes the IAP calls for you. It can spin in a while(1) loop on completion enabling you to either set (and handle) a breakpoint on the return, or you could repeatedly read the PC to see if it returned to your while loop. This also has the advantage that you can debug the code (using a conventional debugger) before attempting to debug your JTAG/SWD code.
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by v0ynich on Mon Nov 24 06:27:53 MST 2014
Thank you for the clarification. This kind of detailed information is really appreciated.


Quote:
The debug logic itself also has no hardwired functionality to do operations on the flash


But it can read/write to RAM, right?

Then let's assume that I want to use this approach:

Quote:
If you connect with JTAG, then you can use this interface to download an executable code to the ARM, which is then running this code, in order to stream some data over the JTAG channel and provide it to the flash programming API.



Please check if this is what I need to do:

1- "Allocate" RAM space for the iap_cmd and iap_res arrays
2- Write on R0 and R1 the addresses of iap_cmd and iap_res arrays
3- Call IAP with ERASE_SECTOR command
4- Check erasing progress (wait for return)
5- "Allocate" and write to RAM segments of the code that I want to flash
6- Call IAP with COPY_RAM_TO_FLASH command
7- Check flashing progress (wait for return)

Thank you
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bavarian on Mon Nov 24 05:55:04 MST 2014
I think this requires some clarification:

[list]
  [*]  The internal flash is not connected in any way to the JTAG or SWD debug logic
  [*]  The debug logic itself also has no hardwired functionality to do operations on the flash
[/list]

As already pointed out:

[list]
  [*]  The only way to program the flash is to use the code which resides in the ROM of the LPC4300.
  [*]  The bootloader also uses this flash programming API to program the data it gets from one of the boot interfaces, for example from UART or USB.
  [*]  If you connect with JTAG, then you can use this interface to download an executable code to the ARM, which is then running this code, in order to stream some data over the JTAG channel and provide it to the flash programming API.
  [*]  So whatever you do, you always let the Cortex-M4 do the job, whatever type of interface you use for getting the data in.
[/list]

The hints to look into the specs from ARM are totally right, it's the only way to start. Then you could also look into this thread:

http://www.lpcware.com/content/forum/lpc1857-jtag-host-not-slave

Regards,
NXP Support Team. 
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by v0ynich on Mon Nov 24 05:05:43 MST 2014
Thank you for the info.

At this moment I'm not being able to find which register I should access (using TAR and DRW) to erase the flash in the LPC4337.

Thank you
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Wed Nov 19 04:54:08 MST 2014
The place to start is to read the ARM 'Coresight' documentation for the Cortex-M4. This is provided by ARM on their website. And, as mentioned previously, (subject to license) you may be able to use the mbed HDK.
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by v0ynich on Wed Nov 19 03:49:59 MST 2014
Hello,

I understand that it is not an easy task. Could you please forward me to some documentation ragarding this?

Thank you
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Nov 14 03:48:38 MST 2014

Quote: v0ynich
How does the debugger downloads the application ?



http://www.lpcware.com/content/blog/introduction-cortex-serial-wire-debugging-part-one
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Nov 14 03:48:29 MST 2014
It downloads via SWD or JTAG.

Assuming that you really do want to try to download a program into flash via SWD or JTAG, then you are basically going to have to implement most of the functionality of a debugger (gain control of the CPU, download data into RAM, setup the registers, start executing the program). Then you are going to need to communicate with that program to send it data and tell it to program the flash with the data that you send it.

Or, you might want to rethink what you are trying to do here...
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by v0ynich on Fri Nov 14 03:15:32 MST 2014

Quote: lpcxpresso-support
So, to do this, you are going to need to download an application that then runs to program the flash. This is exactly how a debugger programs flash.



Ok, perhaps I'm confused with the nomenclature. How does the debugger downloads the application ? In other words, what I'm trying to achieve is to mimic the flashing function of the debugger. I have the pins that I use to program the LPC4337 with the debugger also connected to another micro controller. This micro controller should be able to re-program the LPC4337 with new firmware.

Thank you
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Nov 13 15:48:23 MST 2014
The only way to program internal flash  is through the IAP. There is nothing available through the Debug interface. So, to do this, you are going to need to download an application that then runs to program the flash. This is exactly how a debugger programs flash.

If you really want to go ahead with this, and it is not recommended and is a lot of work, you could start by looking at ARMs CMSIS-DAP. I understand that you can also get an implementation from ARM via mbed and the HDK.
0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by v0ynich on Thu Nov 13 15:00:31 MST 2014
Thank you!

That's a start point. However I'm still struggling to find the commands for flash segment erasing, programming, reading, etc..
As far as I understand, this "Coresight" is the module responsible for handling the JTAG and SWD functions, right?

0 Kudos
Reply

2,583 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mysepp on Thu Nov 13 13:25:23 MST 2014
I don't know if there is something ready to use, it is no easy task.
Have a look here for more detailed information (go down the tree on left side):

Google for "ddi0314h" (complete link is not accepted by spam filter, sorry)
0 Kudos
Reply