cancel
Showing results for 
Search instead for 
Did you mean: 

Help a Hardware guy with NVIC

VE7HR
Associate II
Posted on February 06, 2014 at 19:13

I am trying to understand the NVIC on a SMT32F407. I have found that we are missing USB interrupts randomly. Since I cant solder a pullup to fix the problem I am stuck.

I can understand the documentation enough to be confused. I need a clear example of what to do.

This is what the software guys have cribbed from a whole bunch of examples and I am sure we have things setup wrong.

.DMA1 NVIC Setup

    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream0_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    USART2 NVIC setup

    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;// we want to configure the USART1 interrupts

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;// this sets the priority group of the USART1 interrupts

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;// this sets the subpriority inside the group

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;    // the USART1 interrupts are globally enabled

    NVIC_Init(&NVIC_InitStructure);    // the properties are passed to the NVIC_Init function which takes care of the low level stuff

    TS NVIC Setup

    NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    USB

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable USB Interrupt */

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1 );

    NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    USB Overcurrent

        /* Enable the Overcurrent Interrupt */

    //NVIC_InitStructure.NVIC_IRQChannel = HOST_OVRCURR_IRQn;

    //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

    //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

    //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    TIM2

    NVIC_InitTypeDef NVIC_InitStructure;

    

    /* Configure the Priority Group to 2 bits */

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2 );

    /* Enable the TIM2 gloabal Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    TIM3

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable the TIM3 global Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

Why is the USB interrupt not firing?

How would you alter the numbers for success.

Thanks

Dave The frustrated hardware guy.

#stm32f4-nvic-interrupts
6 REPLIES 6
Posted on February 06, 2014 at 19:27

Setting the Priority Group has global impact, figure out what you want it to be, then set it once.

 /* Configure the Priority Group to 2 bits */

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2 );

Figure out what hierarchy you want for your interrupts. If USB is critical it should have the lowest pre-emption setting. Right now everything except the EXTI has higher priority than the USB.

Understand WHY it's missing USB interrupts? Is it stuck some place else servicing another interrupt or spinning in a loop. Does it need a pull-up?

If the TRM is a bit heavy going, try Joseph Yiu's books on the Cortex-M3 or 4

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
VE7HR
Associate II
Posted on February 06, 2014 at 20:43

Clive,

Thanks for the help

Give me a few things to think about.

So you are suggesting set Priority group to 4 and set priorities to what I think?

Its taken days of troubleshooting to determine that its missing the interrupt.

Open to suggestions on how to figure out what is messing with it.

Thanks

Dave

frankmeyer9
Associate II
Posted on February 06, 2014 at 21:01

Why is the USB interrupt not firing?

 

It might actually be firing, but the handler could blocked by other interrupts of equal or higher priority. If another USB interrupt arrives during this time, the first one is lost.

Try prioritise your interrupts, and/or keep interrupt handlers as short as possible (in runtime, not in code ...).

VE7HR
Associate II
Posted on February 06, 2014 at 21:11

I thought the interrupts were latched? But they seem to be not.

As stated I am not the Software guy. I totally understand keeping runtime short. But I did not write the code. Just trying to understand it enough to keep things coordinated. From Clives comments its rather messed up.

We have a project that works except for this USB issue.  If you have every seen the USB stack its a lot happening in it. Its a open source project ( Ham radio related) and as I am the hardware guy it seems to be left to me to sort it out.

 I appreciate your help. I will figure it out.

Thanks

Dave

 

Posted on February 06, 2014 at 21:38

I thought the interrupts were latched? But they seem to be not.

Indeed, but the latch can't tell you if it was triggered once, or a couple of times, it's not counting. If the time to service it exceeds the periodicity of the source, then you'll have problems. Hence we need to understand the nature of the ''missing'' you describe.

If the interrupt remains signalled the service routine will keep re-entering.

It is possible that if you read/write the wrong registers you can clear pending conditions.

Avoid read-modify-write to registers, avoid bit-banding of registers.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
VE7HR
Associate II
Posted on February 06, 2014 at 22:12

I have a debug statement in the top most base interrupt in the ST provided USB stack. When it does not work it never prints the message. So it does not look like it made it there.

Thanks for your help.

I will figure it out.

Dave