This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to invoke arm cortex m3 pendsv handle

Note: This was originally posted on 4th September 2013 at http://forums.arm.com

I try to invoke pendsv handle after svc. I can enter svc_isr, but after exit svc_isr, can not enter pendsv_handle, direct go to deadloop.
Can not go to pendsv_handle.

dump 0xe000ed04

(gdb) x/1xw 0xe000ed04
0xe000ed04: 0x1080e000[size=2]
[/size][size=2]It looks good.[/size]
Any suggest? Thank you for your help.

environment:
gcc
stm32discovery board

my code:
# test pendSV handler

.equ STACK_TOP, 0x20000800
.text
.global _start
.code 16
.syntax unified
_start:
  .word STACK_TOP, start
  .type start, function @ let lsb to 1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word svc_isr+1 @ svc isr
  .word int_isr+1
  .word int_isr+1
  .word pendsv_handle+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1
  .word int_isr+1

start:

@ ref: @ Cortex™-M3 Technical Reference Manual (file name: DDI0337E_cortex_m3_r1p1_trm.pdf)
@    System Handler Priority Registers (p8-27)
  @ pendsv priority
  ldr r0, =0xe000ed22
  mov r1, #0xff
  strb r1, [r0]

  @ systick priority
  ldr r0, =0xe000ed23
  mov r1, #0xff
  strb r1, [r0]

  @ svc priority
  ldr r0, =0xe000ed1f
  mov r1, #0xff
  strb r1, [r0]

  cpsie i

  svc 0

@ watch 0xe000ed24, 0xe000ed04 ref: arm cortex-m3: 嵌入式系統設計入門 p8-9

  push {r0}

deadloop:
  nop
  push {r0}
  b deadloop

pendsv_handle:
  movs r2, #0x12
  nop
  bx lr

svc_isr:
  @ enable pendsv ref: STM32F207 高性能网络型 MCU 嵌入式系统设计 p 412
  ldr r0, =0xe000ed04
  ldr r1, [r0]
  orr r1, #0x10000000
  str r1, [r0]
  nop
  movs r3, #0x56
  bx lr

int_isr:
  nop
  movs r1, #0xf
  push {r1}
  bx lr

.data
.space  0x200, 0
psp_stack_top:

.space  0x400, 0
msp_stack_top:
             

  • Note: This was originally posted on 4th September 2013 at http://forums.arm.com

    After going through your code I found the priority level of SVC and PendSV exceptions are set at 0xFF (Same priority).
    To execute PendSV exception within SVC handler you need to configure PendSV exception priority higher than SVC priority.
    @ pendsv priority
      ldr r0, =0xe000ed22
      mov r1, #0xf0
      strb r1, [r0]
    Try with the above code snippet and check if you are able to invoke PendSV handler or not



  • Note: This was originally posted on 4th September 2013 at http://forums.arm.com

    May be the PendSV priority is still same as SVC.
    To make sure please try with highest priority for PendSV and check
    ldr r0, =0xe000ed22
      mov r1, #0x00
      strb r1, [r0]
    It should work. You should able to invoke PendSV handler.
    Feel free to contact me further
    PendSV handler will be invoked after the execution of SVC handler (svc_isr) in your case even if the priorities are same.
    From the value of the register it looks the PendSV is already requested. Please read the status registers SHCSR and ICSR
  • Note: This was originally posted on 5th September 2013 at http://forums.arm.com

    I change PendSV priority to 0x00, but still fait to run pendsv_isr

    I dump the SHCSR and ICSR.
    in svc_isr
    (gdb) x/1xw 0xe000ed24
    0xe000ed24: 0x00000080
    (gdb) x/1xw 0xe000ed04
    0xe000ed04: 0x1080e80b


    exit svc_isr


    (gdb) x/1xw 0xe000ed24
    0xe000ed24: 0x00000000

    (gdb) x/1xw 0xe000ed04
    0xe000ed04: 0x1080e000

    I try to use systick handle, but the same result, after exit systick_handle, it never run pendsv_isr.

    compile command:

    arm-none-eabi-gcc -nostartfiles -fno-common -O0 -g -mcpu=cortex-m3 -mthumb  -c pendsv.S
    arm-none-eabi-ld -Ttext 0x0 -Tdata 0x20000000 -Tbss 0x20000100 -o pendsv.elf pendsv.o
    arm-none-eabi-objcopy -R .data -O binary pendsv.elf pendsv.bin
  • Note: This was originally posted on 5th September 2013 at http://forums.arm.com

    I understood your problem now. The reason for which it is not able to process PendSV and SysTick interrupt handler is the following
    The register DHCSR, bit C_MASKINTS is set, which restricts (From CortexM3 TRM)
    [font="TimesNewRomanPSMT"][size="1"][font="Arial"][size="2"][3] C_MASKINTS RW When debug is enabled, the debugger can write to this bit to maskPendSV, SysTick and external configurable interrupts:

    0 = Do not mask.

    1 = Mask PendSV, SysTick and external configurable interrupts.


    It restricts the PendSV and SysTick interrupts. Clear the bit and check
    Let me know if you succeed in invoking the handlers

    [/size][/font][/size][/font]
  • Note: This was originally posted on 5th September 2013 at http://forums.arm.com

    Hi prasant,
    I dump the DHCSR
    (gdb) x/1xw 0xE000EDF0
    0xe000edf0: 0x00030003

    C_MASKINTS is not be set.

    I use st-util. and gdb connect to the stm32 discovery board.
  • Note: This was originally posted on 5th September 2013 at http://forums.arm.com

    From the DHCSR register value, it is known that the processor in is Halt Debugging Mode.
    It is masking PendSV, SysTick and External interrupts, therefore you are not able to invoke those exceptions
    Try to execute in non-debug mode (without breakpoint) and check.
  • Note: This was originally posted on 6th September 2013 at http://forums.arm.com

    ok. I really know what's happen.
    orignal assembly version can work fine.
    but the scenario is
    When exit svc_isr, not immediately enter to pendsv_handle,in deadloop, spend a little time,
    it will enter pendsv_handle.

    prasant, thank you for your help.
    I am so happy that I understand the pendsv handle process.