ERROR: could not write CPU register MSP

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • ERROR: could not write CPU register MSP

    I'm trying debug a stm32f103rb with 20k RAM. I'm using a JLink-EDU. But I get the following error message:

    "ERROR: Could not write CPU register MSP: written: 0x20004FFF"

    The programm is flashed, and it works (toggled LED), but it does not stoped at the breakpoint. The gdbserver has the version 4.12.

    My gdb commands:

    monitor speed 10
    monitor flash device = STM32F103RB
    monitor endian little
    monitor flash breakpoints = 1
    monitor flash download = 1
    load "$(TARGET_OUTPUT_FILE)"
    monitor reg r13 = (0x00000000)
    monitor reg pc = (0x00000004)

    ---

    TARGET_OUTPUT_FILE="...../main.elf"

    What is the problem?
  • My link script:

    /*
    Default linker script for STM32F103RB_128K_20K
    Copyright RAISONANCE S.A.S. 2008
    */

    /* include the common STM32F103RB sub-script */

    /* Common part of the linker scripts for STM32 devices*/

    /* default stack sizes.

    These are used by the startup in order to allocate stacks for the different modes.
    */

    __Stack_Size = 1024 ;

    PROVIDE ( _Stack_Size = __Stack_Size ) ;

    __Stack_Init = _estack - __Stack_Size ;

    /*"PROVIDE" allows to easily override these values from an object file or the commmand line.*/
    PROVIDE ( _Stack_Init = __Stack_Init ) ;

    /*
    There will be a link error if there is not this amount of RAM free at the end.
    */
    _Minimum_Stack_Size = 0x100 ;


    /* include the memory spaces definitions sub-script */
    /*
    Linker subscript for STM32F10x definitions with 128K Flash and 20K RAM */

    /* Memory Spaces Definitions */

    MEMORY
    {
    RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
    FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K
    FLASHB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    }

    ENTRY(Reset_Handler)

    /* higher address of the user mode stack */
    _estack = ORIGIN(RAM)+LENGTH(RAM);

    /* include the sections management sub-script for FLASH mode */

    /* Sections Definitions */

    SECTIONS
    {
    /* for Cortex devices, the beginning of the startup code is stored in the .isr_vector section, which goes to FLASH */
    .isr_vector :
    {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
    } >FLASH

    /* the program code is stored in the .text section, which goes to Flash */
    .text :
    {
    . = ALIGN(4);

    *(.text .text.* .gnu.linkonce.t.*) /* remaining code */
    *(.rodata) /* read-only data (constants) */
    *(.rodata*)
    *(.glue_7)
    *(.glue_7t)

    . = ALIGN(4);
    _etext = .;
    /* This is used by the startup in order to initialize the .data secion */
    _sidata = _etext;
    } >FLASH



    /* This is the initialized data section
    The program executes knowing that the data is in the RAM
    but the loader puts the initial values in the FLASH (inidata).
    It is one task of the startup to copy the initial values from FLASH to RAM. */
    .data : AT ( _sidata )
    {
    . = ALIGN(4);
    /* This is used by the startup in order to initialize the .data secion */
    _sdata = . ;

    *(.data .data* .gnu.linkonce.d.*)

    . = ALIGN(4);
    /* This is used by the startup in order to initialize the .data secion */
    _edata = . ;
    } >RAM



    /* This is the uninitialized data section */
    .bss :
    {
    . = ALIGN(4);
    /* This is used by the startup in order to initialize the .bss secion */
    _sbss = .;

    *(.bss .bss.* .gnu.linkonce.b.*)
    *(COMMON)

    . = ALIGN(4);
    /* This is used by the startup in order to initialize the .bss secion */
    _ebss = . ;
    } >RAM

    PROVIDE ( end = _ebss );
    PROVIDE ( _end = _ebss );

    /* This is the user stack section
    This is just to check that there is enough RAM left for the User mode stack
    It should generate an error if it's full.
    */
    ._usrstack :
    {
    . = ALIGN(4);
    _susrstack = . ;

    . = . + _Minimum_Stack_Size ;

    . = ALIGN(4);
    _eusrstack = . ;
    } >RAM



    /* this is the FLASH Bank1 */
    /* the C or assembly source must explicitly place the code or data there
    using the "section" attribute */
    .b1text :
    {
    *(.b1text) /* remaining code */
    *(.b1rodata) /* read-only data (constants) */
    *(.b1rodata*)
    } >FLASHB1

    /* this is the EXTMEM */
    /* the C or assembly source must explicitly place the code or data there
    using the "section" attribute */

    /* EXTMEM Bank0 */
    .eb0text :
    {
    *(.eb0text) /* remaining code */
    *(.eb0rodata) /* read-only data (constants) */
    *(.eb0rodata*)
    } >EXTMEMB0

    /* EXTMEM Bank1 */
    .eb1text :
    {
    *(.eb1text) /* remaining code */
    *(.eb1rodata) /* read-only data (constants) */
    *(.eb1rodata*)
    } >EXTMEMB1

    /* EXTMEM Bank2 */
    .eb2text :
    {
    *(.eb2text) /* remaining code */
    *(.eb2rodata) /* read-only data (constants) */
    *(.eb2rodata*)
    } >EXTMEMB2

    /* EXTMEM Bank0 */
    .eb3text :
    {
    *(.eb3text) /* remaining code */
    *(.eb3rodata) /* read-only data (constants) */
    *(.eb3rodata*)
    } >EXTMEMB3



    /* after that it's only debugging information. */

    /* remove the debugging information from the standard libraries */
    DISCARD :
    {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
    }

    /* Stabs debugging sections. */
    .stab 0 : { *(.stab) }
    .stabstr 0 : { *(.stabstr) }
    .stab.excl 0 : { *(.stab.excl) }
    .stab.exclstr 0 : { *(.stab.exclstr) }
    .stab.index 0 : { *(.stab.index) }
    .stab.indexstr 0 : { *(.stab.indexstr) }
    .comment 0 : { *(.comment) }
    /* DWARF debug sections.
    Symbols in the DWARF debugging sections are relative to the beginning
    of the section so we begin them at 0. */
    /* DWARF 1 */
    .debug 0 : { *(.debug) }
    .line 0 : { *(.line) }
    /* GNU DWARF 1 extensions */
    .debug_srcinfo 0 : { *(.debug_srcinfo) }
    .debug_sfnames 0 : { *(.debug_sfnames) }
    /* DWARF 1.1 and DWARF 2 */
    .debug_aranges 0 : { *(.debug_aranges) }
    .debug_pubnames 0 : { *(.debug_pubnames) }
    /* DWARF 2 */
    .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
    .debug_abbrev 0 : { *(.debug_abbrev) }
    .debug_line 0 : { *(.debug_line) }
    .debug_frame 0 : { *(.debug_frame) }
    .debug_str 0 : { *(.debug_str) }
    .debug_loc 0 : { *(.debug_loc) }
    .debug_macinfo 0 : { *(.debug_macinfo) }
    /* SGI/MIPS DWARF 2 extensions */
    .debug_weaknames 0 : { *(.debug_weaknames) }
    .debug_funcnames 0 : { *(.debug_funcnames) }
    .debug_typenames 0 : { *(.debug_typenames) }
    .debug_varnames 0 : { *(.debug_varnames) }
    }
  • With this gdb commands, I get not the error message "Could not write....".

    monitor speed 10
    monitor flash device = STM32F103RB
    monitor endian little
    monitor flash download = 1
    monitor flash breakpoints = 1
    load "$(TARGET_OUTPUT_FILE)"
    monitor reg r13 = (0x00000000)
    monitor reg pc = (0x00000004)
    monitor reset
    monitor go

    The microcontroller running, but it does not stop at main.
  • There are the same problem with the following gdb commands:

    monitor speed 10
    monitor flash device = STM32F103RB
    monitor endian little
    monitor flash download = 1
    monitor flash breakpoints = 1
    load "$(TARGET_OUTPUT_FILE)"
    monitor reg r13 = (0x00000000)
    monitor reg pc = (0x00000004)
    monitor reset
  • The complete GDB-Server log-data:

    Connected to 127.0.0.1
    Reading all registers
    Read 4 bytes @ address 0x00000000 (Data = 0x20004FFF)
    JTAG speed set to 10 kHz
    JTAG speed set to 10 kHz
    Select flash device: STM32F103RB
    Select flash device: STM32F103RB
    Target endianess set to "little endian"
    Target endianess set to "little endian"
    Flash download enabled
    Flash download enabled
    Flash breakpoints enabled
    Flash breakpoints enabled
    Writing register (SP = 0x20004FFF)
    Writing register (SP = 0x20004FFF)
    Writing register (PC = 0x0800025D)
    Writing register (PC = 0x0800025D)
    Read 2 bytes @ address 0x08000110 (Data = 0xF000)
    Read 2 bytes @ address 0x08000110 (Data = 0xF000)
    Setting breakpoint @ address 0x08000110, Size = 2, BPHandle = 0x0001
    Starting target CPU...
    ERROR: Could not write CPU register MSP: Written: 0x20004FFF, Read
    0x20004FFC
    All pending breakpoints removed
    Connection to debugger closed !
  • OK, I think it is a problem of Codeblocks and not of the JLink.

    In Eclipde there are 2 sections for gdb commands.
    - Initialization Commands
    - Startup Commands

    In Codeblocks you call this sections "Before connection" and "After connection".

    If I use the following gdb commands in the "Before connection" section, then I do not get the message "ERROR: could not write CPU register MSP".
    But the programm stopped not on the address of main, it stops on a other later address.

    Before connection:
    set mem inaccessible-by-default off
    monitor speed auto
    monitor endian little
    monitor flash device=stm32f103rb
    monitor flash breakpoints = 1
    monitor flash download = 1
    load "$(TARGET_OUTPUT_FILE)"
    monitor reg r13 = (0x00000000)
    monitor reg pc = (0x00000004)

    After connection:
    empty

    Segger gdb server log:
    SEGGER J-Link GDB Server V4.12

    JLinkARM.dll V4.12 (DLL compiled Feb 26 2010 19:22:53)

    Listening on TCP/IP port 2331

    J-Link connected
    Firmware: J-Link ARM V8 compiled Dec 1 2009 11:42:48
    Hardware: V8.00
    S/N: 268000132
    OEM: SEGGER-EDU
    Feature(s): FlashBP

    J-Link found 2 JTAG devices, Total IRLen = 9
    JTAG ID: 0x3BA00477 (Cortex-M3)

    Free mode: To be used for non-commercial and evaluation purposes only.

    Connected to 127.0.0.1
    Reading all registers
    Read 4 bytes @ address 0x00000000 (Data = 0x20004FFF)
    Starting target CPU...
    WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1.
    ...Target halted (PC = 0x00000000)
    Reading all registers
    Read 4 bytes @ address 0x00000000 (Data = 0x20004FFF)
    Starting target CPU...
    ...Target halted (PC = 0x080003E2)
    Reading all registers
    Read 4 bytes @ address 0x080003E2 (Data = 0xF103687B)
  • With the following gdb commands in the section "After connection" do not halt the gdb under codeblocks.

    After connection:
    monitor reset
    continue

    Segger gdb server log:
    SEGGER J-Link GDB Server V4.12

    JLinkARM.dll V4.12 (DLL compiled Feb 26 2010 19:22:53)

    Listening on TCP/IP port 2331

    J-Link connected
    Firmware: J-Link ARM V8 compiled Dec 1 2009 11:42:48
    Hardware: V8.00
    S/N: 268000132
    OEM: SEGGER-EDU
    Feature(s): FlashBP

    J-Link found 2 JTAG devices, Total IRLen = 9
    JTAG ID: 0x3BA00477 (Cortex-M3)

    Free mode: To be used for non-commercial and evaluation purposes only.

    Connected to 127.0.0.1
    Reading all registers
    Read 4 bytes @ address 0x00000000 (Data = 0x20004FFF)
    Starting target CPU...
    WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1.
    ...Target halted (PC = 0x00000000)
    Reading all registers
    Read 4 bytes @ address 0x00000000 (Data = 0x20004FFF)
    Starting target CPU...
    ...Target halted (PC = 0x080003E2)
    Reading all registers
    Read 4 bytes @ address 0x080003E2 (Data = 0xF103687B)
    Starting target CPU...
    ...Target halted (PC = 0x080003E2)
    Reading all registers
    Read 4 bytes @ address 0x080003E2 (Data = 0xF103687B)
    Starting target CPU...
    ...Target halted (PC = 0x080003E2)
    Reading all registers
    Read 4 bytes @ address 0x080003E2 (Data = 0xF103687B)
    Debugger terminated connection !
  • My new gdb commands:

    Before connection:
    ----------------------
    set mem inaccessible-by-default off
    monitor speed auto
    monitor endian little
    monitor flash device=stm32f103rb
    monitor flash breakpoints = 1
    monitor flash download = 1
    file "$(TARGET_OUTPUT_FILE)"
    monitor reg r13 = (0x00000000)
    monitor reg pc = (0x00000004)

    After connection:
    ---------------------
    load
    thbreak main

    The debugger halt at the address of main, but I can not execute a single step. The address of the first command is 0x0800152, and the address of next command is 0x08000156. But it is readed the address 0x08000154.

    Segger gdb server log by single step:
    -------------------------------------------
    Performing single step...
    ...Target halted (PC = 0x08000154)
    Reading all registers
    Read 4 bytes @ address 0x08000154 (Data = 0xAF00B580)
    Performing single step...
    ...Target halted (PC = 0x08000156)
    Reading all registers
    Performing single step...
    ...Target halted (PC = 0x08000158)
    Reading all registers
    Performing single step...
    ...Target halted (PC = 0x080002FC)
    Reading all registers
    Read 4 bytes @ address 0x080002FC (Data = 0xAF00B580)
    Read 4 bytes @ address 0x0800015C (Data = 0xBD8046BD)
    WARNING: Failed to read memory @ address 0xFFFFFFF0
    Read 4 bytes @ address 0xFFFFFFF0 (Data = 0xAAAAAAAA)
    Performing single step...
    ...Target halted (PC = 0x080002FE)
    Reading all registers
    Read 4 bytes @ address 0x080002FE (Data = 0xF241AF00)
    Read 4 bytes @ address 0x0800015C (Data = 0xBD8046BD)

    The address 0x080002FC is the start address of the HardFault-Handler.
  • The Debugging works with the GDB on the command line with the following commands.

    target remote localhost:2331
    monitor speed auto
    monitor endian little
    monitor flash device=stm32f103rb
    monitor flash breakpoints = 1
    monitor flash download = 1
    file stm32_md.elf
    monitor reg r13 = (0x00000000)
    monitor reg pc = (0x00000004)
    load
    thbreak main
    monitor reset
    continue

    The problem is not the JLink-EDU. The problem is Codeblocks.
    How can I configure Codeblocks for the debugging with the JLink-EDU?