[SOLVED]Problems with stack pointer when debugging in internal flash

  • [SOLVED]Problems with stack pointer when debugging in internal flash

    Hello,

    I'm working with SAM-ICE and AT91SAM9XE512. Everything works just fine, when I'm debugging the program running in external SDRAM (with Eclipse and gdb). But if I load the program into the internal flash, the stack pointer has wrong values (or gdb gets wrong values). To show this behaviour, I have logged the debugging session in plain gdb.

    In line 57 of the log file the instruction 'ldr sp, =_sstack' works well and the stack pointer is set to the value 0x304000.

    After 'stmfd sp!, {r0}' (line 62) the stack pointer should be decreased by 4, but still has the value 0x304000.

    'ldmfd sp!, {r0}' (line 75) does not change the stack pointer as well.

    After 'sub r4, sp, #IRQ_STACK_SIZE'(line 96) r4 should have the value 0x303fa0
    (IRQ_STACK_SIZE is 8*3*4), but the value is 0.

    Is this a problem of the SAM-ICE or must I change my gdbinit to get correct results?

    Thanks for your help

    Siegward

    Source Code

    1. user1@core-i3-530:~/Develop/Siegward/EKF-ARM/EKF-ARM-Standalone$
    2. /usr/share/gnuarm.4.4.4-arm-none-eabi/bin/arm-none-eabi-gdb -n -x gdbinit.flash
    3. GNU gdb (GDB) 7.1
    4. Copyright (C) 2010 Free Software Foundation, Inc.
    5. License GPLv3+: GNU GPL version 3 or later
    6. This is free software: you are free to change and redistribute it.
    7. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    8. and "show warranty" for details.
    9. This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-none-
    10. eabi".
    11. For bug reporting instructions, please see:
    12. .
    13. 0x00200efc in ?? ()
    14. Target endianess set to "little endian"
    15. Select auto JTAG speed (65535 kHz)
    16. Resetting target (halt after reset)
    17. Sleep 100ms
    18. Writing 0xA5000004 @ address 0xFFFFFD00
    19. Sleep 10ms
    20. Writing 0x00008000 @ address 0xFFFFFD44
    21. Enable main oscillatorWriting 0x00004001 @ address 0xFFFFFC20
    22. Sleep 100ms
    23. Writing 0x2060BF09 @ address 0xFFFFFC28
    24. Sleep 100ms
    25. Writing 0x207C7F0C @ address 0xFFFFFC2C
    26. Sleep 100ms
    27. Writing 0x00000100 @ address 0xFFFFFC30
    28. Sleep 100ms
    29. Writing 0x00000102 @ address 0xFFFFFC30
    30. Sleep 10ms
    31. JTAG speed set to 9600 kHz
    32. Sleep 100ms
    33. Select flash device: AT91SAM9XE512
    34. Flash download enabled
    35. Loading section .vectors, size 0x6c lma 0x200000
    36. Loading section .exidx, size 0x608 lma 0x20006c
    37. Loading section .ARM.extab, size 0x5b0 lma 0x200674
    38. Loading section .internal_text, size 0xf3f8 lma 0x200c30
    39. Loading section .text, size 0x4d930 lma 0x210028
    40. Loading section .init_array, size 0xc lma 0x25d958
    41. Loading section .data, size 0x944 lma 0x301348
    42. Loading section .external_text, size 0xba058 lma 0x20000000
    43. Loading section .dma_buffers, size 0x400 lma 0x20f00000
    44. Start address 0x200ca0, load size 1148660
    45. Transfer rate: 53 KB/sec, 14917 bytes/write.
    46. (gdb) display /x $pc
    47. 1: /x $pc = 0x200ca0
    48. (gdb) display /x $sp
    49. 2: /x $sp = 0x0
    50. (gdb) i b
    51. No breakpoints or watchpoints.
    52. (gdb) si
    53. 133 ldr pc, =1f
    54. 2: /x $sp = 0x0
    55. 1: /x $pc = 0x200ca4
    56. (gdb)
    57. 159 ldr sp, =_sstack
    58. 2: /x $sp = 0x0
    59. 1: /x $pc = 0x200ca8
    60. (gdb)
    61. resetHandler () at board_cstartup.S:160
    62. 160 stmfd sp!, {r0}
    63. 2: /x $sp = 0x304000
    64. 1: /x $pc = 0x200cac
    65. (gdb)
    66. resetHandler () at board_cstartup.S:161
    67. 161 ldr r0, =LowLevelInit
    68. 2: /x $sp = 0x304000
    69. 1: /x $pc = 0x200cb0
    70. (gdb)
    71. 162 blx r0
    72. 2: /x $sp = 0x304000
    73. 1: /x $pc = 0x200cb4
    74. (gdb)
    75. 164 ldmfd sp!, {r0}
    76. 2: /x $sp = 0x304000
    77. 1: /x $pc = 0x200cb8
    78. (gdb)
    79. 178 ldr r0, =_szero
    80. 2: /x $sp = 0x304000
    81. 1: /x $pc = 0x200cbc
    82. (gdb) b 189
    83. Breakpoint 1 at 0x200cd4: file board_cstartup.S, line 189.
    84. (gdb) c
    85. Continuing.
    86. Breakpoint 1, resetHandler () at board_cstartup.S:189
    87. 189 msr CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT
    88. 2: /x $sp = 0x304000
    89. 1: /x $pc = 0x200cd4
    90. (gdb) si
    91. 190 ldr sp, =_sstack
    92. 2: /x $sp = 0x304000
    93. 1: /x $pc = 0x200cd8
    94. (gdb)
    95. 191 sub r4, sp, #IRQ_STACK_SIZE
    96. 2: /x $sp = 0x304000
    97. 1: /x $pc = 0x200cdc
    98. (gdb) display /x $r4
    99. 3: /x $r4 = 0x0
    100. (gdb) print IRQ_STACK_SIZE
    101. No symbol "IRQ_STACK_SIZE" in current context.
    102. (gdb) si
    103. 194 msr CPSR_c, #ARM_MODE_SVC | F_BIT
    104. 3: /x $r4 = 0x0
    105. 2: /x $sp = 0x304000
    106. 1: /x $pc = 0x200ce0
    107. (gdb)
    108. 195 mov sp, r4
    109. 3: /x $r4 = 0x0
    110. 2: /x $sp = 0x304000
    111. 1: /x $pc = 0x200ce4
    112. (gdb)
    113. resetHandler () at board_cstartup.S:203
    114. 203 LDR r12,=__libc_init_array
    115. 3: /x $r4 = 0x0
    116. 2: /x $sp = 0x0
    117. 1: /x $pc = 0x200ce8
    118. (gdb)
    Display All
  • Hello Siegward,

    Has the problem been resolved by setting the flash wait states correctly in the GDBInit file?

    Best regards
    Alex
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.