<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Hardware%2FEIR%2FOpenOCD%2FOptimize</id>
		<title>Hardware/EIR/OpenOCD/Optimize - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Hardware%2FEIR%2FOpenOCD%2FOptimize"/>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Hardware/EIR/OpenOCD/Optimize&amp;action=history"/>
		<updated>2026-04-28T22:51:26Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Hardware/EIR/OpenOCD/Optimize&amp;diff=402&amp;oldid=prev</id>
		<title>Harald: Created page with &quot;&lt;div id=&quot;content&quot;&gt;  = OpenOCD for AT91SAM7SE - Part 7 =  This is part 7 of our OpenOCD for AT91SAM7SE tutorial.  == Optimizing OpenOCD Configurations ==  Reme...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Hardware/EIR/OpenOCD/Optimize&amp;diff=402&amp;oldid=prev"/>
				<updated>2017-07-13T09:07:26Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;div id=&amp;quot;content&amp;quot;&amp;gt;  = OpenOCD for AT91SAM7SE - Part 7 =  This is part 7 of our &lt;a href=&quot;/nutwiki/index.php?title=Openocd.html&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Openocd.html (page does not exist)&quot;&gt;OpenOCD for AT91SAM7SE tutorial&lt;/a&gt;.  == Optimizing OpenOCD Configurations ==  Reme...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;div id=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= OpenOCD for AT91SAM7SE - Part 7 =&lt;br /&gt;
