I have a hard fault problem when sending data into a queue from an interrupt (i2c), if the array is filled with a few bytes <12 it doesn’t crash, but when I send the array with eg 20 bytes I get the hard-fault. I have read the M3 book and searched the web but cant figure out the problem. Can any one please look at my setup to see if I have misunderstood the priority handling? And I’m also wondering what a suitable array size would be? freertosConfig.h
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/* The lowest priority. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Priority 5, or 95 as only the top four bits are implemented. */
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
interrupt setup
//Interuptconfig, viktigt att I2C har högst prio, se errata.
NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 11; //Lågt värde => hög prio
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Lågt värde => hög prio
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12; //Lågt värde => hög prio
NVIC_InitStructure.NVIC_IRQChannel = I2C1_ER_IRQn;
NVIC_Init(&NVIC_InitStructure);
NVIC_SetPriority(I2C1_ER_IRQn,10);
NVIC_SetPriority(I2C1_EV_IRQn,11);
// term_I2C enable
I2C_Cmd(term_I2C, ENABLE);
I2C ISR
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
if (I2C_GetITStatus(term_I2C, I2C_IT_RXNE)) {
vBMT_ReciveByte(&xHigherPriorityTaskWoken);
I2C_ClearITPendingBit(term_I2C, I2C_IT_RXNE);
}
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
vBMT_ReciveByte()
save data to RxBuf until complete package
if(xQueueSendToBackFromISR(xNMTRxQueue, &RxBuf, xHigherPriorityTaskWoken)==errQUEUE_FULL){
//TODO:Lyckades inte skriva till kön gör en reset!?
}
goes back to handler