• AVR Freaks

AnsweredHot!Why DRV_USBHS_PersistentInterruptSourceClear(SOURCEUSB1) isn't equal to IFS4bits.USBIF = 0

Author
DominusT
Super Member
  • Total Posts : 1398
  • Reward points : 0
  • Joined: 2005/07/22 08:31:18
  • Status: offline
2019/12/19 09:12:06 (permalink)
0

Why DRV_USBHS_PersistentInterruptSourceClear(SOURCEUSB1) isn't equal to IFS4bits.USBIF = 0

Hi.
 
I'm working with the PIC32MZ2048EFM100 with Harmony 2.06 and XC32 v2.30.
 
I'm using the USB module to emulate an RS232 COM port.

I'm reviewing the interrupts related to the module to determine a problem.

The way to clean the USB interrupt is as follows:

_DRV_USBHS_PersistentInterruptSourceClear(hDriver->usbDrvCommonObj.interruptSource);

 
The interrupt source is always INT_SOURCE_USB_1 (which is 0x00084)

Within the function _DRV_USBHS_PersistentInterruptSourceClear the following is done:

PLIB_TEMPLATE void INT_SourceFlagClear_Default( INT_MODULE_ID index , INT_SOURCE source )
{
    volatile uint32_t *IFSx = (volatile uint32_t *) (&IFS0 + ((0x10 * (source / 32)) / 4));
    volatile uint32_t *IFSxCLR = (volatile uint32_t *)(IFSx + 1);

    *IFSxCLR = 1 << (source & 0x1f);
    *IFSxCLR;
}


If source is equal to 0x0000084,the  operation 1 << (source & 0x1f) is equal to 0x1000 and writing that number in IFS4CLR is equivalent to setting logical zero in bit 3 of IFS4.

If the above statement is correct, then it will not be cleaning the USBIF bit, but would clean the CMP2IF bit.

If the statement is incorrect and if the bit USBIF is being cleaned, because instead of writing the INT_SourceFlagClear_Default function, I simply clean (
IFS4bits.USBIF = 0;
) that flag, but the MCU restarts every moment and doesn't work properly (I guess it restarts because it never cleans the flag until the stack overflows)
 
Any comments or suggestions are welcome.
 
 
#1
jdeguire
Super Member
  • Total Posts : 555
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: Why DRV_USBHS_PersistentInterruptSourceClear(SOURCEUSB1) isn't equal to IFS4bits.USBIF 2019/12/19 09:30:47 (permalink) ☼ Best Answerby DominusT 2019/12/19 09:49:09
5 (1)
I'm not sure what's going on with the Harmony function (I'd need more time to think about it), but I can tell you that you should clear interrupt flags using the IFSxCLR registers instead of IFSxbits.FLAG = 0 because the latter will perform a read-modify-write that can affect other flags in the register.
 
You should also make your own _general_exception_handler() and _simple_tlb_refill_exception_handler() functions to capture why the micro is resetting.  See the XC32 docs for more info on these.
 
EDIT:  The result of (1 << (0x84 & 0x1F)) is 0x10.  This would clear bit 4 of the IFS4 register, which is where USBIF is located and is thus correct.
post edited by jdeguire - 2019/12/19 09:36:17
#2
DominusT
Super Member
  • Total Posts : 1398
  • Reward points : 0
  • Joined: 2005/07/22 08:31:18
  • Status: offline
Re: Why DRV_USBHS_PersistentInterruptSourceClear(SOURCEUSB1) isn't equal to IFS4bits.USBIF 2019/12/19 09:38:53 (permalink)
0
jdeguire
I'm not sure what's going on with the Harmony function (I'd need more time to think about it), but I can tell you that you should clear interrupt flags using the IFSxCLR registers instead of IFSxbits.FLAG = 0 because the latter will perform a read-modify-write that can affect other flags in the register.
 
You should also make your own _general_exception_handler() and _simple_tlb_refill_exception_handler() functions to capture why the micro is resetting.  See the XC32 docs for more info on these.
 
EDIT:  The result of (1 << (0x84 & 0x1F)) is 0x10.  This would clear bit 4 of the IFS4 register, which is where USBIF is located and is thus correct.


Hi. 


I'm going to review your suggestion, but I just made the following:
 
 IFS4CLR = 0x1000; 

 
Instead of using the INT_SourceFlagClear_Default function and it is the same problem, the MCU restarts just now, I am more than sure that it is because the correct flag is not cleaned and several interruptions accumulate until the exception occurs.
post edited by DominusT - 2019/12/19 09:43:33
#3
DominusT
Super Member
  • Total Posts : 1398
  • Reward points : 0
  • Joined: 2005/07/22 08:31:18
  • Status: offline
Re: Why DRV_USBHS_PersistentInterruptSourceClear(SOURCEUSB1) isn't equal to IFS4bits.USBIF 2019/12/19 09:48:56 (permalink)
0
jdeguire
 
EDIT:  The result of (1 << (0x84 & 0x1F)) is 0x10.  This would clear bit 4 of the IFS4 register, which is where USBIF is located and is thus correct.



I did the following:


IFS4CLR = 0x10;


And it works correctly. Thanks for the help.

I already realized my mistake, I was confusing binary numbers with hexadecimals. It must be my advanced age.



#4
ric
Super Member
  • Total Posts : 27076
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Why DRV_USBHS_PersistentInterruptSourceClear(SOURCEUSB1) isn't equal to IFS4bits.USBIF 2019/12/19 14:33:55 (permalink)
5 (2)
Indeed, you were writing 0x10000 when you meant 0b10000

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#5
Jump to:
© 2020 APG vNext Commercial Version 4.5