O'key. I found the problem.
I don't know why, but if I change this line
__set_MSP( * ( (uint32_t *) 0x1FFF0000 ) );
to this one
__set_MSP( * ( (uint32_t *) 0x00000000 ) );
and USB bootloader running!
BUT, if I apply optimization by size, the USB bootloader not running.
I think it is because a BUG in compiler in LPCXpresso 8.2.2 that I use.
I find WORKAROUND for this BUG, I use volatile value assigned to zero, like this:
volatile uint32_t topOfStack = 0;
__set_MSP( * ( (uint32_t *) topOfStack) );
I prefer to use _vStackTop value defined in linker script:
.....
PROVIDE(_vStackTop = DEFINED(__user_stack_top) ? __user_stack_top : __top_Ram);
.....
So finally, this is my ReInvokeISP function that run on LPC1347 with ANY optimization:
.....
#define init_msdstate() *((uint32_t *)(0x10000054)) = 0x00000000
extern void _vStackTop(void);
.......
void ReInvokeISP()
{
/* Disable IRQ specific interrupts */
/* DON'T use __disable_irq() */
NVIC_DisableIRQ(PIN_INT0_IRQn);
NVIC_DisableIRQ(PIN_INT1_IRQn);
NVIC_DisableIRQ(PIN_INT2_IRQn);
NVIC_DisableIRQ(PIN_INT3_IRQn);
NVIC_DisableIRQ(PIN_INT4_IRQn);
NVIC_DisableIRQ(PIN_INT5_IRQn);
NVIC_DisableIRQ(PIN_INT6_IRQn);
NVIC_DisableIRQ(PIN_INT7_IRQn);
NVIC_DisableIRQ(GINT0_IRQn);
NVIC_DisableIRQ(GINT1_IRQn);
NVIC_DisableIRQ(RIT_IRQn);
NVIC_DisableIRQ(SSP1_IRQn);
NVIC_DisableIRQ(I2C_IRQn);
NVIC_DisableIRQ(CT16B0_IRQn);
NVIC_DisableIRQ(CT16B1_IRQn);
NVIC_DisableIRQ(CT32B0_IRQn);
NVIC_DisableIRQ(CT32B1_IRQn);
NVIC_DisableIRQ(SSP0_IRQn);
NVIC_DisableIRQ(USART_IRQn);
NVIC_DisableIRQ(USB_IRQ_IRQn);
NVIC_DisableIRQ(USB_FIQ_IRQn);
NVIC_DisableIRQ(ADC_IRQn);
NVIC_DisableIRQ(BOD_IRQn);
NVIC_DisableIRQ(FMC_IRQn);
NVIC_DisableIRQ(USBWAKEUP_IRQn);
/*
* Don't use NVIC_DisableIRQ(WDT_IRQn);
* because you need WDT for MCU reset after firmware.bin replacement
*/
/* Disable SYSTICK timer and interrupt before calling into ISP */
SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
/* Initialize Storage state machine */
init_msdstate();
/*
* Reset main stack pointer. 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) &_vStackTop);
/*
* Invoke ISP. We call "iap_entry" to invoke
* ISP because the ISP entry is done through the same
* command interface as IAP.
*/
flash_LPC13XX_IAP_ReInvokeISP();
/* Code will never return! */
}
I attached useful drivers that can help you.
Have a good day!