User Tools

Site Tools


FreeRTOS fault sample

For example.

Cause

The Fault called by USART3 interrupt while FreeRTOS scheduler is running.

master.c
void usart3_isr(void) {
    uint8_t c = 0;
 
    BaseType_t xHigherPriorityTaskWoken;
    xHigherPriorityTaskWoken = pdTRUE;
 
    if (usart_rx_int_is_enable(USART3) && usart_recv_is_ready(USART3)) {
        c = usart_recv_blocking(USART3);
        xQueueSendFromISR(usart3_q, &c, &xHigherPriorityTaskWoken);
    }
    portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
Decision
FreeRTOSConfig.h
#define IRQ2NVIC_PRIOR(x)       ((x) << 4)
#define configKERNEL_INTERRUPT_PRIORITY         IRQ2NVIC_PRIOR(15)
#define configMAX_SYSCALL_INTERRUPT_PRIORITY    IRQ2NVIC_PRIOR(5)
main.c
#define _IRQ2NVIC_PRIOR(x)   ((x) << 4)
 
int main(void) {
   ...
   scb_set_priority_grouping(SCB_AIRCR_PRIGROUP_GROUP16_NOSUB);
    //nvic_set_priority(NVIC_SYSTICK_IRQ, _IRQ2NVIC_PRIOR(15));
    nvic_set_priority(NVIC_USART1_IRQ, configMAX_SYSCALL_INTERRUPT_PRIORITY + _IRQ2NVIC_PRIOR(1));
    nvic_set_priority(NVIC_USART3_IRQ, configMAX_SYSCALL_INTERRUPT_PRIORITY + _IRQ2NVIC_PRIOR(2));
 
    ...
    xTaskCreate(...);
    ...
    vTaskStartScheduler();
 
    while(1);
}

First PagePrevious PageBack to overviewNext PageLast Page