STM32 Primer freeze on xQueueSendToFrontFromI

anonymous wrote on Wednesday, March 31, 2010:

Is there anything special has to be done to call xQueueSendToFrontFromISR from interrupt handler on STM32?

I have ISR on USB_LP_CAN1_RX0_IRQHandler(USB Low Priority) that calls USB_Istr in the std framework and then to my EP1_OUT_Callback gets called.

When I call xQueueSendToFrontFromISR from there it freezes on prvCopyDataToQueue->memcpy.
The same call from the vApplicationTickHook works well.

Thanks

anonymous wrote on Wednesday, March 31, 2010:

Actually memcpy produces HardFault!!

davedoors wrote on Wednesday, March 31, 2010:

The normal reason for crashes in Cortex M3 interrupts is an invalid interrupt priority. The priority must be equal to or below configMAX_SYSCALL_INTERRUPT_PRIORITY, which on the Cortex M3 means the priority value must be lower than configMAX_SYSCALL_INTERRUPT_PRIORITY (a priority of 255 being lower than a priority of 0). You must set the interrupt priority otherwise it will default to zero and most probably crash. Also, make sure you set it correctly as different functions use different methods, some need the priority shifted up to the most significant bits and other don’t.

If it is memcpy that is crashing, can you stop on the debugger and see the addresses it is copying to and from?

anonymous wrote on Wednesday, March 31, 2010:

interrupts priority is above 0:

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

message I’m trying to send is static:
static const xLCDMessage endpointMsg=
{
   mainWRITE_STRING_MESSAGE,  “USB”
};

task initialized as tskIDLE_PRIORITY+3:

pxQueue structure seems fine

Any suggestions?

thanks.

davedoors wrote on Wednesday, March 31, 2010:

As suggested, I think this is where your bug lies. The interrupt priority is below 0, because it is numerically higher.

What is configMAX_SYSCALL_INTERRUPT_PRIORITY set to in FreeRTOSConfig.h.  By default it will be 11, so your interrupt priorities need to be 11, 12, 13, or 14. Anything else will cause intermittent problems.

thomask wrote on Wednesday, March 31, 2010:

… and if I understand correctly, priority 15 should be fine too?

davedoors wrote on Wednesday, March 31, 2010:

Yes.

anonymous wrote on Wednesday, March 31, 2010:

so far I did the following

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

No Help
Still get HardFault during prvCopyDataToQueue (memcpy but if I comment out memcpy it will happen on next instruction)

anonymous wrote on Thursday, April 01, 2010:

No matter what I do I have HardFault when I try to call xQueueSendToFrontFromISR from ISR.

Can somebody point me to working example where it actually works?