ATXMEGA384D3 port

jaynicholson wrote on Tuesday, March 12, 2013:

Hi,
I am relatively new to the free RTOS but have been developing some new code using it and things have been progressing pretty well. That is until I have reached a certain code size on my device > 78500. Now when I try to delete the first startup task my code resets. I realize there is no official port but wonder if there are some pointers as to what is going wrong.
Heap and stack are ok plenty of space there.
I have enabled task delete and suspend. (using either from within the task cause a re start)

Any suggestions greatly received.

Jay

rtel wrote on Tuesday, March 12, 2013:

Where did you get the code from?  The official ATMega port does not support the larger memory devices.  Supporting the larger memory devices is, I believe, quite straight forward and requires that a couple of extra RAMn registers are saved in the task context.  Is your port doing that?

Regards.

jaynicholson wrote on Tuesday, March 12, 2013:

I got this after looking at various port attempts so couldn’t be exactly sure where it came from now.
save context is as below.

#if defined(__AVR_ATxmega384D3__)
/* 3-Byte PC Save */
#define portSAVE_CONTEXT() \
asm volatile ( “push r0 \n\t” \
“in r0, __SREG__ \n\t” \
“cli \n\t” \
“push r0 \n\t” \
“push r1 \n\t” \
“clr r1 \n\t” \
“push r2 \n\t” \
“push r3 \n\t” \
“push r4 \n\t” \
“push r5 \n\t” \
“push r6 \n\t” \
“push r7 \n\t” \
“push r8 \n\t” \
“push r9 \n\t” \
“push r10 \n\t” \
“push r11 \n\t” \
“push r12 \n\t” \
“push r13 \n\t” \
“push r14 \n\t” \
“push r15 \n\t” \
“push r16 \n\t” \
“push r17 \n\t” \
“push r18 \n\t” \
“push r19 \n\t” \
“push r20 \n\t” \
“push r21 \n\t” \
“push r22 \n\t” \
“push r23 \n\t” \
“push r24 \n\t” \
“push r25 \n\t” \
“push r26 \n\t” \
“push r27 \n\t” \
“push r28 \n\t” \
“push r29 \n\t” \
“push r30 \n\t” \
“push r31 \n\t” \
“lds r26, pxCurrentTCB \n\t” \
“lds r27, pxCurrentTCB + 1 \n\t” \
“in r0, 0x3d \n\t” \
“st x+, r0 \n\t” \
“in r0, 0x3e \n\t” \
“st x+, r0 \n\t” \
);

rtel wrote on Tuesday, March 12, 2013:

Just from a brief look, without referring to the manuals, I think you need to also be storing RAMX and RAMY (or something like that) in addition to the registers in your post if you want to go above 64K.  You would also need to have initial values for the extra registers in the stack setup for a task when the task is created.

Have a look at the Atmel forum in http://interactive.freertos.org to see if you can find an example.  You can also ask on http://www.avrfreaks.net

Regards.

jaynicholson wrote on Tuesday, March 12, 2013:

Looking at the manual the x y and z registers run from R26 to R31. Not really sure how to use them in this instance though. Apologies.

Rgards

jaynicholson wrote on Tuesday, March 12, 2013:

I have now resolved my issue. The problem was in the pxPortInitialiseStack function. The issue was with the program counter being larger than 16bit.

I used yuris from https://github.com/yuriykulikov/FreeRTOS-on-XMEGA

Regards

Many thanks for your help.