AN10986 help with LPC1347

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

AN10986 help with LPC1347

586 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ECamino on Fri Feb 01 07:42:59 MST 2013
Hi,

We want to use "Automating entry of USB ISP" as described in AN10986, section 5.  We are trying to use code from the software example "autoisp_main.c".  But this doesn't seem to work on an LPC1347.  Why doesn't this code allow "programmatic entry into [USB] ISP" and is it possible to do this on an LPC1347?

/* This data must be global so it is not read from the stack */
typedef void (*IAP)(uint32_t [], uint32_t []);
IAP iap_entry = (IAP)0x1fff1ff1;
uint32_t command[5], result[4];
#define init_msdstate() *((uint32_t *)(0x10000054)) = 0x0
void ReinvokeISP(void)
{
  /* make sure USB clock is turned on before calling ISP */
  LPC_SYSCON->SYSAHBCLKCTRL |= 0x04000;
  /* make sure 32-bit Timer 1 is turned on before calling ISP */
  LPC_SYSCON->SYSAHBCLKCTRL |= 0x00400;
  /* make sure GPIO clock is turned on before calling ISP */
  LPC_SYSCON->SYSAHBCLKCTRL |= 0x00040;
  /* make sure IO configuration clock is turned on before calling ISP */
  LPC_SYSCON->SYSAHBCLKCTRL |= 0x10000;
  /* make sure AHB clock divider is 1:1 */
  LPC_SYSCON->SYSAHBCLKDIV = 1;
  /* Send Reinvoke ISP command to ISP entry point*/
  command[0] = 57;
  init_msdstate();      /* Initialize Storage state machine */
  /* Set stack pointer to ROM value (reset default) This must be the last
     piece of code executed before calling ISP, because most C expressions
     and function returns will fail after the stack pointer is changed. */
  __set_MSP(*((uint32_t *)0x1FFF0000)); /* inline asm function */
  /* Enter ISP. We call "iap_entry" to enter ISP because the ISP entry is done
     through the same command interface as IAP. */
  iap_entry(command, result);
  // Not supposed to come back!
}
0 Kudos
6 Replies

490 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ddowling on Tue May 07 04:51:19 MST 2013
I am trying to get ISP working on an LPC1347 as well. No luck so far. Is it critical to have ReinvokeISP called from main() or should the stack setting code work as well?
0 Kudos

490 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by BPC on Mon Feb 04 17:13:21 MST 2013
This issue was resolved by disabling the interrupt and reset for Timer 32-0 and Timer 32-1 prior to calling ReinvokeISP.

[SIZE=3]pUsbApi->[COLOR=#0000c0][COLOR=#0000c0]hw[/COLOR][/COLOR]->[COLOR=#0000c0][COLOR=#0000c0]Connect[/COLOR][/COLOR](hUsb, 0);  [COLOR=green]//Soft Disconnect from USB[/COLOR][/SIZE]
LPC_CT32B0->[COLOR=#0000c0][COLOR=#0000c0]MCR[/COLOR][/COLOR] = 0;  [COLOR=#008000]//Disable Timer 32-0 Interrupt and Reset[/COLOR]
LPC_CT32B1->[COLOR=#0000c0][COLOR=#0000c0]MCR[/COLOR][/COLOR] = 0;  [COLOR=#008000]//Disable Timer 32-1 Interrupt and Reset[/COLOR]
0 Kudos

490 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by BPC on Mon Feb 04 15:12:41 MST 2013
Thanks for the update.  One more question.

I am using the LPC1347 as a CDC device.  If I call ReinvokeISP prior to connecting to USB pUsbApi->[COLOR=#0000c0][COLOR=#0000c0]hw[/COLOR][/COLOR]->[COLOR=#0000c0][COLOR=#0000c0]Connect[/COLOR][/COLOR](hUsb, 1) then it works perfectly.

However, if I call ReinvokeISP after connecting, nothing happens.

I have tried doing a disconnect pUsbApi->[COLOR=#0000c0][COLOR=#0000c0]hw[/COLOR][/COLOR]->[COLOR=#0000c0][COLOR=#0000c0]Connect[/COLOR][/COLOR](hUsb, 0) prior to calling ReinvokeISP, but with no success.

Any ideas?
0 Kudos

490 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ECamino on Mon Feb 04 09:37:57 MST 2013
Here's how to do this for a ~40s time out:

#define WDTCLK_SRC_WDT_OSC 1
#define wdt_time 40 // 40 seconds
#define WDTCLK_FREQ 500000 // 500kHz
#define IAP_LOCATION 0x1FFF1FF1
typedef void (*IAP)(unsigned long[], unsigned long[]);
IAP iap_entry;

In main, call these two when you want to enter bootloader and set the wwdt to reset the device:

SetWDTReset(wdt_time);
<turn on clockout or led if you'd like>
ReinvokeISP();

void ReinvokeISP(void)
{
// make sure USB clock is turned on before calling ISP
LPC_SYSCON->SYSAHBCLKCTRL |= 0x04000;
// make sure 32-bit Timer 1 is turned on before calling ISP
LPC_SYSCON->SYSAHBCLKCTRL |= 0x00400;
// make sure GPIO clock is turned on before calling ISP
LPC_SYSCON->SYSAHBCLKCTRL |= 0x00040;
// make sure IO configuration clock is turned on before calling ISP
LPC_SYSCON->SYSAHBCLKCTRL |= 0x10000;
// make sure AHB clock divider is 1:1
LPC_SYSCON->SYSAHBCLKDIV = 1;
unsigned long command[5];
unsigned long result[4];
iap_entry = (IAP) IAP_LOCATION;
command[0] = 57;
iap_entry(command, result);
}

void SetWDTReset(uint32_t s)
{
/* make sure WDT config clock is turned on */
LPC_SYSCON->SYSAHBCLKCTRL |= 0x08000;
// set up wdt_osc_clk for .5MHz,
LPC_SYSCON->WDTOSCCTRL = (0x7<<5) |(0x1);
/* Enable internal wd_oscillator clock */
LPC_SYSCON->PDRUNCFG &= ~(64); // power up wd oscillator
LPC_WWDT->CLKSEL = WDTCLK_SRC_WDT_OSC;
LPC_WWDT->TC = (WDTCLK_FREQ/4) * s; // TC = 4C 4B40 ~40sec wd timeout
/* Enable watchdog, and arm it to generate a reset upon timeout */
LPC_WWDT->MOD = 0x3;
/* Send watchdog "feed" sequence- final step to begin the timeout */
LPC_WWDT->FEED = 0xAA;
LPC_WWDT->FEED = 0x55;
}
0 Kudos

490 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ECamino on Fri Feb 01 12:03:54 MST 2013
We hope there is a way to enter the MSD bootloader from the application on the LPC1347.  The LPC1343 probably won't have enough memory for our application.  Porting code from LPC1347 to LPC1343 would be a lot of work too, as the two parts are so different!

EC
0 Kudos

490 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Fri Feb 01 07:48:10 MST 2013
This application note has been written before release of the LPC1347. So the code will work on a LPC1343 for example. The difference between the two is that for LPC1347 all USB drivers are in ROM. So you will have to port the code to use the ROM-drivers in the LPC1347. Maybe Tsuneo can point you in the right direction.
0 Kudos