AVR32 UC3A0512 + Free RTOS

beach1981 wrote on Tuesday, April 14, 2009:

Hi everybody,

I’m using the FreeRTOS port AVR32 UC3A0512 (Atmel EVK1100 Starter Kit)! In my application i two interrupt service routines which manage the RS232 traffic like in the demo application. Everything works fine with no RS232 traffic. With RS232 traffic Free RTOS crashes after an undefined time. Sometimes the Application runs half an hour with a lot of RS232 traffic before RS232 crashes. When a crash occours and i stop the Application in debug mode (Jtag mk II) one of the following execptions is viewed:
“Bus error data fetch” or “Bus error instruction fetch”
Has any one a solution for this problem or can anyone give me a help to isolate the failure!?!

Thanks in advance!
Richard

anonymous wrote on Tuesday, April 14, 2009:

Have you checked the usual suspects? If your interrupt routines use API calls, do they use the "FromISR" versions? And if they do, do you correctly put a critical section around your ISR as directed in http://www.freertos.org/portAVR32.html?

beach1981 wrote on Wednesday, April 15, 2009:

Hey,

here is my ISR! It’s the same as in the example so i dont’t think there is something wrong.

__attribute__((__naked__)) static void xUSART_0_ISR(void)
{
    portENTER_SWITCHING_ISR();
    xUSART_ISR_NON_NAKED(&xUSART0_MC35);
    portEXIT_SWITCHING_ISR();
}

__attribute__((__naked__)) static void xUSART_1_ISR(void)
{
    portENTER_SWITCHING_ISR();
    xUSART_ISR_NON_NAKED(&xUSART1_SHELL);
    portEXIT_SWITCHING_ISR();
}

__attribute__((__noinline__)) static void xUSART_ISR_NON_NAKED(xusartData *xUsart)
{

    int rx_char;
    signed char cchar;
    unsigned portLONG     ulStatus;
    portBASE_TYPE          queuestatus;
    portBASE_TYPE           xHigherPriorityTaskWoken = pdFALSE;

    ulStatus = xUsart->usart->csr & xUsart->usart->imr;

    if (ulStatus & AVR32_USART_CSR_RXRDY_MASK)
    {
        cchar = xUsart->usart->rhr;
        rx_char = (int) cchar;
        if ( rx_char )
        {
            portENTER_CRITICAL();
            xQueueSendFromISR( xUsart->hRXQueue,  &cchar, ( portTickType ) 5 );
            portEXIT_CRITICAL();
        }
    }
    if (ulStatus & AVR32_USART_CSR_TXRDY_MASK)
    {
        portENTER_CRITICAL();
        queuestatus = xQueueReceiveFromISR( xUsart->hTXQueue , &cchar, &xHigherPriorityTaskWoken );
        portEXIT_CRITICAL();
        rx_char = (int) cchar;
        if (queuestatus == pdTRUE)
        {
            xUsart->usart->thr = cchar;
        }
        else
        {
            xUsart->usart->idr = AVR32_USART_IDR_TXRDY_MASK;
        }

    }
}

bowkerrtos wrote on Wednesday, April 15, 2009:

I’m seeing the same problem using ATSAM7x and the Atmel eval kit (256KB part).  I’m using FreeRTOS 5.3 and see a prefetch abort error.  

I debugged it yesterday and I’ve been able to catch it sometimes.  The crash happens during portRESTORE_CONTEXT.  It is on this line:

    /* And return - correcting the offset in the LR to obtain the */   
    /* correct address. */                                               
    "SUBS    PC, LR, #4                                            \n\t"    \

The PC is restored incorrectly and then the processor crashes because of bad opcode or data (depending on circumstance).   I also notice that r14_irq contains an invalid address (0xe94e7fff) but this may be a derivative problem of the stack crash.

I originally thought it was an issue with using the Queue calls (and, yes, I am using the "FromISR" ones!).  But I reduced the UART ISR to just read the byte out of the holding register and exit; the crash still occurs.

bowkerrtos wrote on Wednesday, April 15, 2009:

Clarification - I think my last post suggested I only read in one byte and then it crashes.  In fact, it takes several bytes before the crash occurs; exact number seems to be "random".