groschh wrote on Wednesday, July 17, 2013:
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 = 0x32;
_PSVPAG = 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 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 DSWPAG
MOV _uxCriticalNesting, W0
…
MOV W0, _uxCriticalNesting
POP DSWPAG
POP DSRPAG
POP CORCON
….
So the project compiles and starts running. If reaching 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 ) /* 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();
xTaskCreate( MainTask, (signed char*) “Main”, 300, NULL, Default_TASK_PRIORITY, 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 )
{
for( ;; )
{
vTaskDelay(10); //–>>> Crash!
Nop();
Nop();
};
};