AnsweredAssumed Answered

IAP with USB usage

Question asked by achterop.sietse on Apr 30, 2014
Latest reply on May 1, 2014 by achterop.sietse
  Hello List,

I have a working IAP program that uses USB to upload new code.
See
  http://fwn06.housing.rug.nl/stm-test
for the code. The project IAPtest contains the code, including an example to upload
new code, using the linux command ./sendcode <bin-file>

There is however a problem when I want to use USB in the code to upload DIRECTLY after
flashing new code. If after uploading a reset is performed the newcode (including USB use)
is working perfectly!

Here a fragment of the IAPtest code:
mode = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0);
if (!mode) {
  // we want to flash new code
  usb_init();
  if ((i=getcode()) != 0) {
    while (1) {
      GPIO_ToggleBits(LED_RED_GPIO_PORT, LED_RED_PIN);
      delay(100);
    }
    // to give usb time to settle, 100 seems ok
    delay(100);
    NVIC_DisableIRQ(OTG_FS_WKUP_IRQn);
    NVIC_DisableIRQ(OTG_FS_IRQn);
  }
}
 
/* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20020000)
  {
    /* Jump to user application */
    JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
    Jump_To_Application = (pFunction) JumpAddress;
    /* Initialize user application's Stack Pointer */
    __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
    Jump_To_Application();
  }

The problem is of course that USB code is used in uploading and after that in the uploaded code.
How do I "reset" the USB code after "getcode()" so it later can we initialized again in the newcode?
In this version I try to disable the USB interrupts, but that clearly is not enough.

  Hopefully someone can shed some light on this.
      Thanks in advance,
              Sietse

Outcomes