This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC2300 LPC2368 Reinvoke ISP from user code

Hi,

I am trying to get an LPC2368 to reinvoke the ISP from user code, and although there is a good application note for the LPC2100 chips, I can't find anything for the LPC2300 ones.

I have found some code for an LPC2458 (below), but I'm not sure what compiler it's for, (it doesn't compile in uVision MDK-ARM V4.10), and I'm not sure it's even suitable for the LPC2368. I have read that the SP is not writeable in inline assembly... So I'm quite lost.

I've read the UM, and it makes it sound quite simple; one command does it all, but it seems like I still need to use inline assy to run said command.

I was hoping to find a code snippet online; I'd imagine the 'reinvoke-isp' function to be highly re-usable for any LPC2300 application..? But no luck..

If anyone has managed to get it going, I'd really appreciate a pointer (no pun intended), or even a function to copy & paste (I can dream..).

Thanks in advance

Nat

=========================================

LPC2458 Code:

void iap_cmd_reinvoke_isp(void) {
// Ensure fast I/O is supported.
SCS |= 1;

// Disconnect PLL.
PLLCON = 0x00;
PLLFEED = 0xAA;
PLLFEED = 0x55;

// Set IRC as the clock source.
CLKSRCSEL = 0x00;
// CCLK divider = 0 (CCLK = 4MHz)
CCLKCFG = 0x00;

__asm("ldr r0, =spval\n\t" /* Set the stack pointer */
"ldr sp, [r0]\n\t" /* to the end of (SRAM - 32) */
"ldr r0, =iapcommand\n\t" /* Enter ISP mode (via IAP) */
"ldr r2, =iapentry\n\t"
"ldr r2, [r2]\n\t"
"bx r2\n\n"
"spval: .word 0x40007FE0\n\t" /* SRAM - 32 */
"iapentry: .word 0x7FFFFFF1\n\t" /* Address of IAP function (Thumb) */
"iapcommand: .word 57"); /* IAP command 57 (Reinvoke ISP) */
}

Parents Reply Children
  • Thanks for the fast reply!

    It's for the Keil compiler.

    If I start playing with startup.s, won't that prevent the 'Configuration Wizard' from working properly?

    Is it that it's not possible to do it inline, or is it just your preference to keep it in startup.s?

  • The configuration wizard doesn't understand assembler.

    It just read source code comments to create the menu system.
    It then sets the value of parameters that are either used by the assembler instructions, or that controls conditional compilation.

    But you can make serious edits of the startup file and still maintain the use of the configuration wizard.

  • Thanks again for your help.

    I've got the C code successfully calling a function in a assembly file, and that all compiles. I've also attempted to implement the LPC2458 code, which as far as I can see should work for the the LPC2368, (The IAP entry point and command are correct, and the stack pointer is being set to 32 bytes from the top of the 32k of on chip SRAM (both the 2368 and 2458 have 32k I think)

    The bootloader is not being re-invoked however. I know my set up is ok as I can invoke the bootloader by holding P2.10 low on reset and successfully program it this way, so it must be falling over when trying to re-invoke it from my code. (The processor does hang when I call reinvoke_isp() so it's doing something.)

    I've added the code I'm using below. (I've made a separate .s file for this function, rather than putting it in the startup.s)

    ==================== C Code

    void reinvoke_isp(void)
    { // Ensure fast I/O is supported. SCS |= 1;

    // Disconnect PLL. PLLCON = 0x00; PLLFEED = 0xAA; PLLFEED = 0x55;

    // Set IRC as the clock source. CLKSRCSEL = 0x00; // CCLK divider = 0 (CCLK = 4MHz) CCLKCFG = 0x00;

    reinvoke_isp_asm();

    }

    ===================== ASM Code

    AREA asm_func, CODE, READONLY
    ; Export my_asm function location so that C compiler can find it and link EXPORT reinvoke_isp_asm
    reinvoke_isp_asm

    ldr r0, =0x40007FE0 ;Set the stack pointer to the end of (SRAM - 32) ldr sp, [r0] ldr r0, =57 ;Enter ISP mode (via IAP) - IAP command 57 ldr r2, =0x7FFFFFF1 ;Address of IAP function (Thumb) ldr r2, [r2] bx r2

    END