Marus / cortex-debug

Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers
MIT License
1.01k stars 238 forks source link

STLink And Arm-none-eabi-gdb Works, But Cortex-Debug Gives "0x00001000 in ?? ()" And "Not Implemented..." #133

Open vindicatorr opened 5 years ago

vindicatorr commented 5 years ago

It almost sounds similar to https://github.com/Marus/cortex-debug/issues/105 but I don't get anywhere. I was starting with a simple blink to get the feel for it. The only main difference between working and not working is running in RAM only, vs running from FLASH.

STM32F407GFTx_FLASH.ld (commented out >FLASH stuff, replaced with >RAM):

...
  /* The startup code goes first into FLASH */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >RAM
  /*} >FLASH*/

  /* The program code and other data goes into FLASH */
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >RAM
  /*} >FLASH*/

  /* Constant data goes into FLASH */
  .rodata :
  {
    . = ALIGN(4);
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    . = ALIGN(4);
  } >RAM
  /*} >FLASH*/

  .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >RAM /*>FLASH*/
  .ARM : {
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
  } >RAM
  /*} >FLASH*/

  .preinit_array     :
  {
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
  } >RAM
  /*} >FLASH*/
  .init_array :
  {
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
  } >RAM
  /*} >FLASH*/
  .fini_array :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
  } >RAM
  /*} >FLASH*/

  /* used by the startup to initialize data */
  _sidata = LOADADDR(.data);

  /* Initialized data sections goes into RAM, load LMA copy after code */
  .data : 
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */

    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
  } >RAM /*AT> FLASH*/
...

startup_stm32f407xx.S (commented "@" FLASH related parts, to run in RAM only):

...
Reset_Handler:  
  ldr   sp, =_estack     /* set stack pointer */

/* Copy the data segment initializers from flash to SRAM */  
@   movs  r1, #0
@   b  LoopCopyDataInit

@ CopyDataInit:
@   ldr  r3, =_sidata
@   ldr  r3, [r3, r1]
@   str  r3, [r0, r1]
@   adds  r1, r1, #4

@ LoopCopyDataInit:
@   ldr  r0, =_sdata
@   ldr  r3, =_edata
@   adds  r2, r0, r1
@   cmp  r2, r3
@   bcc  CopyDataInit
@   ldr  r2, =_sbss
@   b  LoopFillZerobss
@ /* Zero fill the bss segment. */  
@ FillZerobss:
@   movs  r3, #0
@   str  r3, [r2], #4

@ LoopFillZerobss:
@   ldr  r3, = _ebss
@   cmp  r2, r3
@   bcc  FillZerobss

/* Call the clock system intitialization function.*/
  bl  SystemInit
...

tasks.json (uncomment for running in RAM only):

...
// "-DVECT_TAB_SRAM",
...

Debug Console for "cortex-debug": FLASH:

Reading symbols from ./build/stm32f4discovery.elf...
done.
0x200003c6 in impure_data ()
Not implemented stop reason (assuming exception): undefined

RAM:

Reading symbols from ./build/stm32f4discovery.elf...
done.
0x00001000 in ?? ()
Not implemented stop reason (assuming exception): undefined

Debug Console for "stlink & gdb": RAM:

st-util: 2019-02-26T18:14:23 INFO common.c: Loading device parameters....
st-util: 2019-02-26T18:14:23 INFO common.c: Device connected is: F4 device, id 0x10016413
st-util: 2019-02-26T18:14:23 INFO common.c: SRAM size: 0x30000 bytes (192 KiB), Flash: 0x100000 bytes (1024 KiB) in pages of 16384 bytes
st-util: 2019-02-26T18:14:23 INFO gdb-server.c: Chip ID is 00000413, Core ID is  2ba01477.
st-util: 2019-02-26T18:14:23 INFO gdb-server.c: Listening at *:4242...
=thread-group-added,id="i1"
GNU gdb (GDB) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
st-util: 2019-02-26T18:14:23 INFO gdb-server.c: Found 6 hw breakpoint registers
st-util: 2019-02-26T18:14:23 INFO gdb-server.c: GDB connected.
0x08009014 in ?? ()
st-util: 2019-02-26T18:14:24 INFO gdb-server.c: Found 6 hw breakpoint registers
Loading section .isr_vector, size 0x188 lma 0x20000000
+download,{section=".isr_vector",section-size="392",total-size="377616"}
+download,{section=".isr_vector",section-sent="392",section-size="392",total-sent="392",total-size="377616"}
Loading section .text, size 0x9ce4 lma 0x20000188
+download,{section=".text",section-size="40164",total-size="377616"}
+download,{section=".text",section-sent="24520",section-size="40164",total-sent="24912",total-size="377616"}
Loading section .rodata, size 0xa0 lma 0x20009e6c
+download,{section=".rodata",section-size="160",total-size="377616"}
Loading section .ARM, size 0x8 lma 0x20009f0c
+download,{section=".ARM",section-size="8",total-size="377616"}
Loading section .init_array, size 0x8 lma 0x20009f14
+download,{section=".init_array",section-size="8",total-size="377616"}
Loading section .fini_array, size 0x4 lma 0x20009f1c
+download,{section=".fini_array",section-size="4",total-size="377616"}
+download,{section=".fini_array",section-sent="4",section-size="4",total-sent="40736",total-size="377616"}
Loading section .data, size 0x9e0 lma 0x20009f20
+download,{section=".data",section-size="2528",total-size="377616"}
Start address 0x20009014, load size 43264
Transfer rate: 35 KB/sec, 3933 bytes/write.
Breakpoint 1, main () at src/main.c:75
75    HAL_Init();
Marus commented 5 years ago

Can you post a minimal example of this, along with instructions on how to compile/run it manually (I'm pretty sure I've got a Nucleo board with a 407 around here somewhere to use) - may just be some assumptions that the extension is making that causes it to send the incorrect commands for running from ram vs from memory.

vindicatorr commented 5 years ago

Whoof, this is a bit of an old issue, but I had moved on, added openocd to my arsenal, progressed with my project and forgot all about this issue.

Since I was about to start on another project, I went ahead and plopped in some of the previous setup code I used to replicate the issue, and it still does.

Also for reference, since I neglected to mention it in my OP, the version I think I used at that time was 0.2.4 and I just tested it again with 0.2.7.

STM32F4Discovery.tar.gz

Just follow the README for changes needed with what works and doesn't work. You also have 2 other debuggers set up for use in launch.json.