Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

vTaskSwitchContext not working on PIC32

Posted by Chris Verges on September 16, 2008
Hey all,

I posted a message the other day regarding problems with the PIC32 and the MPLAB SIM environment. As I poked around some more, it turns out that the problem may be more involved.

Within a single time slice, prvIdleTask performs as expected -- the PC works down through the function to vApplicationIdleHook and then loops. I was able to confirm this by toggling some GPIO pins and watching them with an oscilloscope.

During the evaluation of line 1699 in tasks.c, a "sltiu v0,v0,2" instruction is issued. The next command should be "bne v0,zero,0x9d0014f4." However, the PC instead jumps to 9FC0_1200, which is the location for portSAVE_CONTEXT from ISR_Support.h. So I'm guessing that some kind of timer triggered off an asynchronous event, and we're now entering vTaskSwitchContext.

vTaskSwitchContext processes through, and as portRESTORE_CONTEXT is called, we end with our "ERET" instruction at 9D00_4B78. But instead of jumping back to where we were at 9D00_14F4, we jump right back to portSAVE_CONTEXT and begin the process anew. This continues ad infinium, causing the simulator to crash (due to a spurious error related to "sd ra,-1(ra)" being processed as NOP) and the real PIC32 board to hang.

The full contents of FreeRTOSConfig.h are below. Anyone have an idea on how to solve this one? Is this a bug in v5.0.3, or is it a user error?

Thanks,
Chris



#define configUSE_PREEMPTION1
#define configUSE_IDLE_HOOK1
#define configUSE_TICK_HOOK0
#define configTICK_RATE_HZ( ( portTickType ) 1000 )
#define configCPU_CLOCK_HZ( ( unsigned portLONG ) 80000000UL )
#define configPERIPHERAL_CLOCK_HZ( ( unsigned portLONG ) 40000000UL )
#define configMAX_PRIORITIES( ( unsigned portBASE_TYPE ) 5 )
#define configMINIMAL_STACK_SIZE( 400 )
#define configISR_STACK_SIZE( 500 )
#define configTOTAL_HEAP_SIZE( ( size_t ) 28000 )
#define configMAX_TASK_NAME_LEN( 8 )
#define configUSE_TRACE_FACILITY0
#define configUSE_16_BIT_TICKS0
#define configIDLE_SHOULD_YIELD1
#define configUSE_MUTEXES1
#define configCHECK_FOR_STACK_OVERFLOW2
#define configQUEUE_REGISTRY_SIZE0

#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )

#define INCLUDE_vTaskPrioritySet1
#define INCLUDE_uxTaskPriorityGet1
#define INCLUDE_vTaskDelete0
#define INCLUDE_vTaskCleanUpResources0
#define INCLUDE_vTaskSuspend1
#define INCLUDE_vTaskDelayUntil1
#define INCLUDE_vTaskDelay1
#define INCLUDE_uxTaskGetStackHighWaterMark1

#define configKERNEL_INTERRUPT_PRIORITY0x01

#define configMAX_SYSCALL_INTERRUPT_PRIORITY0x03

RE: vTaskSwitchContext not working on PIC32

Posted by Richard on September 17, 2008
Exiting one interrupt then entering another is not necessarily an error - this could be a legitimate execution patter especially if interrupts are nesting.

It is my understanding the the simulator is a bit 'limited' when it comes to PIC32. I'm sure it will be improved.

Which hardware are you using/do you have access to an Explorer 16? Ideally can you confirm that you have the demo as provided in the FreeRTOS.org download running before making any modifications?

If you have different hardware, then can you try a simple LED flashing example first - see http://www.freertos.org/porting-a-freertos-demo-to-different-hardware.html .

The PIC32 port is being used on some quite complex projects so I am as confident as I can be that it is sound, but obviously I cannot guarantee it. I too have used it quite extensively.

Have you checked that you are not overflowing your stacks?

Regards.

SOLVED - vTaskSwitchContext on PIC32

Posted by Chris Verges on September 17, 2008
Hi Richard,

Thanks for the posting. There definitely wasn't any overflowing of stacks; I used an LED-style example to do debugging to determine if this was the case.

After comparing against the demo code, I found that I had missed a tiny #pragma config declaration. Once I corrected that, the timers seemed to fire off correctly, and context switching worked as expected. So chalk this one up to user error. :-)

Thanks for taking the time to look into it!

Chris


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists