# dsPIC33EP- Project compiles but fails to Run

**URL:** <https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818>\
**Category:** Kernel\
**Created:** [July 17, 2013, 2:16pm UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818 "2013-07-17T14:16:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 17, 2013, 2:16pm UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818/1 "2013-07-17T14:16:12Z")

</div>

**[groschh](https://sourceforge.net/u/groschh/)** wrote on [Wednesday, July 17, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/7d32a74f/#529d):

Hello,

MPLAB 8.91  
C30 3.31 or XC16  
Testing with MPLAB Simulator

I want to port a project from dsPIC33F to dsPIC33EP256MU810.  
I took care about the missing declaration of the PSVPAG and modified Linkerscript as follows:  
PSVPAG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0x32;  
\_PSVPAG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0x32;  
I declared MPLAB\_DSPIC\_PORT with in the Project macros and exchanged the include directive in FreeRTOSConfig.h to #include \<p33Exxxx.h\>.  
As the silicon specifies aux-Flash it defines “\_\_HAS\_EDS\_\_” I modified port.c&nbsp; as follows:

…  
#define portRESTORE\_CONTEXT() \  
asm volatile( “MOV \_pxCurrentTCB, W0 \n” /\* Restore the stack pointer for the task. \*/ \  
“MOV , W15 \n” \  
“POP W0 \n” /\* Restore the critical nesting counter for the task. \*/ \  
“MOV W0, \_uxCriticalNesting \n” \  
“POP DSWPAG \n” \  
"POP DSRPAG  
…  
and \_vPortYield:  
…

PUSH CORCON  
PUSH DSRPAG  
push&nbsp;&nbsp;&nbsp; DSWPAG  
MOV \_uxCriticalNesting, W0  
…  
MOV W0, \_uxCriticalNesting  
POP&nbsp;&nbsp;&nbsp;&nbsp; DSWPAG  
POP DSRPAG  
POP CORCON  
….

So the project compiles and starts running. If reaching&nbsp; _vTaskDelay(10);_ it crashes in _portYIELD\_WITHIN\_API();_  
What I found is that \*pxCurrentTCB holds obviously an invalid adress and so the poped return address will lead to a wrong PC after _call \_vTaskSwitchContext_.

Same Project compiled for dsPIC33FJ128MC804 does work fine.  
As my knowledge ends at this point I want to ask you to check this behavior.

Best regards and thanks for your help in advance

Heiko

Code :

//—  
#ifndef FREERTOS\_CONFIG\_H  
#define FREERTOS\_CONFIG\_H

#include \<p33exxxx.h\>

#define configUSE\_PREEMPTION 0  
#define configUSE\_IDLE\_HOOK 1  
#define configUSE\_TICK\_HOOK 0  
#define configTICK\_RATE\_HZ ( ( portTickType ) 1000 )  
#define configCPU\_CLOCK\_HZ ( ( unsigned long ) 40000000 )&nbsp; /\* Fosc / 2 \*/  
#define configMAX\_PRIORITIES ( ( unsigned portBASE\_TYPE ) 4 )  
#define configMINIMAL\_STACK\_SIZE ( 200 )  
#define configTOTAL\_HEAP\_SIZE ( ( size\_t ) 2000 )  
#define configMAX\_TASK\_NAME\_LEN ( 4 )  
#define configUSE\_TRACE\_FACILITY 0  
#define configUSE\_16\_BIT\_TICKS 1  
#define configIDLE\_SHOULD\_YIELD 1

/\* Co-routine definitions. \*/  
#define configUSE\_CO\_ROUTINES 0  
#define configMAX\_CO\_ROUTINE\_PRIORITIES ( 2 )

/\* Set the following definitions to 1 to include the API function, or zero  
to exclude the API function. \*/

#define INCLUDE\_vTaskPrioritySet 0  
#define INCLUDE\_uxTaskPriorityGet 0  
#define INCLUDE\_vTaskDelete 0  
#define INCLUDE\_vTaskCleanUpResources 0  
#define INCLUDE\_vTaskSuspend 1  
#define INCLUDE\_vTaskDelayUntil 1  
#define INCLUDE\_vTaskDelay 1

#define configKERNEL\_INTERRUPT\_PRIORITY 0x01

#endif /\* FREERTOS\_CONFIG\_H \*/

//—  
int main( void )  
{

prvSetupHardware();

&nbsp;&nbsp;&nbsp; xTaskCreate( MainTask,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (signed char\*) “Main”, 300,&nbsp;&nbsp;&nbsp;&nbsp; NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Default\_TASK\_PRIORITY,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL);

/\* Finally start the scheduler. \*/  
vTaskStartScheduler();

/\* Will only reach here if there is insufficient heap available to start  
the scheduler. \*/

while(1);  
return 0;  
}

//-----  
void MainTask( void \*pvParameters )  
{  
&nbsp;&nbsp;&nbsp; for( ;; )  
{  
&nbsp;&nbsp; vTaskDelay(10); //–\>\>\> Crash!  
&nbsp;&nbsp; Nop();  
&nbsp; Nop();  
};  
};

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [July 17, 2013, 2:42pm UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818/2 "2013-07-17T14:42:08Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, July 17, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/7d32a74f/#df3d):

> I want to port a project from dsPIC33F to dsPIC33EP256MU810.

As you found out, EDS is not currently supported on the dsPIC.&nbsp; It is supported on PIC24, and there was a reason why the same support was not extended to the dsPIC but to be honest I can’t quite remember what it was - something to do with additional registers being required though.

> I declared MPLAB\_DSPIC\_PORT

That is actually not necessary - the old definitions are maintained in portable.h for backward compatibility with ancient projects (including the demos in the FreeRTOS download - although V7.5.0 has MPLAB X projects for the PIC24 and dsPIC).&nbsp; It won’t do any harm defining it, but its just easier to not define in and instead make sure the correct path is included in your IDEs include path.&nbsp; That is, the path to the correct portmacro.h header file in FreeRTOS/source/portable/MPLAB/…

> Same Project compiled for dsPIC33FJ128MC804 does work fine.

So that is good…but does not necessarily prove it is working correctly unless you have tired all combinations of placement to ensure the EDS extensions are being exercised.

> As my knowledge ends at this point I want to ask you to check this behavior.

Sorry - can’t do that right now, especially as this is your own code rather than supported code.&nbsp; However, I can confirm that yes, there was a problem expected…somewhere.

If you sort this out please be sure to post your work to the FreeRTOS Interactive site.&nbsp; Maybe you will be lucky and somebody else reading this post will have this working already.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 17, 2013, 3:44pm UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818/3 "2013-07-17T15:44:42Z")

</div>

**[groschh](https://sourceforge.net/u/groschh/)** wrote on [Wednesday, July 17, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/7d32a74f/#4bd7):

Dear RichardBarry,

thanks for your fast reply.

if MPLAB\_DSPIC\_PORT is not declared, the compiler will fail to find “portRESTORE\_CONTEXT()”. I can find this Macro in the source only within the defines of MPLAB\_DSPIC\_PORT.

> I can’t quite remember what it was - something to do with additional registers being required though.

Could it be that the DO Stack was the Problem as there is a Stack with four places now for DO Loops?

> especially as this is your own code rather than supported code.

Well my code actually rather consists of a Main Task with an endless loop including a vTaskDelay(10); and the suggested RTOS init. Nothing else. I also tried your Demo Projects with similar modification and same result.

The Question is now, will dsPic33e Family be supported in the near future or would I have to change to another RTOS?

Is there a way to get more support regarding this matter if buying kind of professional Support Ticket or what ever?

Best regards

Heiko

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [July 17, 2013, 4:11pm UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818/4 "2013-07-17T16:11:37Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, July 17, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/7d32a74f/#7362):

> if MPLAB\_DSPIC\_PORT is not declared, the compiler will fail to find “portRESTORE\_CONTEXT()”.

You are right.&nbsp; I forgot that.&nbsp; It has been fixed in V7.5.0 (I think).

> Could it be that the DO Stack was the Problem as there is a Stack with four places now for DO Loops?

Probably.

> will dsPic33e Family be supported in the near future

In the very near future no - in the longer term I can’t say for definite as it will depend on demand.

I will come back to you on that last point.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 18, 2013, 8:16am UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818/5 "2013-07-18T08:16:05Z")

</div>

**[groschh](https://sourceforge.net/u/groschh/)** wrote on [Thursday, July 18, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/7d32a74f/#f3c9):

Richard,

you mentioned Version 7.5.0. coming up.  
When will this be relaesed, do you have a prerelease version for tests?

Best

Heiko

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [July 18, 2013, 8:25am UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818/6 "2013-07-18T08:25:45Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, July 18, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/7d32a74f/#4e9b):

It will be released as soon as I have updated the documentation - in the mean time you can get it out of SVN.&nbsp; It is currently the head revision and will be tagged when the zip files are released (see the “Code” menu item at the top of the SourceForge page when you are viewing this form).

If all goes well today then the .zip files may get uploaded this afternoon.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 9, 2013, 6:19pm UTC](https://forums.freertos.org/t/dspic33ep-project-compiles-but-fails-to-run/2818/7 "2013-10-09T18:19:31Z")

</div>

**[groschh](https://sourceforge.net/u/groschh/)** wrote on [Wednesday, October 09, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/7d32a74f/#a649):

Richard,

hello again.  
please refer to following discussion, solving for the moment the problems I had .  
[https://sourceforge.net/p/freertos/discussion/382005/thread/9df19af7/](https://sourceforge.net/p/freertos/discussion/382005/thread/9df19af7/)

best regards  
Heiko
