interoberlin / nRF51-playground

Playground for our nRF51822 Bluetooth Low Energy experiments
https://www.interoberlin.de/blog/category/projects/ble/
9 stars 2 forks source link

Error: nrf51.cpu -- clearing lockup after double fault #4

Closed matthiasbock closed 8 years ago

matthiasbock commented 8 years ago
$ make clean all
rm -f main *.o *.out *.bin *.elf *.hex *.map
/usr/bin/arm-none-eabi-gcc -std=gnu99 -Wall -g -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -c system_nrf51.c -o system_nrf51.o
/usr/bin/arm-none-eabi-gcc -std=gnu99 -Wall -g -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -c nrf_delay.c -o nrf_delay.o
/usr/bin/arm-none-eabi-gcc -std=gnu99 -Wall -g -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -c main.c -o main.o
main.c: In function '_exit':
main.c:15:6: warning: number of arguments doesn't match built-in prototype [enabled by default]
 void _exit() {};
      ^
/usr/bin/arm-none-eabi-ld -L /usr/lib/gcc/arm-none-eabi/4.8/armv6-m/ -L /usr/lib/arm-none-eabi/newlib/armv6-m/ -T gcc_nrf51_blank.ld -Map main.map system_nrf51.o nrf_delay.o main.o -o main.elf
/usr/bin/arm-none-eabi-ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000000000000
/usr/bin/arm-none-eabi-size main.elf
   text    data     bss     dec     hex filename
    568       4       0     572     23c main.elf
/usr/bin/arm-none-eabi-objcopy -Oihex main.elf main.hex
$ arm-none-eabi-gdb main.elf 
GNU gdb (7.7.1+dfsg-1+6) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main.elf...done.
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0xfffffffe in ?? ()
(gdb) continue
Continuing.
nrf51.cpu -- clearing lockup after double fault

Program received signal SIGINT, Interrupt.
0xfffffffe in ?? ()

Meanwhile OpenOCD outputs:

...
** Programming Finished **
Info : accepting 'gdb' connection on tcp/3333
Error: nrf51.cpu -- clearing lockup after double fault
Polling target nrf51.cpu failed, trying to reexamine
Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints
...
matthiasbock commented 8 years ago

The double fault is probably related to the warning "cannot find entry symbol Reset_Handler"...

matthiasbock commented 8 years ago

Single-stepping through the code using gdb reveals, that the exception occured, whenever trying to push values to the stack.

Recent commits fix this issue by setting valid stack pointer.

(gdb) load
Loading section .text, size 0x27c lma 0x0
Loading section .ARM.exidx, size 0x8 lma 0x27c
Loading section .data, size 0x4 lma 0x284
Start address 0x0, load size 648
Transfer rate: 1 KB/sec, 216 bytes/write.
(gdb) s
Single stepping until exit from function Reset_Handler,
which has no line number information.
SystemInit () at system_nrf51.c:62
62      {
(gdb) i r
r0             0xf42400 16000000
r1             0x284    644
r2             0x20000000       536870912
r3             0x0      0
r4             0xffffffff       -1
r5             0xffffffff       -1
r6             0xffffffff       -1
r7             0xffffffff       -1
r8             0xffffffff       -1
r9             0xffffffff       -1
r10            0xffffffff       -1
r11            0xffffffff       -1
r12            0xffffffff       -1
sp             0x480a2100       0x480a2100
lr             0x29     41
pc             0x64     0x64 
xPSR           0x61000000       1627389952
(gdb) set $sp=0x20002000
(gdb) si
0x00000066      62      {
(gdb) disas
Dump of assembler code for function SystemInit:
   0x00000064 <+0>:     push    {r7, lr}
=> 0x00000066 <+2>:     add     r7, sp, #0
   0x00000068 <+4>:     bl      0xa8 
   0x0000006c <+8>:     adds    r3, r0, #0
   0x0000006e <+10>:    cmp     r3, #0
   0x00000070 <+12>:    beq.n   0x80 
   0x00000072 <+14>:    ldr     r3, [pc, #40]   ; (0x9c )
   0x00000074 <+16>:    ldr     r2, [pc, #40]   ; (0xa0 )
   0x00000076 <+18>:    str     r2, [r3, #0]
   0x00000078 <+20>:    ldr     r3, [pc, #40]   ; (0xa4 )
   0x0000007a <+22>:    movs    r2, #128        ; 0x80
   0x0000007c <+24>:    lsls    r2, r2, #8
   0x0000007e <+26>:    str     r2, [r3, #0]
   0x00000080 <+28>:    bl      0x128 
   0x00000084 <+32>:    adds    r3, r0, #0
   0x00000086 <+34>:    cmp     r3, #0
   0x00000088 <+36>:    beq.n   0x96 
   0x0000008a <+38>:    movs    r3, #128        ; 0x80
   0x0000008c <+40>:    lsls    r2, r3, #23
   0x0000008e <+42>:    movs    r3, #193        ; 0xc1
   0x00000090 <+44>:    lsls    r3, r3, #3
   0x00000092 <+46>:    movs    r1, #1
   0x00000094 <+48>:    str     r1, [r2, r3]
   0x00000096 <+50>:    mov     sp, r7
   0x00000098 <+52>:    pop     {r7, pc}
   0x0000009a <+54>:    nop                     ; (mov r8, r8)
   0x0000009c <+56>:    lsls    r4, r0, #20
   0x0000009e <+58>:    ands    r0, r0
   0x000000a0 <+60>:    vaddl.u16       q14, d15, d7
   0x000000a4 <+64>:    ldr     r0, [r3, #64]   ; 0x40
   0x000000a6 <+66>:    ands    r0, r0
End of assembler dump.
(gdb)