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

dsPIC33F keeps crashing: stack error

Posted by https://www.google.com/accounts on November 13, 2011
I have modified the standard demo code for the PIC24F/dsPIC33F port. I just want to get a feel of how FreeRTOS works. I'm using the MPLAB simulator (no hardware yet.)

The basic program just launches the watchdog task and goes idle, waking up only every 500ms to serve the watchdog. It runs the task once, but then crashes. I plan to add a few more tasks later but I thought I'd start off small.

My code for main.c is below (the rest of the code in the demo is unmodified):


/* Standard includes. */
#include

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"

/* Application includes. */
#include "BlockQ.h"
#include "crflash.h"
#include "blocktim.h"
#include "integer.h"
#include "comtest2.h"
#include "partest.h"
#include "lcd.h"
#include "timertest.h"
#include "portmacro.h"

void pre_RTOS_init_hardware()
{
// e.g. setup CPU clock/PLL
// setup analog inputs
// setup uart config
// etc.
}

/**
* Watchdog task. This periodically runs (at least once a second) to
* clear the watchdog. The watchdog will reset the processor if more
* than one second elapses between watchdog events. The watchdog has
* a very high priority level but it only executes every 500ms.
*/
void vWatchdogTask(void *pvParameters)
{
for(;;)
{
// Here we would clear the WDT (TODO.)
vTaskDelay(500 / portTICK_RATE_MS);
}
}

/**
* Idle hook. This doesn't execute anything.
* TODO: Low power mode.
*/
void vApplicationIdleHook()
{
vCoRoutineSchedule();
}

int main()
{
// Set up the hardware (before the RTOS scheduler starts.)
pre_RTOS_init_hardware();

// Create the watchdog task. This periodically clears the WDT.
xTaskCreate(vWatchdogTask, (signed char*) "Watchdog", 16, NULL, 0, NULL );

// Start the scheduler. This function should not return as it causes the execution
// context to change from main() to one of the created tasks.
vTaskStartScheduler();

// Should never get here.
while(1);
return 0;
}


The crash:

CORE-E0002: Trap due to misaligned data word access, occurred from instruction at 0x001de8

CORE-E0003: Trap due to unimplemented RAM memory access, occurred from instruction at 0x001de8

CORE-E0001: Trap due to stack error, occurred from instruction at 0x001de8

CORE-W0008: Software Reset Instruction called at PC=0x0002be


I'm sure I must have missed something out but I can't think what it is. If more info is needed please let me know.

Thanks
Tom

RE: dsPIC33F keeps crashing: stack error

Posted by Richard on November 13, 2011
You have only allocated 16 words of stack. You need to allocate at least configMINIMAL_STACK_SIZE bytes (taking the value form the original demo), more if you task does anything other than calling a few self defined functions that don't use much stack.

I would also suggest taking the call to the co routine schedule out unless you have co-routines too.

Regards.

RE: dsPIC33F keeps crashing: stack error

Posted by https://www.google.com/accounts on November 13, 2011
Thanks Richard, that solved the problem.


[ 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