cancel
Showing results for 
Search instead for 
Did you mean: 

I can't seem to trigger PendSV

sailorembedded
Associate III

Hi, I have created this kernel for an ARM Cortex M3, on an Atmel (microchip) board, and now I am porting it to Nucleo f767zi.

I thought it would be an easier task, just adapting the HAL calls, and kernel (C and ASM) routines would keep the same. But I am having an strange behavior: when SysTick handler is called (and it is the one who triggers PendSV) my CONTROL == 0x01, which means I am not on priviliged mode. How could that be possible?

This is how I set my interrupts on NVIC:

HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

/* System interrupt init*/
HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
HAL_NVIC_SetPriority(SVCall_IRQn, 7, 7);
HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
HAL_NVIC_SetPriority(PendSV_IRQn, 8, 8);
HAL_NVIC_SetPriority(SysTick_IRQn, 7, 7);
HAL_NVIC_SetPriority(USART3_IRQn, 9, 9);

PendSV is being triggered as usual:
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;

I end up getting a hard fault:

Thread #1 57005 (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)
HardFault_Handler() at stm32f7xx_it.c:85 0x8002196
<signal handler called>() at 0xfffffff1

Does this signal handler called at 0xfffffff1 means the system got a nested interrupt?

Any feedback is appreciated.

7 REPLIES 7
Pavel A.
Evangelist III

STM32F7 is not CM3. It is CM7. What you can do:

- Get the "Cube" library package for STM32F7 and look how PendSV is handled in FreeRTOS.

https://github.com/STMicroelectronics/STM32CubeF7/blob/0ca53f3fca70b418d093902d9c009967c5b93cef/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1/port.c#L491

 

 I am not on priviliged mode. How could that be possible?

Perhaps, stack corruption occurred, or other bug. Use the Fault analyzer tool of CubeIDE to get clues. Yes, values like 0xfffffff1 on call stack mean nested exceptions.

I understand CM7 != CM3 but both have the same architecture regarding register file and interrupt management, or am I missing something? That is why I thought the kernel port would be easier.

Btw, I was able to port a version that does not use MSP and PSP and System Calls. Uses only MSP and system calls are simple function calls. This one worked just by plugging in and rearranging the BSP related stuff. 

Pavel A.
Evangelist III

Not sure what's missing in your code - but something should be missing, because your code crashes and FreeRTOS works.

 

Was looking at a book, see when on SysTick Handler, the nPRIV bit of Control is 1, even though the system is said to be in privileged mode. (

sailorembedded_1-1699377627615.png

Martin, Trevor. The Designer's Guide to the Cortex-M Processor Family

Bob S
Principal

nPRIV indicates the privilege level or THREAD mode.  Handler mode (interrupts/exceptions) ALWAYS runs in privileged mode.  See ST's PM0253 (STM32F7/H7 Programming manual) section 2.1.1.

sailorembedded
Associate III

If I had known before I wouldn't assume that was the problem I cant trigger PendSV.