Skip to main content
Graduate
November 5, 2023
Question

I can't seem to trigger PendSV

  • November 5, 2023
  • 4 replies
  • 3746 views

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.

    This topic has been closed for replies.

    4 replies

    Super User
    November 5, 2023

    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.

    Graduate
    November 6, 2023

    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.

    Graduate
    November 6, 2023

    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. 

    Super User
    November 6, 2023

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

     

    Graduate
    November 7, 2023

    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

    Super User
    November 7, 2023

    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.

    Graduate
    November 7, 2023

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