Code crach when adding FreeRTOS to PIC32MX795

kshi1028 wrote on Monday, July 22, 2013:

Hope it is the right place asking FreeRTOS related question using PIC32MX795F512L.

I am new to PIC32.

I made four external interrups (INT1 to INT4) and CAN 1 working properly on the board (not start kit, I don’t have start kit). Then I added FreeRTOS to the code. The issue is that after adding FreeRTOS, the code always crashes as soon as calling vTaskStartScheduler(). I noticed that if I only made the CAN 1 running, it works ok, as long as enabling external interrupts, even just one, the software crash. On the PIC32, I also set up PWM to output clocks and setup 4 SPI buses (setup to master), but there is no interrupts on SPI bus.

This is the external interrupt routine, all four external interrupts have almost the same code except line = 0;      

/* Meter 1 IRQ */
void __ISR(_EXTERNAL_1_VECTOR, ipl3) INT1Interrupt(void)
    struct ipc_message msg;
    portBASE_TYPE err;
    if(mPORTEReadBits(BIT_8) == 0) {
        /* Disable further interrupt from INT1 since need to process interrupt */
        msg.command = IPC_INTERRUPT_REQUEST; = 0;                    /* task uses zero-based */
        err = xQueueSendToBackFromISR(meters_ipc.ipc_inbox, &msg, NULL);
        if(err == errQUEUE_FULL) {
            meters_ipc.ipc_overflow = 1;
        } else {
            if(meters_ipc.ipc_overflow == 1)
            meters_ipc.ipc_overflow = 0;  

on FreeRTOSConfig.h, defined:

/* The priority at which the tick interrupt runs.  This should probably be
kept at 1. */
#define configKERNEL_INTERRUPT_PRIORITY            0x01

/* The maximum interrupt priority from which API functions can
be called.  Only API functions that end in …FromISR() can be used within
interrupts. */

I also setup

#pragma config FPLLMUL    = MUL_20    /* In DEVCFG2 */
#pragma config FPLLIDIV = DIV_2        /* In DEVCFG2 */
#pragma config FPLLODIV = DIV_1        /* In DEVCFG2 */
#pragma config FWDTEN    = OFF
#pragma config POSCMOD    = HS        /* In DEVCFG1 */
#pragma config FNOSC    = PRIPLL    /* In DEVCFG1 */
#pragma config FPBDIV    = DIV_1        /* In DEVCFG1 */
/* code protect, boot write protect, flash write protect */
#pragma config CP = OFF, BWP = OFF, PWP = OFF
#pragma config UPLLEN = OFF
#pragma config FSRSSEL = PRIORITY_7

At the beginning of the main() loop, I called:


any problem on it?

Very appreciate for the help.


edwards3 wrote on Monday, July 22, 2013:

You need some simple wrappers on your ISR. Look at the Interrupt Service Routines section on this page for an example

Then with the settings you show in your post make sure the interrupt priority is 3 or below.