cancel
Showing results for 
Search instead for 
Did you mean: 

Can I disable USB interrupt for < 10us ? If can, how ?

taz1000
Associate III

I am generating a special signals with GPIO.

It is unique protocol signal to communicate with other system.

To make signal timing, I ran one of TIMER counter and check the value in a while loop.

But, the problem is from USB connection.

If I don't connect to PC, then the TIMER counter check routine works fine. MCU exits the routine as expected.

But, if i connect to PC via USB, then sometimes the checking routine spend more time than expected.

I guess MCU jumps to USB interrupt service routine regularly.

Is it possible for me to disable USB interrupt for < 10us without loosing PC USB connection ?

If yes, how can I do ?

6 REPLIES 6

Run the protocol in an interrupt that has a higher preemption level than the USB?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

You did not care to tell us the STM32 model, but generally, you can always disable the USB interrupt in NVIC. 10us, or even several tens of us, is no big deal, even in HS where things happen in 125us microframes - the lowest level where there are tight timeouts is handled in hardware; reception is buffered and if buffers are full the host is notified and retries later; higher levels generally have timeouts in (tens, hundreds of) milliseconds... unless we are talking about isochronous transfers, of course.

However, tightly timed signals are always better solved by hardware, if possible, i.e. using some channel of a timer to generate pulses of required length. I understand that you already have a working solution and don't want to change on that if possible, but maybe in the future you might want to reconsider this.

JW

Dear JW,

STM32L412RBT is the one I'm using.

I had tried as following, but it doesn't work.

NVIC_DisableIRQ(OTG_FS_IRQn);

NVIC_EnableIRQ(OTG_FS_IRQn);

Would you teach me how to disable and enable USB interrupt on STM32L412RBT ?

* It is good to hear that microframes are handled in hardware.

THANKS.

Thanks for your comment,

In the current project, the function needs to work outside of interrupt service routine.

But, in future, it can be one of solutions.

Making a SW triggered interrupt and give it a proper interrupt level.

Thanks ~!

alister
Lead

Agree with earlier posters.

Also, your implementation may never be reliable because any interrupt, e.g. system tick, would affect the waveform's shape.

If you're generating the waveform rarely and/or you're not overly fussed about your app's interrupt responsiveness, you might consider merely disabling all interrupts before starting the waveform and enabling them again after using __disable_interrupt() and __enable_interrupt() or __disable_irq() and __enable_irq() depending on your compiler and MCU.

Alister

> I had tried as following, but it doesn't work.

> NVIC_DisableIRQ(OTG_FS_IRQn);

> NVIC_EnableIRQ(OTG_FS_IRQn);

What do you mean but "doesn't work"? Does not compile? That would be no surprise, as there's no OTG unit in the 'L412. You should look into the device header for the proper symbol for USB interrupt, but most likely it will be USB_IRQn .

JW