SPI interrupt with FPU-Thread not working properly

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Nikhil V R
Posts: 12
Joined: Thu Jul 10, 2014 11:18 am

Re: SPI interrupt with FPU-Thread not working properly

Post by Nikhil V R »

CH_IRQ_HANDLER(SysTickVector) {

CH_IRQ_PROLOGUE();

chSysLockFromIsr();
chSysTimerHandlerI();
chSysUnlockFromIsr();

CH_IRQ_EPILOGUE();
}

This part is giving debug error as SV#8 and when I comment CH_IRQ_PROLOGUE(); and CH_IRQ_EPILOGUE(); debug error changed to SV#6.How can I sole this?

CH_IRQ_PROLOGUE() is not called any where in my code other than here.Do i need to call CH_IRQ_PROLOGUE() before calling chSysLockFromIsr(); inside all other ISR?
Nikhil V R
Posts: 12
Joined: Thu Jul 10, 2014 11:18 am

Re: SPI interrupt with FPU-Thread not working properly

Post by Nikhil V R »

I found the problem as stack overflow whenever SPI interrupt is enabled?Can any body suggest how to solve this? Is the problem is with ISR stack?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI interrupt with FPU-Thread not working properly

Post by Giovanni »

In general, if you are going to use any ChibiOS function from an ISR then you need the ISR to be written using ALL those macro, essential OS operations can be performed in there.

If into a library you have an ISR function called xyz() just call xyz() from an ISR written according to rules.

About the stack overflow, it could happen in any stack, not just the IRQ stack, try enlarging all them if you suspect there is an overflow.

About the SPI, why the ST library if I may ask?

Giovanni
Nikhil V R
Posts: 12
Joined: Thu Jul 10, 2014 11:18 am

Re: SPI interrupt with FPU-Thread not working properly

Post by Nikhil V R »

do {
cp = cp->p_next;
} while (cp->p_prio >= tp->p_prio);

after solving stack overflow my code is getting stuck inside this loop.Any suggestions pls?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI interrupt with FPU-Thread not working properly

Post by Giovanni »

That can happen only because a corruption of the ready list, you must be doing something strange somewhere but I have no elements for a meaningful suggestion.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI interrupt with FPU-Thread not working properly

Post by Giovanni »

Something like this could be caused by readying up a thread that is already in the ready list, search for something that could cause this. It is strange that some assertion has not been triggered.

Giovanni
Nikhil V R
Posts: 12
Joined: Thu Jul 10, 2014 11:18 am

Re: SPI interrupt with FPU-Thread not working properly

Post by Nikhil V R »

Hi Giovanni,

When I made CH_DBG_SYSTEM_STATE_CHECK = TRUE, panic msg shows as SV#4, misplaced @p chSysLock()

I have four threads and initialization is given below,

void Initialize_Threads(void) {

static WORKING_AREA(Task1, 1536);
static WORKING_AREA(Task2, 3584);
static WORKING_AREA(Task3, 3524);
static WORKING_AREA(Task4, 1024);

Thread_Id1 = chThdCreateStatic(Task1, sizeof(Task1), HIGHPRIO, Thread1, NULL);
Thread_Id2 = chThdCreateStatic(Task2, sizeof(Task2), HIGHPRIO, Thread2, NULL);
Thread_Id3 = chThdCreateStatic(Task3, sizeof(Task3), HIGHPRIO, Thread3, NULL);
Thread_Id4 = chThdCreateStatic(Task4, sizeof(Task4), HIGHPRIO, Thread4, NULL);

}

msg_t Thread1(void *arg)
{
(void)arg;
chRegSetThreadName("Thread1");
while (TRUE) {

/* Task */

chThdSleepMilliseconds( 2 );

}
}

Thread 2 thread 3 and thread 4 are also same like thread1. Before calling chThdSleepMilliseconds( 2 ); dbg_lock_cnt = 1.This variable is setting by

chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK);while creating the thread.

So Im getting a debugging error as SV#4, misplaced @p chSysLock().How can I solve this?

without giving chThdSleepMilliseconds how can I achieve context switching?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI interrupt with FPU-Thread not working properly

Post by Giovanni »

sv#4 means that somewhere there are probably two consecutive chSysLock(), the function is not reentrant and that is the error you are getting.

In order to yield control to other threads (with equal priority) the function to call is chThdYield().

Giovanni
Nikhil V R
Posts: 12
Joined: Thu Jul 10, 2014 11:18 am

Re: SPI interrupt with FPU-Thread not working properly

Post by Nikhil V R »

Is it possible to change priority of main thread?
Post Reply