Problems when starting first task.

nobody wrote on Sunday, August 20, 2006:

Hi all!

I have cleaned out the AT91SAM7X demo to work with AT91SAM7S instead. Most of the code except the USB CDC task is removed and replaced with my own code. It all compiles and run fine in IAR but I am having issues with Crosswork. The code compiles in crosswork and all initiation seam to work fine exccept when it is time to start all the created tasks. As I understand the "vTaskStartScheduler" function ends by calling "vPortISRStartFirstTask" to start the sceduler. When this is done I get a data abort and the program stucks in the "dabort_handler" loop.

Does anyone have an idea where I should start to look for the problem. Can there be an memmory issue, stack perhaps? The Heap should be fine. I still have arround 100 bytes left on the heap assigned in freertosconfig.h file after all tasks are created. I also use heap_1.c for memory management.

Thank you for any ideas.
/Lars Andersson

nobody wrote on Sunday, August 20, 2006:

In crossworks you need to have SUPERVISOR_START and VECTORED_IRQ_INTERRUPTS defined in the pre processor.  Do you have these?

nobody wrote on Sunday, August 20, 2006:

Thnx for the quick reply!

Well, I have the "ldr pc, [PC, #-0xF20]" in my startup.s file. As for global pre processor definitions I have the same as in the demo "SAM7_GCC;THUMB_INTERWORK;SUPERVISOR_START" I can not find the "VECTORED_IRQ_INTERRUPTS" defined anywhere. Should this be defined in the same place, under "solution" in the "common" configuration

nobody wrote on Sunday, August 20, 2006:

That should be fine then.  In my startup file I have the lines

#ifdef VECTORED_IRQ_INTERRUPTS
  .word 0xB9205F88 
  ldr pc, [pc, #-0xFF0]                         #else
  .word 0xB8A06F60   ldr pc, [pc, #irq_handler_address - . - 8]    /* irq handler */
#endif

Does not sound like you have the same.

nobody wrote on Sunday, August 20, 2006:

I searched the whole FreeRTOS catalog and only found the "VECTORED_IRQ_INTERRUPTS" to be used with Philips LPC210X processor. Is this also needed for the AT91SAM7 series?

nobody wrote on Sunday, August 20, 2006:

Are you compiling for ARM or Thumb?

Step into the vPortISRStartFirstTask code.  Check that the processor is in supervisor mode when this code runs.  See the line where the PC register is loaded, at that point all the other registers should be loaded with known values that are obvious ( value 1 in register 1 ect ) is this the case?

when the first task starts the interrupts will be enabled.  Is it that you are jumping directly to an interrpt handler that is crashing?

nobody wrote on Sunday, August 20, 2006:

It might depend on the version of crossworks in use.

nobody wrote on Sunday, August 20, 2006:

I am compiling for thumb, exccept for the ISRs, which are definedas “naked” and compiled in in arm mode. I can’t check exactly where the crash occuers at the moment, will do later.

Let’s assume it crasshes where you explained, at the actual jump. What is your sugestion in that case?

/L

nobody wrote on Sunday, August 20, 2006:

Sorry, I am using 1.6. All initiation files are from the freertos project and according to the documentation one should use 1.6 after FreeRTOS 4.0.3

nobody wrote on Sunday, August 20, 2006:

Only to check that all the registers are correct immediately prior to the jump, that it is in system mode with interrupt disabled, and if all this is so, then see where the heck it goes!  It might be worth setting a break point on the IRQ vector as you load the program counter.  That way you can see if an interrupt is eventing as soon as the interrupt is enabled as task starts.

nobody wrote on Monday, August 21, 2006:

I could not get the stock applications to run on a SAM7S with interwork enabled, once I changed all files to compile to full-fat ARM and removed the pre-processor THUMB_INTERWORK define then I was able to get the scheduler running.

I still cannot get thumb applications to work when Crossworks & FreeRTOS on a SAM7S.

nobody wrote on Tuesday, August 22, 2006:

Finaly I have managed to get it to work, when canceling out all my own code except for some simple HW initiation :slight_smile: The code is basically the AT91SAM7X demo with only the USB task runing. This works fine on the SAM7S now with THUMB_INTERWORK defined. I run all code in THUMB mode eccept for the ISR routines which are in ARM mode,as required.

At this point I beleive that there may be a memmory issue or that I do something unclever when creating my tasks. I’ll look into that tomorrow.

I have one thing thay may be of relevance. I know that all IRS functions must be declared as "naked" and running in ARM mode. When defining a function that are called from within an ISR, does this function need to be running in ARM mode as well? is it required to be "naked"?

Thnx

nobody wrote on Tuesday, August 22, 2006:

No - functions called from the isr can be normal functions.

Declaring the isr naked is just one method, and the way the sam7x demo works.  If you look at the str9 demo you will see that only a single isr entry point is defined that saves the context, then all isr functions are just standard functions.  Both ways have pros and cons, I don’t want to confuse things, just an alternative. :wink: