LPC2101

Hi!

Im running openocd version 2008-02-02 svn 279. I installed it as precompiled package from yagarto web page.

The part I’m working with at the moment is LPC2101. It has 8K of flash and 2K of RAM. I have specified the openocd config file as:


#define our ports

telnet_port 4444

gdb_port 3333

interface ft2232

ft2232_device_desc “dev A”

ft2232_layout usbjtag

jtag_speed 3

jtag_nsrst_delay 200

jtag_ntrst_delay 200

#reset_config [combination] [trst_type] [srst_type]

reset_config trst_and_srst

#jtag_device

jtag_device 4 0x1 0xf 0xe

#daemon_startup <‘attach’|‘reset’>

daemon_startup reset

#target <reset_mode> <jtag#> [variant]

target arm7tdmi little run_and_halt 0 arm7tdmi-s_r4

#run_and_halt_time <target#> <time_in_ms>

run_and_halt_time 0 30

flash bank lpc2000 0x00000000 0x00002000 0 0 0 lpc2000_v2 14745 calc_checksum

working_area 0 0x40000000 0x800 nobackup


Trying to flash the device from telnet fails.

(flash write 0 file.bin 0)

Openocd complains that there is not enough working area available. But I have specified the maximum size for working area… There is just no more ram available in that specific part…

Openocd output to the console:

Warning: target.c:563 target_alloc_working_area(): not enough working area available

Error: lpc2000.c:489 lpc2000_write(): no working area specified, can’t write LPC2000 internal flash

Is it normal behavior and is there any workaround for that problem?

Thank you,

Madis

The workaround is to let openocd have more memory.

The lpc flash driver needs minimum 4268 bytes at the last look.

Openocd only uses this while flashing the part so give it a nice 8/16k buffer.

It is released when openocd has finished with it.

Most people don’t but you can backup the working area: use backup instead of the nobackup option.

Cheers

Spen

Hi!

Thank you for your advice. But Im afraid that no more memory is available. That specific part (LPC2101) has only 2KB RAM on board. So I specified it:

working_area 0 0x40000000 0x800 nobackup

According to my understanding all the available memory (2K) is given for openocd now. So it can install its write routines or whatever it feels right…

Maybe Im totally misunderstanding something here…?

Thank you,

Madis

I have just looked at the data, openocd will need tweaking to support the 2k ram of this device.

As by default openocd requires more than this.

I can probably provide a patch if you can build and test openocd.

cheers

Spen

Ok. Most likely we will change to 2103 in our proto board. As I just happened to have those around.

About openocd. I can not test it here as I dont have suitable build environment. But during the weekend at my linux box I can try it.

Madis

Attached is a patch against svn 286

Let me know if it works and i will commit to svn

Index: src/flash/lpc2000.c
===================================================================
--- src/flash/lpc2000.c	(revision 286)
+++ src/flash/lpc2000.c	(working copy)
@@ -91,7 +91,10 @@
 int lpc2000_build_sector_list(struct flash_bank_s *bank)
 {
 	lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
-
+	
+	/* default to a 4096 write buffer */
+	lpc2000_info->cmd51_max_buffer = 4096;
+	
 	if (lpc2000_info->variant == 1)
 	{
 		int i = 0;
@@ -156,7 +159,12 @@
 		/* variant 2 has a uniform layout, only number of sectors differs */
 		switch (bank->size)
 		{
+			case 4 * 1024:
+				lpc2000_info->cmd51_max_buffer = 1024;
+				num_sectors = 1;
+				break;
 			case 8 * 1024:
+				lpc2000_info->cmd51_max_buffer = 1024;
 				num_sectors = 2;
 				break;
 			case 16 * 1024:
@@ -484,7 +492,7 @@
 	}
 	
 	/* allocate a working area */
-	if (target_alloc_working_area(target, 4096, &download_area) != ERROR_OK)
+	if (target_alloc_working_area(target, lpc2000_info->cmd51_max_buffer, &download_area) != ERROR_OK)
 	{
 		ERROR("no working area specified, can't write LPC2000 internal flash");
 		return ERROR_FLASH_OPERATION_FAILED;
@@ -533,8 +541,8 @@
 	while (bytes_remaining > 0)
 	{
 		u32 thisrun_bytes;
-		if (bytes_remaining >= 4096)
-			thisrun_bytes = 4096;
+		if (bytes_remaining >= lpc2000_info->cmd51_max_buffer)
+			thisrun_bytes = lpc2000_info->cmd51_max_buffer;
 		else if (bytes_remaining >= 1024)
 			thisrun_bytes = 1024;
 		else if ((bytes_remaining >= 512) || (!lpc2000_info->cmd51_can_256b))
Index: src/flash/lpc2000.h
===================================================================
--- src/flash/lpc2000.h	(revision 286)
+++ src/flash/lpc2000.h	(working copy)
@@ -32,6 +32,7 @@
 	int cmd51_can_256b;
 	int cmd51_can_8192b;
 	int calc_checksum;
+	int cmd51_max_buffer;
 } lpc2000_flash_bank_t;
 
 enum lpc2000_status_codes

Cheers

Spen