# Olimex LPC-P2919
# http://www.olimex.com/

# Delays on reset lines
jtag_nsrst_delay 50
jtag_ntrst_delay 1

# Maximum of 1/8 of clock frequency (XTAL = 16 MHz).
# Adaptive clocking through RTCK is not supported.
jtag_khz 2000

# Target device: LPC29xx with ETB
# The following variables are used by the LPC2900 script:
#   HAS_ETB             Must be set to 1. The CPU on this board has ETB.
#   FLASH_CLOCK         CPU frequency at the time of flash programming (in kHz)
set HAS_ETB             1
set FLASH_CLOCK         112000
source [find target/lpc2900.cfg]

# A working area will help speeding the flash programming
$_TARGETNAME configure -work-area-phys 0x80000000 -work-area-size 0x2000 -work-area-backup 0

# Event handlers
$_TARGETNAME configure -event reset-start {
  # Back to the slow JTAG clock
  jtag_khz 2000
}

# External 16-bit flash at chip select CS7 (SST39VF3201-70, 4 MiB)
#flash bank cfi 0x5C000000 0x400000 2 2 $_TARGETNAME jedec_probe


$_TARGETNAME configure -event reset-init {
  # Flash
  mww 0x20200010 0x00000007     # FBWST: 7 wait states, not chached

  # Use PLL
  mww 0xFFFF8020 0x00000001     # XTAL_OSC_CONTROL: enable, 1-20 MHz
  mww 0xFFFF8070 0x01000000     # SYS_CLK_CONF: Crystal
  mww 0xFFFF8028 0x00000005     # PLL: (power down)
  mww 0xFFFF8028 0x01060004     # PLL: M=7, 2P=2 (power up)
                                # --> f=112 MHz, fcco=224 MHz
  sleep 100
  mww 0xFFFF8070 0x02000000     # SYS_CLK_CONF: PLL

  # Increase JTAG speed
  jtag_khz 6000
}

