PIC32 configISR_STACK_SIZE setting

Hi Folks,
i have two questions – probably someone can help me a little. I’ve read already the whole pdf documention but i could not find a proper answer (that does not mean, that this is not in the documentation). 1) Parameter configISR_STACK_SIZE.
For what is this setting exactly for? 2) Stack question:
In my application the kernel runs at priority 1, MAX_SYSCALL_ISR_PRIO is by default 3. All tasks (6 in total) run on prio 1 either. I have several interrupts that runs on prio >= 4..7, so they are out of reach from FreeRTOS (thats what i’ve understood from the manual). If one of the interrupts is being called, which stack is being used then. For example: If task 2 is currently active and an interrupt >= 4..7 is being raised – will the stack of task 2 will be used? Thanks in advance,
Peter

PIC32 configISR_STACK_SIZE setting

Which port and compiler are you using?

PIC32 configISR_STACK_SIZE setting

Iam running FreeRTOS v6.0.2 on a PIC32MX360F512L and using the Microchip C32 compiler v1.10b.

PIC32 configISR_STACK_SIZE setting

1) Parameter configISR_STACK_SIZE.
For what is this setting exactly for?
This sets the size of the stack that is used when an interrupt occurs.  The PIC32 port implements multiple stacks in software (whereas other hardware platforms do this in hardware).  When an interrupt occurs the stack is switched to the ISR stack to prevent each and every task having to allocate enough stack for interrupts that may nest deeply.
2) Stack question:
In my application the kernel runs at priority 1, MAX_SYSCALL_ISR_PRIO is by default 3. All tasks (6 in total) run on prio 1 either. I have several interrupts that runs on prio >= 4..7, so they are out of reach from FreeRTOS (thats what i’ve understood from the manual). If one of the interrupts is being called, which stack is being used then.
For example: If task 2 is currently active and an interrupt >= 4..7 is being raised – will the stack of task 2 will be used? That depends on how you have implemented the interrupt handler.  If you just use the compiler to generate the interrupt entry and exit code then the task stack will be used – but this is not recommended as it wastes RAM.  If you use the FreeRTOS provided interrupt entry and exit code then the separate ISR stack will be used. Regards.

PIC32 configISR_STACK_SIZE setting

Hi Richard,
thank you for the detailed informations. Regarding that answer i have some more questions. Sorry about that. 1) Regarding my implementation of the interrupts and the stack usage. Iam using the compiler generated interrupt routines ->
void __ISR(_UART_1_VECTOR) UART1_ISR(void).
That means that i can set the parameter configISR_STACK_SIZE to 0, because the stack which is needed to process the interrupt is being nested in the currently active task. Even if this solution is wasting RAM. Correct? 2) If i want to use the FreeRTOS provided interrupt entry and exit code, i have to create my own interrupt service routine(provided with the demos in assembly). So the routine should look something like this: File: UART1_ISR.S – This creates my own ISR entry and exit code. .section .FreeRTOS, “ax”, @progbits
.set noreorder
.set noat
.ent UART1_ISR_WRAPPER UART1_ISR_WRAPPER:
portSAVE_CONTEXT
jal UART1_ISR_HANDLER
nop
portRESTORE_CONTEXT
.end UART1_ISR_WRAPPER File: UART1.c
void __attribute__( (interrupt(ipl2), vector(_UART1_VECTOR))) UART1_ISR_WRAPPER(void); void UART1_ISR_HANDLER(void)
{
  … whithin this i can handle my code as i did before.
  … I can also access my static defined buffer to read and write to it without the need of using the Queue-Functions and the
  … fromISR / toISR functions. Correct?
} 3) Am i right if i say that this interrupt (FreeRTOS provided entry/exit code) is being handled like a “normal” interrupt, that means: 
   An interrupt with a higher priority can interrupt the currently running interrupt? 4) How to check the stack usage within an interrupt (FreeRTOS provided entry/exit code)? Is that being done with a call to
uxTaskGetStackHighWaterMark( NULL );
   within the interrupt? Thanks very very much for all the answers in advance! Kind regards,
Peter

PIC32 configISR_STACK_SIZE setting

1) Regarding my implementation of the interrupts and the stack usage. Iam using the compiler generated interrupt routines ->
void __ISR(_UART_1_VECTOR) UART1_ISR(void).
That means that i can set the parameter configISR_STACK_SIZE to 0, because the stack which is needed to process the interrupt is being nested in the currently active task. Even if this solution is wasting RAM. Correct?
No, because if nothing else the scheduler interrupts will still expect there to be a separate stack.
2) If i want to use the FreeRTOS provided interrupt entry and exit code, i have to create my own interrupt service routine(provided with the demos in assembly). So the routine should look something like this:
If the snipped code is as per the online documentation and provided examples, then yes, otherwise no.  Just do the same as the examples then you will be ok.
[quote]3) Am i right if i say that this interrupt (FreeRTOS provided entry/exit code) is being handled like a "normal" interrupt, that means:
An interrupt with a higher priority can interrupt the currently running interrupt?[/quote]
Yes.  The entry/exit code is designed to allow interrupt nesting while preserving the RAM required.
[quote]4) How to check the stack usage within an interrupt (FreeRTOS provided entry/exit code)? Is that being done with a call to
uxTaskGetStackHighWaterMark( NULL );
within the interrupt?[/quote]
No!  You cannot call functions that don't end in FromISR or FROM_ISR from an interrupt.
uxTaskGetStackHighWaterMark() will only check the high water mark of the task stack, not the interrupt stack.  You can however fill the interrupt stack with a known pattern before calling main(), then write a utility to see how much has been overwritten, or just view it in the debugger.  Be careful not to corrupt the stack that is being used by the currently executing code, which is why I say do it before main() is called.  Alternatively you could just write the pattern at the far end of the stack.
Regards.

PIC32 configISR_STACK_SIZE setting

Hello Richard,
regarding that issue below.
1) Regarding my implementation of the interrupts and the stack usage. Iam using the compiler generated interrupt routines ->
void __ISR(_UART_1_VECTOR) UART1_ISR(void).
That means that i can set the parameter configISR_STACK_SIZE to 0, because the stack which is needed to process the interrupt is being nested in the currently active task. Even if this solution is wasting RAM. Correct?
No, because if nothing else the scheduler interrupts will still expect there to be a separate stack.
Checking fill level of ISR stack: You can however fill the interrupt stack with a known pattern before calling main(), then write a utility to see how much has been overwritten, or just view it in the debugger. Be careful not to corrupt the stack that is being used by the currently executing code, which is why I say do it before main() is called. Alternatively you could just write the pattern at the far end of the stack.
1) Is the ISR stack stored in the structure xISRStack?
2) The stack is being filled from the end of the structure to be beginning?
3) This stack is also being used for the context-switch vPortYieldISR (so thats the reason, why its not to be allowed to configure configISR_STACK_SIZE == 0)? Thanks in advance,
Peter