cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE failed to download Segment[0] when code size reaches 50% of flash

chodge
Associate II

I working with the stm32cubeide version 1.9.0, stlink-v3 debugger and the stm32l4r9 with 1M flash. Everything was going fine until the code size reached 128 sectors ( ~ 50% of the flash). I'm now getting the following error when I attempt to download and debug the application:

STMicroelectronics ST-LINK GDB server. Version 6.1.0

Copyright (c) 2022, STMicroelectronics. All rights reserved.

Starting server with the following options:

       Persistent Mode           : Disabled

       Logging Level             : 1

       Listen Port Number        : 61234

       Status Refresh Delay      : 15s

       Verbose Mode              : Disabled

Waiting for debugger connection...

Debugger connected

Waiting for debugger connection...

Debugger connected

Waiting for debugger connection...

     -------------------------------------------------------------------

                       STM32CubeProgrammer v2.10.0                 

     -------------------------------------------------------------------

Log output file:  /tmp/STM32CubeProgrammer_ZLtEAK.log

ST-LINK SN : 005500333137511533333639

ST-LINK FW : V3J9M3B5S1

Board      : STLINK-V3SET

Voltage    : 3.35V

JTAG freq  : 21333 KHz

Connect mode: Under Reset

Reset mode : Hardware reset

Device ID  : 0x470

Revision ID : Rev W

Device name : STM32L4Rxxx/STM32L4Sxxx

Flash size : 1 MBytes

Device type : MCU

Device CPU : Cortex-M4

BL Version : --

Debug in Low Power mode enabled

Memory Programming ...

Opening and parsing file: ST-LINK_GDB_server_GjIRXM.srec

 File         : ST-LINK_GDB_server_GjIRXM.srec

 Size         : 512.24 KB

 Address      : 0x08000000

Erasing memory corresponding to segment 0:

Erasing internal memory sectors [0 128]

Download in Progress:

Error: failed to download Segment[0]

Error: failed to download the File

Note: If I reduce the code size to 126 sectors or less, then I can download debug as expected.

Any ideas

1 ACCEPTED SOLUTION

Accepted Solutions
chodge
Associate II

It appears I have found a permanent solution for the "failed to download Segment[0] when code size reaches 50% of flash" issue. The solution for me was to uncheck the DB1M ( Changing dual flash bank mode to single flash bank mode) within the STM32Programmer's user configuration settings and update the chip.

View solution in original post

4 REPLIES 4
chodge
Associate II

For the benefit of others, I'm answering my own questions. Keep in mind this is my first time using any ST parts.

I suspected the issue was related to the flash protection bits but was unable to find a way within the STM32CubeIDE to address the issue. After posting this question and further research, I discovered that ST has a standalone Programmer utility. This utility can be used to correct the issue. Download and install the standalone stm32programmer utility. Run the utility, select the "OB" tab, then select Read out protection. Ensure it is set to AA, then go to the Erase and Programming Tab, click full chip erase. After that you should be able to continue as normal.

Not sure how to mark this as SOLVED

>>Not sure how to mark this as SOLVED

Select as "best answer"

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chodge
Associate II

So it appears my solution is only temporary. After downloading and debugging a few times the issue returns. I can repeat the process of using the standalone programmer to erase the flash and once again it will work. I don't understand why this is happening. Anyone want to take a stab at it.

This is an in-house developed board, so I'm fully responsible for the design and can change it. But this is rather simple setup 3 spi interfaces and 2 i2c interface and a CAN bus interface.

The code size is is mostly due to using lvgl library on a spi display with touch screen. I haven't attempted to optimise this library yet so it's a little big, I'm not attempting to use any of the protection mechanisms in the processor. I have physical hardware reset attached to the jtag interface. However I have notice that I often have to download and debug the code a second time in-order to get it to properly run and debug. It would appear the processor is not properly resetting I've tried hardware reset, connect under reset etc. none of this appear to have any effect.

chodge
Associate II

It appears I have found a permanent solution for the "failed to download Segment[0] when code size reaches 50% of flash" issue. The solution for me was to uncheck the DB1M ( Changing dual flash bank mode to single flash bank mode) within the STM32Programmer's user configuration settings and update the chip.