OpenOCD: flash write algorithm aborted by target

Sysprogs forums Forums VisualGDB OpenOCD: flash write algorithm aborted by target

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #12769
    HSU
    Participant

    Hello,

    I’m using VisualGDB Custom Edition 5.3R3 (build 1864) and OpenOCD 20170821-0.10.0 for a STM32l443RC device (256K flash) with ST-Link v2.1. When I add a new section in the linker script and move this section to a place somewhere inside the flash with a space of more than one flash page, the download failed. In the GDB Session window an error message occurs “Error finishing flash operation”. In the GBDServer Console (openocd) an error occurs “Error: flash write algorithm aborted by target”.

    To reproduce the problem I took the LEDBlink example. I moved the four lines of code from the for loop to a blink() function. The blink() function was moved to the .blink section at address 0x08002000. So there are a space of free flash pages between .text/.data and .blink section.

    .text/.data sections from 0x08000000 to 0x08000970 (end of flash page at 0x08001000)
    –> free space from 0x08001000 to 0x08002000 (two flash pages)
    .blink section from 0x08002000 to 0x08002030 (end of flash page at 0x08002800)

    LEDBlink.c

    int main(void)
    {
      HAL_Init();
      
      __GPIOC_CLK_ENABLE();
      GPIO_InitTypeDef GPIO_InitStructure;
      
      GPIO_InitStructure.Pin = GPIO_PIN_6;
      
      GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
      GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
      GPIO_InitStructure.Pull = GPIO_NOPULL;
      HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
      
      for (;;)
      {
        blink();
      }
    }
    
    void __attribute__( (section( ".blink" ), used) ) blink( void )
    {
      HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_SET);
      HAL_Delay(500);
      HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET);
      HAL_Delay(500);
    }

    STM32L443RC_flash.lds

    ...
    .blink 0x08002000 : AT (0x08002000)
    {
      . = ALIGN(4);
      KEEP(*(.blink))
      . = ALIGN(4);
    } > FLASH

    openocd

    C:\Users\xxx\AppData\Local\VisualGDB\EmbeddedDebugPackages\com.sysprogs.arm.openocd\bin\openocd.exe -c "gdb_port 58715" -c "telnet_port 58716" -f interface/stlink-v2-1.cfg -f target/stm32l4x.cfg -c init -c "reset init" -c "
    echo VisualGDB_OpenOCD_Ready"
    Open On-Chip Debugger 0.10.0 (2017-08-21) [https://github.com/sysprogs/openocd]
    Licensed under GNU GPL v2
    For bug reports, read
            http://openocd.org/doc/doxygen/bugs.html
    Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
    Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    adapter speed: 500 kHz
    adapter_nsrst_delay: 100
    none separate
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    Info : clock speed 480 kHz
    Info : STLINK v2 JTAG v28 API v2 SWIM v17 VID 0x0483 PID 0x374B
    Info : using stlink api v2
    Info : Target voltage: 3.246966
    Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    adapter speed: 480 kHz
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x08000334 msp: 0x2000c000
    adapter speed: 4000 kHz
    VisualGDB_OpenOCD_Ready
    Info : accepting 'gdb' connection on tcp/58715
    Info : Device id = 0x10016435
    Info : STM32L4xx flash size is 256kb, base address is 0x8000000
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    adapter speed: 480 kHz
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x08000334 msp: 0x2000c000
    adapter speed: 4000 kHz
    Info : Device id = 0x10016435
    Info : STM32L4xx flash size is 256kb, base address is 0x8000000
    flash_bank_summary:0x8000000|0x40000|stm32l4x.flash
    FLASH progress reporting is now on
    
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    adapter speed: 480 kHz
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x08000334 msp: 0x2000c000
    adapter speed: 4000 kHz
    Info : Erasing FLASH: 0x08000000-0x08001000...
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    adapter speed: 480 kHz
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
    adapter speed: 4000 kHz
    Info : Erasing FLASH: 0x08002000-0x08002800...
    Info : Programming FLASH (2 sections, 2464 bytes)...
    Info : Programming FLASH section 1/2 (2416 bytes) at 0x08000000...
    Info : Padding image section 0 with 5776 bytes
    target halted due to breakpoint, current mode: Thread 
    xPSR: 0x61000000 pc: 0x20000050 msp: 0xfffffffc
    <span style="color: #ff0000;">Error: flash write algorithm aborted by target</span>
    Info : error executing stm32l4x flash write algorithm
    <span style="color: #ff0000;">Error: flash write failed = 000000a8</span>
    <span style="color: #808000;">Warn : block write failed</span>
    <span style="color: #ff0000;">Error: error writing to flash at address 0x08000000 at offset 0x00000000</span>
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    Info : Unable to match requested speed 500 kHz, using 480 kHz
    adapter speed: 480 kHz
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x08000334 msp: 0x2000c000

    Raw output from GDB

    -gdb-version
    =thread-group-added,id="i1"
    ~"GNU gdb (GDB) 7.12\n"
    ~"Copyright (C) 2016 Free Software Foundation, Inc.\n"
    ~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n"
    ~"This GDB was configured as \"--host=i686-pc-mingw32 --target=arm-eabi\".\nType \"show configuration\" for configuration details."
    ~"\nFor bug reporting instructions, please see:\n"
    ~"<http://www.gnu.org/software/gdb/bugs/>.\n"
    ~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
    ~"For help, type \"help\".\n"
    ~"Type \"apropos word\" to search for commands related to \"word\"...\n"
    ~"Reading symbols from E:\\VisualGDB\\EmbeddedProject2\\EmbeddedProject2/Debug/EmbeddedProject2.elf..."
    ~"done.\n"
    ~"GNU gdb (GDB) 7.12\n"
    ~"Copyright (C) 2016 Free Software Foundation, Inc.\n"
    ~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n"
    ~"This GDB was configured as \"--host=i686-pc-mingw32 --target=arm-eabi\".\nType \"show configuration\" for configuration details."
    ~"\nFor bug reporting instructions, please see:\n"
    ~"<http://www.gnu.org/software/gdb/bugs/>.\n"
    ~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
    ~"For help, type \"help\".\n"
    ~"Type \"apropos word\" to search for commands related to \"word\".\n"
    ^done
    -list-features
    ^done,features=["frozen-varobjs","pending-breakpoints","thread-info","data-read-memory-bytes","breakpoint-notifications","ada-task-info","language-option","info-gdb-mi-command","undefined-command-error-code","exec-run-start-option"]
    -gdb-set disassembly-flavor intel
    <span style="color: #ff0000;">^error,msg="No symbol \"disassembly\" in current context."</span>
    -gdb-set print demangle off
    ^done
    -break-insert -f main
    ^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x08000296",func="main",file="LEDBlink.c",fullname="E:\\VisualGDB\\EmbeddedProject2\\EmbeddedProject2\\LEDBlink.c",line="17",thread-groups=["i1"],times="0",original-location="main"}
    set remotetimeout 60
    &"set remotetimeout 60\n"
    =cmd-param-changed,param="remotetimeout",value="60"
    ^done
    target remote :58715
    &"target remote :58715\n"
    ~"Remote debugging using :58715\n"
    =thread-group-started,id="i1",pid="42000"
    =thread-created,id="1",group-id="i1"
    ~"Reset_Handler () at C:\\Users\\xxx\\AppData\\Local\\VisualGDB\\EmbeddedBSPs\\arm-eabi\\com.sysprogs.arm.stm32/STM32L4xxxx/StartupFiles/startup_stm32l443xx.c:820\n"
    ~"820\t\tfor (pSource = &_sidata, pDest = &_sdata; pDest != &_edata; pSource++, pDest++)\n"
    *stopped,frame={addr="0x08000334",func="Reset_Handler",args=[],file="C:\\Users\\xxx\\AppData\\Local\\VisualGDB\\EmbeddedBSPs\\arm-eabi\\com.sysprogs.arm.stm32/STM32L4xxxx/StartupFiles/startup_stm32l443xx.c",fullname="C:\\Users\\xxx\\AppData\\Local\\VisualGDB\\EmbeddedBSPs\\arm-eabi\\com.sysprogs.arm.stm32\\STM32L4xxxx\\StartupFiles\\startup_stm32l443xx.c",line="820"},thread-id="1",stopped-threads="all"
    ^done
    info shared
    &"info shared\n"
    ~"No shared libraries loaded at this time.\n"
    ^done
    mon halt
    &"mon halt\n"
    ^done
    mon reset init
    &"mon reset init\n"
    @"Unable to match requested speed 500 kHz, using 480 kHz\n"
    @"Unable to match requested speed 500 kHz, using 480 kHz\n"
    @"adapter speed: 480 kHz\n"
    @"target halted due to debug-request, current mode: Thread \n"
    @"xPSR: 0x01000000 pc: 0x08000334 msp: 0x2000c000\n"
    @"adapter speed: 4000 kHz\n"
    ^done
    mon report_flash_progress 1
    &"mon report_flash_progress 1\n"
    @"Device id = 0x10016435\n"
    @"STM32L4xx flash size is 256kb, base address is 0x8000000\n"
    @"flash_bank_summary:0x8000000|0x40000|stm32l4x.flash\n"
    @"FLASH progress reporting is now on\n"
    @"\n"
    ^done
    load
    &"load\n"
    ~"Loading section .isr_vector, size 0x18c lma 0x8000000\n"
    <span style="color: #ff0000;">+download,{section=".isr_vector",section-size="396",total-size="44994"}</span>
    ~"Loading section .text, size 0x7d8 lma 0x800018c\n"
    <span style="color: #ff0000;">+download,{section=".text",section-size="2008",total-size="44994"}</span>
    ~"Loading section .init_array, size 0x4 lma 0x8000964\n"
    <span style="color: #ff0000;">+download,{section=".init_array",section-size="4",total-size="44994"}</span>
    ~"Loading section .fini_array, size 0x4 lma 0x8000968\n"
    <span style="color: #ff0000;">+download,{section=".fini_array",section-size="4",total-size="44994"}</span>
    ~"Loading section .data, size 0x4 lma 0x800096c\n"
    <span style="color: #ff0000;">+download,{section=".data",section-size="4",total-size="44994"}</span>
    ~"Loading section .blink, size 0x30 lma 0x8002000\n"
    <span style="color: #ff0000;">+download,{section=".blink",section-size="48",total-size="44994"}</span>
    &"Error finishing flash operation\n"
    <span style="color: #ff0000;">^error,msg="Error finishing flash operation"</span>
    -data-evaluate-expression "sizeof(void *)"
    ^done,value="4"
    -data-evaluate-expression "sizeof(int)"
    ^done,value="4"
    -data-evaluate-expression "sizeof(short)"
    ^done,value="2"
    -data-evaluate-expression "sizeof(long)"
    ^done,value="4"
    -data-evaluate-expression "sizeof(long long)"
    ^done,value="8"
    -data-evaluate-expression "sizeof(char)"
    ^done,value="1"
    -data-evaluate-expression "sizeof(wchar_t)"
    <span style="color: #ff0000;">^error,msg="No symbol \"wchar_t\" in current context."</span>
    -data-evaluate-expression "sizeof(float)"
    ^done,value="4"
    -data-evaluate-expression "sizeof(double)"
    ^done,value="8"
    -data-evaluate-expression "sizeof(long double)"
    ^done,value="8"
    info target
    &"info target\n"
    ~"Symbols from \"E:\\VisualGDB\\EmbeddedProject2\\EmbeddedProject2\\Debug\\EmbeddedProject2.elf\".\n"
    ~"Remote serial target in gdb-specific protocol:\n"
    ~"Debugging a target over a serial line.\n"
    ~"\tWhile running this, GDB does not access memory from...\n"
    ~"Local exec file:\n"
    ~"\t`E:\\VisualGDB\\EmbeddedProject2\\EmbeddedProject2\\Debug\\EmbeddedProject2.elf', file type elf32-littlearm.\n"
    ~"\tEntry point: 0x8000334\n"
    ~"\t0x08000000 - 0x0800018c is .isr_vector\n"
    ~"\t0x0800018c - 0x08000964 is .text\n"
    ~"\t0x08000964 - 0x08000968 is .init_array\n"
    ~"\t0x08000968 - 0x0800096c is .fini_array\n"
    ~"\t0x20000000 - 0x20000004 is .data\n"
    ~"\t0x20000004 - 0x20000024 is .bss\n"
    ~"\t0x08002000 - 0x08002030 is .blink\n"
    ^done
    -data-evaluate-expression "&_estack"
    ^done,value="0x2000c000"
    -var-create - * "*((void **)0x2000bffc)"
    ^done,name="var1",numchild="0",value="0x1000000",type="void *",has_more="0"
    -var-assign "var1" 0x4a327626
    ^done,value="0x4a327626"
    -data-evaluate-expression "\*\(\(void\ \*\*\)0x2000bffc\)"
    ^done,value="0x4a327626"
    -exec-continue
    ^running
    *running,thread-id="all"
    ~"Note: automatically using hardware breakpoints for read-only addresses.\n"
    =breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x08000296",func="main",file="LEDBlink.c",fullname="E:\\VisualGDB\\EmbeddedProject2\\EmbeddedProject2\\LEDBlink.c",line="17",thread-groups=["i1"],times="1",original-location="main"}
    ~"\n"
    ~"Breakpoint 1, main () at LEDBlink.c:17\n"
    ~"17\t\tHAL_Init();\n"
    *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame={addr="0x08000296",func="main",args=[],file="LEDBlink.c",fullname="E:\\VisualGDB\\EmbeddedProject2\\EmbeddedProject2\\LEDBlink.c",line="17"},thread-id="1",stopped-threads="all"
    -break-delete 1
    ^done
    -exec-continue
    ^running
    *running,thread-id="all"

    How can I fix this bug?

    #12770
    HSU
    Participant

    by the way… when I perform a full chip erase (e.g. with STM32 ST-Link Utility) and then load the “moved blink example” via VisualGDB the download succeeds. When I restart the download it fails again. So there might be a difference between a full erased flash and a partly erased flash for the OpenOCD flash driver…

    #12772
    support
    Keymaster

    Hi,

    Thanks for reporting this. It looks like an OpenOCD bug, so we usually rely on the OpenOCD community to fix those.

    As a workaround please try adding command to erase FLASH in to the additional gdb commands in VisualGDB Project Properties.

    E.g.:

    mon flash erase_sector …

    You can find more about OpenOCD FLASH-related commands here: http://openocd.org/doc/html/Flash-Commands.html

    #12775
    HSU
    Participant

    Hello,

    I added “mon stm32l4x mass_erase 0” direct before the “load” command and it works.

    set remotetimeout 60
    target remote :$$SYS:GDB_PORT$$
    mon reset init
    mon halt
    mon stm32l4x mass_erase 0
    load

    Are you report the bug to the OpenOCD community?

    #12781
    support
    Keymaster

    Hi,

    Sorry, as we don’t have an STM32l443RC  board here, we would be able to reproduce it/confirm the fix, hence we won’t be reporting this to OpenOCD.

    Please consider reporting this via OpenOCD mailing lists as described here: http://openocd.org/doc-release/doxygen/bugs.html

    Please also try our latest update to the OpenOCD package. It may already include the fix.

    #12808
    HSU
    Participant

    Sorry, as we don’t have an STM32l443RC  board here, we would be able to reproduce it/confirm the fix, hence we won’t be reporting this to OpenOCD.

    I am sure you can reproduct it with every STM32L4…

    Please also try our latest update to the OpenOCD package. It may already include the fix.

    I am using the OpenOCD 20170821-0.10.0 package. I think it is your lastest…

    #12844
    support
    Keymaster

    Hi,

    No problem, we have submitted a ticket to the OpenOCD bugtracker: https://sourceforge.net/p/openocd/tickets/165/

    #12846
    HSU
    Participant

    thanks for reporting the bug to OpenOCD.

    I think the behaviour with partly erased flash and full erased flash is important. The download always succeeds with previous full flash erase.

    Just for info: the bug still exists in your latest OpenOCD 20171024-0.10.0 package.

    #12848
    support
    Keymaster

    Hi,

    We understand your frustration and agree that this is important, so we will try to give more context on this.

    There are 2 popular low-level debug tools for modern ARM devices: OpenOCD and Segger J-Link.

    • OpenOCD is free and works with many inexpensive debug probes like ST-Link, however it has some glitches and is not as user-friendly.
    • Segger J-Link software requires a more expensive J-Link probe, but its low-level gdb stub is fully supported by the probe manufacturer, explicitly tested with many devices and is generally much more reliable.

    With VisualGDB we don’t aim to replace any of those 2 low-level methods. Instead we build on top of them, focusing on usability features like easy project configuration, profiler, real-time watch, live variables, etc. We also provide easy setup GUI for OpenOCD that automatically detects and configures common setups, but this approach still inherits various glitches for advanced scenarios like the one you are encountering. We could address it by making a “bulletproof” fork of OpenOCD, however making it as reliable as J-Link would raise the product costs accordingly. Instead of doing that, we maintain out-of-the-box support for both debug methods and let our users choose between more reliable J-Link and free OpenOCD.

    Hopefully this explains.

    Thanks.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.