Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


[PIC32] undetermined exception in xSemaphoreG

Posted by Erupter on March 24, 2012

I just tried to implement a basic synchronization mechanism.

In the main.c I have

static void prvTermTest (void *pvParameters );
static void prvTaskFeeder (void *pvParameters);
xSemaphoreHandle periodSemaHndl;

void main (void)

xSemaphoreTake(periodSemaHndl, 0);

myresult = xTaskCreate( prvTermTest, "Terminal", 500, NULL, tskIDLE_PRIORITY, &task3);
myresult = xTaskCreate( prvTaskFeeder, "TermFeeder", 200, NULL, tskIDLE_PRIORITY, &task2);


void InitializeRTCC (void)

//wait for the SOSC to be actually running and RTCC to have its clock source

//RTCC interrupt config
mRtccSetIntPriority(2, 3);
//we created a global TIME variable at the beginning of the main.c
//here we set it to some value, doesn't have to mean a specific time
mytime.hour = 0x0;
mytime.min = 0x0;
mytime.sec = 0x0;

//we do the same for the global DATE variable

//we assign the values to the RTCC

mytime.hour = 0x0;
mytime.min = 0x0;
mytime.sec = 0x1;

//here we call the alarm setting macro with our values

//this is a usefull debug point: put a breakpoint here and watch if the values are what you expected them to be

//one alarm will do

//enable the alarm


//RTCC interrupt service routine
void __ISR(_RTCC_VECTOR, ipl2) __RTCCInterrupt(void)

//this is just for testing: if you place a breakpoint here you can have a look at the passing time

//redundant, should already be set
xHigherPriorityTaskWoken = pdFALSE;
// be sure to clear RTCC interrupt flag
//let the main cycles restart
if (tick==0)
xSemaphoreGiveFromISR(periodSemaHndl, xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE)

//this is the sleep flag, you may take actions based on its value
//meaning that the RTC may have risen an interrupt but the device may or
//may not have been sleeping, this tells you which
//RCONbits.SLEEP = 0;

//clear the sleeping led

static void prvTermTest(void* pvParameters)


static void prvTaskFeeder (void *pvParameters)
UINT8 counter = 0;
xSemaphoreTake(periodSemaHndl, portMAX_DELAY);
MPL_LOGD("Counter %d",counter);

What happens is that inside the call to xSemaphoreGiveFromISR, the code reaches line 855 of queue.c

uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
traceQUEUE_SEND_FROM_ISR( pxQueue );

prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );

/* If the queue is locked we do not alter the event list. This will
be done when the queue is unlocked later. */
if( pxQueue->xTxLock == queueUNLOCKED )
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
/* The task waiting has a higher priority so record that a
contextswitch is required. */
==>*pxHigherPriorityTaskWoken = pdTRUE;

At this point execution jumps to the exception handler, with exception code 1C (which is outside the enumerated values) and this line corresponds to line 9D005130 reported below

852: {
853: /* The task waiting has a higher priority so record that a
854: contextswitch is required. */
855: *pxHigherPriorityTaskWoken = pdTRUE;
9D005128 8FC20028 LW V0, 40(S8)
9D00512C 24030001 ADDIU V1, ZERO, 1
9D005130 AC430000 SW V1, 0(V0)
9D005134 0B401454 J 0x9D005150
9D005138 00000000 NOP

I'm clueless to what is happening here.
The max priority in the FreeRTOSConfig.h is 5.
Without the semaphoregive inside the interrupt, the code runs fine (in fact this is the beginning of another project where I reused code working surely in another project).

I'm open to any suggestion.

RE: [PIC32] undetermined exception in xSemaphoreG

Posted by Erupter on March 24, 2012
I forgot: at the beginning of the main.c there is also (obviously, it wouldn't even compile otherwise)

static signed portBASE_TYPE xHigherPriorityTaskWoken;

I also tried putting the above line inside the RTCC ISR as per the examples, didn't change anything.

RE: [PIC32] undetermined exception in xSemaphoreG

Posted by Erupter on March 24, 2012
Ok I was missing the leading & in both xSemaphoreGive and portEND_SWITCHING_ISR.

Now it still crashes but on a different line.

void vListRemove( xListItem *pxItemToRemove )
xList * pxList;

==>pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;

Am still trying to catch what exactly is causing this.
The currentTCB is already gibberish, so I'm having difficulties figuring what task caused the crash and why.

RE: [PIC32] undetermined exception in xSemaphoreG

Posted by Erupter on March 24, 2012
Ok it was just a memory problem: too less assigned to the task and it crashed.

Thank you anyway.

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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner