Saving CRC Register on context switch

I am using MSP430F5418 with FreeRTOS 7 in medium data model. I want to save the MSP CRC registers on FreeRTOS context switch. I edited the portext.s43 like this. In save context macro, after pushing 15 registers to stack, I push the CRC registers. (CRCDI is the MSP register to save) mov.w CRCD1, r15
pushx.a r15
In restore context macro, I poped the CRC just before poping the 15 registers. popx.a r15
mov.w r15, CRCDI
It is supposed to be working , but it is not. The program control is going to unknow location. Anybody have any Idea?

Saving CRC Register on context switch

You will also have to set up the initial stack given to the task when it is created to include the additional register – otherwise, when the task first starts, the restore context macro will try and pop a register that does not exist resulting in junk in the register and a stack underflow. Look at the function pxPortInitialiseStack() in whichever port.c file you are using. Regards.

Saving CRC Register on context switch

Thank you Richard for your reply.
In that function what should I change?

Saving CRC Register on context switch

I don’t know which port you are looking at, but if you look at FreeRTOS/Source/Portable/IAR/MSP430X/port.c, then assume PRELOAD_REGISTER_VALUES is set, you will see that the function writes a value for each register that is to be popped from the stack when the context is loaded.  If your new register is the last thing popped from the stack, add it to the start of the list, if it is the first thing popped from the stack, add it to the end of the list. Regards.

Saving CRC Register on context switch

But PRELOAD_REGISTER_VALUES is not set in my port.c, what should I do?

Saving CRC Register on context switch

I added the following at the top. before #ifdef PRELOAD_REGISTER_VALUES
*pxTopOfStack = (portSTACK_TYPE) 0xffff;
pxTopOfStack--;
#ifdef PRELOAD_REGISTER_VALUES follows
Now it is working but while restoring context, incorrect value is loaded

Saving CRC Register on context switch

Ya Now it is working. I want to save CRCRESR register also to do that. So I need one more
*pxTopOfStack = (portSTACK_TYPE) 0xffff;
pxTopOfStack--;
for that, right?

Saving CRC Register on context switch

But PRELOAD_REGISTER_VALUES is not set in my port.c, what should I do?
Which port are you using then? Regards.

Saving CRC Register on context switch

I’m Sorry,
I found it

Saving CRC Register on context switch

I am sorry, I couldn’t found the PRELOAD_REGISTER_VALUES, anywhere in the free RTOS 7.0 files. Could you please tell me how can I delete a post from this forum?