/* This function resets some microcontroller peripherals to reset * hardware configuration to ensure that the USB In-System Programming module * will work properly. It is normally called from reset and assumes some reset * configuration settings for the MCU. * Some of the peripheral configurations may be redundant in your specific * project. */ 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. * In addition ensure the CONTROL register is set to 0 so the MSP is * used rather than the PSP. */ __set_MSP(*((volatile uint32_t *)0x00000000)); __set_CONTROL(0); /* 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! }
// This function resets some microcontroller peripherals to reset // hardware configuration to ensure that the USB In-System Programming module // will work properly. It is normally called from reset and assumes some reset // configuration settings for the MCU. // Some of the peripheral configurations may be redundant in your specific // project. // // TODO: this seems to works but require additional review. void ReinvokeISP() { // Disable SYSTICK timer and interrupt before calling into ISP */ SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk); // Disable USB interrupts. NVIC_DisableIRQ(USB0_IRQn); /* make sure USB clock is turned on before calling ISP */ LPC_SYSCTL->SYSAHBCLKCTRL |= 0x04000; /* make sure 32-bit Timer 1 is turned on before calling ISP */ LPC_SYSCTL->SYSAHBCLKCTRL |= 0x00400; /* make sure GPIO clock is turned on before calling ISP */ LPC_SYSCTL->SYSAHBCLKCTRL |= 0x00040; /* make sure IO configuration clock is turned on before calling ISP */ LPC_SYSCTL->SYSAHBCLKCTRL |= 0x10000; /* make sure AHB clock divider is 1:1 */ LPC_SYSCTL->SYSAHBCLKDIV = 1; // TODO: test this with an actual active WDT. (do we need it at all? // the ROM functionality may disable the WDT anyway). Chip_WWDT_DeInit(LPC_WWDT); // Send Reinvoke ISP command to ISP entry point. command[0] = 57; // Initialize Storage state machine. // TODO: what does this mean? Do we need it? init_msdstate(); // 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 *)0x00000000)); // Enter ISP. We call "iap_entry" to enter ISP because the ISP entry is done // through the same command interface as IAP. */ // xiap_entry(command, result); iap_entry(command, result); // Not supposed to come back! }
void ReinvokeISP(void) { Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_RAM1); if(ISP_Request == 0x12345678) { ISP_Request = 0; //ReinvokeISP(); //Jump to USB ISP bootloader //} /* make sure USB clock is turned on before calling ISP */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USB); /* make sure 32-bit Timer 1 is turned on before calling ISP */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_CT32B1); /* make sure GPIO clock is turned on before calling ISP */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO); /* make sure IO configuration clock is turned on before calling ISP */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); /* make sure AHB clock divider is 1:1 */ Chip_Clock_SetSysClockDiv(1); /* Send Reinvoke ISP command to ISP entry point*/ IAP_Command[0] = IAP_REINVOKE_ISP; //Reinvoke bootloader command (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 *)0x00000000)); /* Enter ISP. We call "iap_entry" to enter ISP because the ISP entry is done through the same command interface as IAP. */ iap_entry(IAP_Command, IAP_Result); // Not supposed to come back! //vPortExitCritical(); } }
int main (void) { uint32_t n; MscDevInfo.idVendor = USB_VENDOR_ID; MscDevInfo.idProduct = USB_PROD_ID; MscDevInfo.bcdDevice = USB_DEVICE; MscDevInfo.StrDescPtr = (uint32_t)&USB_StringDescriptor[0]; MscDevInfo.MSCInquiryStr = (uint32_t)&InquiryStr[0]; MscDevInfo.BlockSize = MSC_BlockSize; MscDevInfo.BlockCount = MSC_BlockCount; MscDevInfo.MemorySize = MSC_MemorySize; MscDevInfo.MSC_Read = MSC_MemoryRead; MscDevInfo.MSC_Write = MSC_MemoryWrite; DeviceInfo.DevType = USB_DEVICE_CLASS_STORAGE; DeviceInfo.DevDetailPtr = (uint32_t)&MscDevInfo; /* Enable Timer32_1 and IOCON blocks */ LPC_SYSCON->SYSAHBCLKCTRL |= (EN_TIMER32_1 | EN_IOCON | EN_USBREG); initializeBoard(); SPI_Config(); (*rom)->pUSBD->init_clk_pins(); /* Use pll and pin init function in rom */ /* insert a delay between clk init and usb init */ for (n = 0; n < 75; n++) { } (*rom)->pUSBD->init(&DeviceInfo); /* USB Initialization */ init_msdstate(); /* Initialize Storage state machine */ (*rom)->pUSBD->connect(TRUE); /* USB Connect */ while (1); /* Loop forever */ }