• AVR Freaks

Helpful ReplyHot!USB HOST Bootloader and Application issue.

Author
LeeZimme
Starting Member
  • Total Posts : 78
  • Reward points : 0
  • Joined: 2014/06/11 12:14:35
  • Location: 0
  • Status: offline
2019/09/13 13:42:59 (permalink)
0

USB HOST Bootloader and Application issue.

I had a USB MSD HOST bootloader that worked great.  I have an issue with USB drives getting corrupted during the application code.  Maybe cheap USB or I am opening and closing them too much.  I am working on that to make them better but it has shown weakness in the bootloader.  A corrupt USB will hang the bootloader and it won't start the application.  I thought an easy fix would be if it can't load the USB thumb drive in 3 seconds jump to application.   If there isn't a USB installed or if a corrupted USB is installed, the application starts but stops after the LED self test.  If there is a valid USB it starts and runs normally.
 
Bootloader in the _T3Interrupt.  

  if(msTimer>3000)  {
  USBHostShutdown();
  SYS_Deinitialize();
  (((int(*)(void))(0xa800ul))());
  while(1);
  }

 
Can the bootloader jump to application code at anytime?  Do I need to clear special flags since the application is getting called from the interrupt?  Why is it dependent on the USB being there?
 
For reference 

void SYS_Deinitialize()
{
U1IE = 0;
U1IR = 0xFF;
IEC5 = 0;
IFS5 = 0;
INTCON2bits.ALTIVT = 0;
}

 
I think my linker is good and if I remove the code from the interrupt, the bootloader will launch the application when there is or is not a usb drive and hangs when there is a corrupt drive. 
#1
NKurzman
A Guy on the Net
  • Total Posts : 17847
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: USB HOST Bootloader and Application issue. 2019/09/13 16:04:42 (permalink)
+2 (2)
Make sure all your Interrupt flags are disabled.
#2
paulmtcuk
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2007/08/23 05:16:51
  • Location: 0
  • Status: offline
Re: USB HOST Bootloader and Application issue. 2019/09/16 00:59:04 (permalink) ☄ Helpfulby LeeZimme 2019/09/16 12:16:35
+2 (2)
I wouldn't jump to the application code from within an interrupt! - Unless the application expects that and handles the RETFIE instruction and stack appropriately. I guess it won't.
 
How do you currently jump to application? I guess it is somewhere in the bootloader main loop.
What are the requirements for a normal jump? You should just use the same code and same location to jump.
 
Furthermore it is probably best to disable interrupts in the bootloader entirely and instead poll interrupt flags - I assume you are using vectored interrupts which may be overwritten by your application? Instead I'd poll the T3Interrupt flag in the bootloader main loop and check the timeout at that point. If interrupts are generated for the bootloader USB code I'd call the USB interrupt code from the bootloader main loop only if the interrupt flag is TRUE. 
 
Also you can also just use an asm("GOTO 0xa800") instead of a function call as it should never return anyway. I also assume that 0xa800 is the location of the application program memory start and not the main() function of the application!
post edited by paulmtcuk - 2019/09/16 01:44:06
#3
LeeZimme
Starting Member
  • Total Posts : 78
  • Reward points : 0
  • Joined: 2014/06/11 12:14:35
  • Location: 0
  • Status: offline
Re: USB HOST Bootloader and Application issue. 2019/09/16 12:16:38 (permalink)
0
So it is because it doesn't return correctly from the interrupt.  I tried unsuccessfully to change the return pointer so the RETIF would just go to the start of the application code.
 
asm("mov #0xa800, wreg15");  // didn't work.
 
The USB interrupt routines had a lot of while(usb...)  which took too long.  I tried to insert code to exit when these took too long but it wasn't working due to the USB host being interrupt based. 
 
I got it working by disabling the USB and timer interrupts timer interrupt then the normal exit logic would happen. 
#4
Jump to:
© 2019 APG vNext Commercial Version 4.5