Skip to main content
Visitor II
October 29, 2021
Solved

Priorities on STM32 (USB, SD, EXTI...)

  • October 29, 2021
  • 1 reply
  • 1208 views

Hi,

please help me figure out priorities in my project.

So, I'm using:

  • SDIO 4 bit + DMA
  • USB Composite Device = CDC + MSC with VBUS detection on PA9 pin.

I configured PA9 as EXTI on Rising/Falling edge. For now i just want to light a diode when USB conection is detected. It works on simplier project with just USB device CDC.

My priorities:

  • SDIO global interrupt - Preemption priority 1
  • DMA2 stream3 and stream 6 global interrupt - Preemption priority 2
  • USB OTG FS global interrupt - Preemption priority 5

All sub priorities are 0.

I tried giving EXTI9_5 (PA9 pin) preemption priority from 0 to 6, and also preemption priority 5 with subpriority 1.

I know that the higher number it is, the lower priority it gets. My guess is that EXTI should have the last priority, but I'm not sure.

My MCU is STM32F407VG.

Thanks, and have a nice day!

    This topic has been closed for replies.
    Best answer by TDK

    This is correct. Numerically lower priorities will pre-empt numerically higher ones.

    The usual method (and typically best) is not to use subpriorities at all and assign all 4 bits to preemption.

    > My guess is that EXTI should have the last priority, but I'm not sure.

    It's your choice. Anything should work here.

    Consider debouncing the line, and/or delaying USB initialization for 100ms after the line goes high.

    1 reply

    TDKAnswer
    Super User
    October 29, 2021

    This is correct. Numerically lower priorities will pre-empt numerically higher ones.

    The usual method (and typically best) is not to use subpriorities at all and assign all 4 bits to preemption.

    > My guess is that EXTI should have the last priority, but I'm not sure.

    It's your choice. Anything should work here.

    Consider debouncing the line, and/or delaying USB initialization for 100ms after the line goes high.