&lt;br /&gt;
This is part 7 of our [[openocd.html|OpenOCD for AT91SAM7SE tutorial]].&lt;br /&gt;
&lt;br /&gt;
== Optimizing OpenOCD Configurations ==&lt;br /&gt;
&lt;br /&gt;
Remember the flashy notes we got from OpenOCD when executing the &amp;lt;code&amp;gt;reset init&amp;lt;/code&amp;gt; command?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;coding&amp;quot;&amp;gt;NOTE! DCC downloads have not been enabled, defaulting to slow memory writes. Type 'help dcc'.&lt;br /&gt;
NOTE! Severe performance degradation without working memory enabled.&lt;br /&gt;
NOTE! Severe performance degradation without fast memory access enabled. Type 'help fast'.&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this part we will show how to increase the speed of the JTAG communication. Furthermore, we will discuss, how to re-organize our configuration to make it a bit more re-usable.&lt;br /&gt;
&lt;br /&gt;
=== Work Area ===&lt;br /&gt;
&lt;br /&gt;
As stated in the previous part, OpenOCD flash drivers may use the JTAG interface to present code and data to the CPU without using any real memory. Code and data is shifted into special JTAG registers located between the core and peripherals, which make the CPU think it got these values from real memory. This is sometimes quite helpful to get a virgin system running small code fragments. But it is also slow, because a large number of low level JTAG command are required. Specifically on low end JTAG adapters like the Turtelizer 2, the USB becomes a real bottleneck.&lt;br /&gt;
&lt;br /&gt;
Luckily, OpenOCD offers a solution, if we can provide some RAM on the target board. In this case, OpenOCD will not have to mimic each code and data memory access via lengthy register shifting, but can upload code and data into the work area and let the CPU access this area directly, without JTAG intervention. A few kilobytes are sufficient, which makes the internal SRAM of the AT91SAM7SE a good candidate.&lt;br /&gt;
&lt;br /&gt;
It's quite obvious, that the related configuration is part of the debug target and, as such, needs to be added to the &amp;lt;code&amp;gt;target create&amp;lt;/code&amp;gt; command. It turned out later, that this is somewhat inflexible. While the debug target needs to be declared during the configuration stage and can be declared once only, it is sometimes required to setup the work area after certain hardware initializations took place. In addition, it is often required to select different work areas for different tasks. Note, that the work area occupies memory and may clash with other firmware already running on the target.&lt;br /&gt;
&lt;br /&gt;
OpenOCD allows dynamic configuration of certain debug target parameters via the &amp;lt;code&amp;gt;configure&amp;lt;/code&amp;gt; command, which must be prepended by the dotted name of the related debug target. To allow OpenOCD to use the last 8kBytes of internal SRAM as a work area, we define&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;coding&amp;quot;&amp;gt;sam7se512.cpu configure -work-area-phys 0x00206000 -work-area-size 0x4000&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can add this line to openocd.cfg now.&lt;br /&gt;
&lt;br /&gt;
=== Debug Communication Channel ===&lt;br /&gt;
&lt;br /&gt;
Even if we have established a work area on the target, filling this with data or code via JTAG shifting is still cumbersome. Some CPUs, including the AT91SAM7SE, provide a UART like JTAG interface named debug communication channel, or just DCC, which is much easier to handle than the JTAG state machine. The following command tells OpenOCD to make use of the DCC:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;coding&amp;quot;&amp;gt;arm7_9 dcc_downloads enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
Unfortunately, this may not work on targets running at low speed. In our case it will probably not work until we switched the main clock to be fed by the PLL. Do not add this line to openocd.cfg now. We will soon see, where the best place for this configuration is.&lt;br /&gt;
&lt;br /&gt;
=== Fast Memory Access ===&lt;br /&gt;
&lt;br /&gt;
Frankly, I have no idea, what the following configuration internally works:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;coding&amp;quot;&amp;gt;arm7_9 fast_memory_access enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it significantly increases the transfer rate between the PC and the target. Again, this may not work at slow CPU clocks and we will soon add it at the right place within openocd.cfg.&lt;br /&gt;
&lt;br /&gt;
=== Increasing the JTAG Clock ===&lt;br /&gt;
&lt;br /&gt;
This is not new, we already set the JTAG clock in our current openocd.cfg. However, as soon as we have the CPU running at 48kHz, we should increase the JTAG clock as well. And, we can also all the other optimizations, which are not working reliable at slow clocks. The right place is, you guessed it, the reset-init handler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;coding&amp;quot;&amp;gt;# Initialize the EIR board.&lt;br /&gt;
#&lt;br /&gt;
proc eir_init {} {&lt;br /&gt;
        eir_init_clock&lt;br /&gt;
&lt;br /&gt;
        # Minimum ICE cycle time is 102ns (9800 kHz)&lt;br /&gt;
        adapter_khz 9800&lt;br /&gt;
        arm7_9 dcc_downloads enable&lt;br /&gt;
        arm7_9 fast_memory_access enable&lt;br /&gt;
&lt;br /&gt;
        eir_init_membus&lt;br /&gt;
        eir_init_sdram&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally we have now a complete OpenOCD configuration for our EIR board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;coding&amp;quot;&amp;gt;interface turtle&lt;br /&gt;
ft2232_layout turtelizer2&lt;br /&gt;
ft2232_device_desc &amp;amp;quot;Turtelizer JTAG/RS232 Adapter&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
reset_config srst_only&lt;br /&gt;
adapter_khz 8&lt;br /&gt;
&lt;br /&gt;
jtag newtap sam7se512 cpu -irlen 4 -expected-id 0x3f0f0f0f&lt;br /&gt;
target create sam7se512.cpu arm7tdmi -chain-position sam7se512.cpu&lt;br /&gt;
sam7se512.cpu configure -work-area-phys 0x00206000 -work-area-size 0x4000&lt;br /&gt;
&lt;br /&gt;
flash bank sam7se512.flash.0 at91sam7 0 0 0 0 sam7se512.cpu 0 0 0 0 0 0 0 18432&lt;br /&gt;
flash bank sam7se512.flash.1 at91sam7 0 0 0 0 sam7se512.cpu 1 0 0 0 0 0 0 18432&lt;br /&gt;
&lt;br /&gt;
sam7se512.cpu configure -event reset-init { eir_init }&lt;br /&gt;
&lt;br /&gt;
# Initialize the EIR board.&lt;br /&gt;
#&lt;br /&gt;
proc eir_init {} {&lt;br /&gt;
        eir_init_clock&lt;br /&gt;
&lt;br /&gt;
        # Minimum ICE cycle time is 102ns (9800 kHz)&lt;br /&gt;
        adapter_khz 9800&lt;br /&gt;
        arm7_9 dcc_downloads enable&lt;br /&gt;
        arm7_9 fast_memory_access enable&lt;br /&gt;
&lt;br /&gt;
        eir_init_membus&lt;br /&gt;
        eir_init_sdram&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Initialize the EIR clocks.&lt;br /&gt;
#&lt;br /&gt;
# The board uses an 18.432MHz crystal.&lt;br /&gt;
# Let the CPU run at 48MHz.&lt;br /&gt;
#&lt;br /&gt;
proc eir_init_clock {} {&lt;br /&gt;
&lt;br /&gt;
        # Enable main oscillator.&lt;br /&gt;
        #&lt;br /&gt;
        # Start-up time of 6 x 8 slow clocks.&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xfffffc20 0x00000601       ;# CKGR_MOR&lt;br /&gt;
        sleep 2&lt;br /&gt;
&lt;br /&gt;
        # Configure the PLL.&lt;br /&gt;
        #&lt;br /&gt;
        # 18.432MHz * (72 + 1) / 14 = 96MHz&lt;br /&gt;
        #&lt;br /&gt;
        # Divider 14 (0x0e)&lt;br /&gt;
        # Start-up time of 28 (0x1c) slow clocks&lt;br /&gt;
        # Multiplier 72 (0x48)&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xfffffc2C 0x00481c0e       ;# CKGR_PLLR&lt;br /&gt;
        sleep 1&lt;br /&gt;
&lt;br /&gt;
        # Select PLL clock and divide it by 2&lt;br /&gt;
        #&lt;br /&gt;
        # 96MHz / 2 = 48MHz&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xfffffc30 0x00000007       ;# PMC_MCKR&lt;br /&gt;
        sleep 1&lt;br /&gt;
&lt;br /&gt;
        # 1 wait for read, 2 waits for write&lt;br /&gt;
        # We have 48 master clocks in 1us&lt;br /&gt;
        mww 0xffffff60 0x00480100       ;# MC_FMR&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Initialize external memory bus.&lt;br /&gt;
#&lt;br /&gt;
proc eir_init_membus {} {&lt;br /&gt;
        # Enable address bus (A0, A2-A11, A13-A17) at PIO B&lt;br /&gt;
        mww 0xfffff674 0x0003effd ;# PIOB_BSR&lt;br /&gt;
        mww 0xfffff604 0x0003effd ;# PIOB_PDR&lt;br /&gt;
&lt;br /&gt;
        # Enable 16 bit data bus at PIO C&lt;br /&gt;
        mww 0xfffff870 0x0000ffff ;# PIOC_ASR&lt;br /&gt;
        mww 0xfffff804 0x0000ffff ;# PIOC_PDR&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Initialize the EIR SDRAM.&lt;br /&gt;
#&lt;br /&gt;
# EIR uses Samsung K4S511632D-UC75 SDRAM:&lt;br /&gt;
# Organization: 32M x 16&lt;br /&gt;
# 8k rows, 1k columns&lt;br /&gt;
# 20ns row precharge time&lt;br /&gt;
# 45ns min. and 100us max. row active time&lt;br /&gt;
#&lt;br /&gt;
# MCK cycle is 20ns when running at 48MHz.&lt;br /&gt;
#&lt;br /&gt;
proc eir_init_sdram {} {&lt;br /&gt;
&lt;br /&gt;
        # Enable SDRAM control at PIO A&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xfffff474 0x3f800000 ;# PIOA_BSR&lt;br /&gt;
        mww 0xfffff404 0x3f800000 ;# PIOA_PDR&lt;br /&gt;
&lt;br /&gt;
        # Enable SDRAM chip select&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffff80 0x00000002 ;# EBI_CSA&lt;br /&gt;
&lt;br /&gt;
        # Set SDRAM characteristics in configuration register.&lt;br /&gt;
        # At 48MHz 1 cycle is about 21ns.&lt;br /&gt;
        #&lt;br /&gt;
        # 0x00000003 NC: Number of column bits&lt;br /&gt;
        # 0x00000002 10 bits, 1k columns&lt;br /&gt;
        #&lt;br /&gt;
        # 0x0000000C NR: Number of row bits&lt;br /&gt;
        # 0x00000008 13 bits, 8k rows&lt;br /&gt;
        #&lt;br /&gt;
        # 0x00000010 NB: Number of banks&lt;br /&gt;
        # 0x00000010 4 banks&lt;br /&gt;
        #&lt;br /&gt;
        # 0x00000060 CAS: CAS latency&lt;br /&gt;
        # 0x00000040 2 cycles&lt;br /&gt;
        #&lt;br /&gt;
        # 0x00000780 TWR: Write recovery delay&lt;br /&gt;
        # 0x00000100 2 cycles&lt;br /&gt;
        #&lt;br /&gt;
        # 0x00007800 TRC: Row cycle delay&lt;br /&gt;
        # 0x00002000 4 cycles&lt;br /&gt;
        #&lt;br /&gt;
        # 0x00078000 TRP: Row precharge delay&lt;br /&gt;
        # 0x00020000 4 cycles&lt;br /&gt;
        #&lt;br /&gt;
        # 0x00780000 TRCD: Row to column delay&lt;br /&gt;
        # 0x00100000 2 cycles&lt;br /&gt;
        #&lt;br /&gt;
        # 0x07800000 TRAS: Active to precharge delay&lt;br /&gt;
        # 0x01800000 3 cycles&lt;br /&gt;
        #&lt;br /&gt;
        # 0x78000000 TXSR: Exit self refresh to active delay&lt;br /&gt;
        # 0x20000000 4 cycles&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffffb8 0x2192215a ;# SDRAMC_CR&lt;br /&gt;
        sleep 10&lt;br /&gt;
&lt;br /&gt;
        # Issue 16 bit SDRAM command: NOP&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffffb0 0x00000011 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
&lt;br /&gt;
        # Issue 16 bit SDRAM command: Precharge all&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffffb0 0x00000012 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
&lt;br /&gt;
        # Issue 8 auto-refresh cycles&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
        mww 0xffffffb0 0x00000014 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000000&lt;br /&gt;
&lt;br /&gt;
        # Issue 16 bit SDRAM command: Set mode register&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffffb0 0x00000013 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000014 0xcafedede&lt;br /&gt;
&lt;br /&gt;
        # Set refresh rate count ???&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffffb4 0x00000013 ;# SDRAMC_TR&lt;br /&gt;
&lt;br /&gt;
        # Issue 16 bit SDRAM command: Normal mode&lt;br /&gt;
        #&lt;br /&gt;
        mww 0xffffffb0 0x00000010 ;# SDRAMC_MR&lt;br /&gt;
        mww 0x20000000 0x00000180&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Harald</name></author>	</entry>

	</feed>