Conflict between IAP (reinvoke_ISP) and USBHID LPC11u24

19 May 2015

Hi there,

I am trying to write a code for the LPC11u24 to send data via USB, as a USBhid report, and also include a routine to update the firmware via software, using the reinvoke_ISP function. However, I am experiencing some sort of conflict between the IAP reinvoke_ISP function and the USBHID lib.

I am using the code from https://developer.mbed.org/questions/3237/Can-mbed-jump-to-ISP-rom-like-the-autois/, posted by Neil. The IAP part works fine without instantiating the USBHID object: the MCU enumerates as a MSD after 10 seconds. However, when I include the line below, the device does not appear as a MSD. USBHID hid(output_report_length, input_report_length, vendor_id, product_id, product_release);

The code below is kind of the "first step" of what I am trying to do, but I can't get it to work. Has anyone else had this problem?

Thanks, Rafael

main.cpp

#include "mbed.h"
#include "USBHID.h"

using namespace std;

// using a led
DigitalOut myled(P0_9);

USBHID hid(8,8); // If I comment this line, the code works fine
 
//This data must be global so it is not read from the stack
unsigned int m_Command[5], m_Result[5];
typedef void (*IAP)(unsigned int [], unsigned int []);
const IAP IAP_Entry = (IAP)0x1FFF1FF1;

/* 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 IAP_ReinvokeISP()
{
    //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;
 
    //Prepare the command array
    m_Command[0] = 57;
    
    //Initialize the storage state machine
    *((unsigned int *)(0x10000054)) = 0x0;
     
    //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(*((unsigned int *)0x00000000));
 
    //Invoke IAP call...
    IAP_Entry(m_Command, m_Result);
 
    //Shouldn't return
    while(1);
}
 
 
int main(){

   for (int i = 0; i < 10; i++) {
       myled = !myled;
       wait(0.5);
   }
   
   IAP_ReinvokeISP();

}