cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474RB - can't debug program over 64 kB

gjepali
Associate II

Hi,

I have a toubles with a debuging my program.

I started from the begining... so I create a empty project in VSCode for this MCU (setup is CLANG only). I build the empty program. It has 702 B. Debuging is working at this point.

But after create a "data" in flash with this code:

 
#include <stdint.h>
#include <sys/cdefs.h>

#define TARGET_FLASH_SIZE_B (64*1024)
extern const uint8_t size_filler[TARGET_FLASH_SIZE_B];

void __attribute__((noinline)) force_data_use(void)
{
    volatile const uint8_t *ptr = size_filler;
    
    uint8_t dummy = ptr[0]; 
}

const uint8_t size_filler[TARGET_FLASH_SIZE_B] = {
    [0] = 0xAA,
    [TARGET_FLASH_SIZE_B - 1] = 0x55
};

int main(void)
{
    /* Loop forever */
    force_data_use();
	for(;;);
}​
Debug can't be lauched...
 
But if you replace line 4 with:
#define TARGET_FLASH_SIZE_B (63*1024)

it works...

 

So I think there is some problem with flash size erasing / flashing. The MCU has 2 kB per page and two banks.

 

Here is DEBUG CONSOLE:

 

STMicroelectronics ST-LINK GDB server. Version 7.11.0
Copyright (c) 2025, 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
        SWD Debug                  : Enabled
        InitWhile                  : Enabled

Waiting for debugger connection...
GNU gdb (GNU Tools for STM32 13.3.rel1.20250523-0900) 14.2.90.20240526-git
Copyright (C) 2023 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-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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".
add-symbol-file "C:/<my_path>/empty/build/Debug/empty.elf" 
add symbol table from file "C:/<my_path>/empty/build/Debug/empty.elf"
(y or n) [answered Y; input not from terminal]
Reading symbols from C:/<my_path>/empty/build/Debug/empty.elf...
Debugger connected
Waiting for debugger connection...
0x1fff5048 in ?? ()
connected to remote target localhost:61234
Note: automatically using hardware breakpoints for read-only addresses.
load "C:/<my_path>/empty/build/Debug/empty.elf" 
Loading section .isr_vector, size 0x1d8 lma 0x8000000
Loading section .text, size 0xec lma 0x80001d8
Loading section .rodata, size 0x10000 lma 0x80002c4
Loading section .ARM, size 0x18 lma 0x80102c4
Loading section .preinit_array, size 0x4 lma 0x80102e0
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.20.0                  
      -------------------------------------------------------------------
3

Log output file:   C:\Users\<username>\AppData\Local\Temp\STM32CubeProgrammer_a13408.log
ST-LINK SN  : 50FF70067867515350350467
ST-LINK FW  : V2J46S7
Board       : --
Voltage     : 3.44V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x469
Revision ID : Rev X
Device name : STM32G47x/G48x/G414
Flash size  : 128 KBytes
Device type : MCU
Device CPU  : Cortex-M4
BL Version  : 0xD5
Debug in Low Power mode enabled
3

Opening and parsing file: ST-LINK_GDB_server_a13408.srec
2

Memory Programming ...
  File          : ST-LINK_GDB_server_a13408.srec
  Size          : 64.72 KB 
  Address       : 0x08000000
2

Erasing memory corresponding to segment 0:
Error: Operation exceeds memory limits
2

Error: failed to erase memory
Encountered Error when opening C:/Users/<username>/AppData/Local/stm32cube/bundles/programmer/2.20.0/bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer
Error finishing flash operation
cube is killed by signal SIGTERM

 

Mass erase is working with ST-Link Utility and with STM32CubeProgrammer. So Option Bytes are OK.

I think there is a bug with flashing procedure...

 

8 REPLIES 8
TDK
Super User

What is the part number of the chip you are using?

In title, missed it.

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Super User

The chip has two 64 kB sections of contiguous flash and your project exceeds those limits. STM32CubeProgrammer will not flash portions of the memory that are not guaranteed to work correctly. You will be limited to a program size of 64 kB, or you can split the program up into two sections of up to 64 kB each, but this requires some work with the linker file.

If you feel a post has answered your question, please click "Accept as Solution".

Hello,

128K with two flash banks of 64K but NOT contiguous, that is the issue here.

But as you said, you can use the other 64K but you need to specify the linker with correct sections.

Rgds,

Laurent

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
gjepali
Associate II

TDK and LaurentL - thank you for realy quick response.

You are both right about double bank limitation (2x 64 KB, not 128 KB as I expect). But my linker script was defined for 128 kB FLASH size - compiler and linker made program bigger than 64 kB with no error and I was able to load the program by programmer.

Solution for me - STM32CubeProgrammer -> Option Bytes -> User Configuration -> DBANK: uncheck

Now I can load and debug program bigger than 64 kB for this MCU (STM32G474RBxx).

It's interesting that linker script generated by STM32CubeMX has this configuration:

MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 128K
}

but linker script generated by STM32Cube for VSCode has this configuration (empty project):

MEMORY
{
  CCMSRAM    (xrw)    : ORIGIN = 0x10000000,   LENGTH = 32K
  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 128K
  FLASH    (rx)    : ORIGIN = 0x8000000,   LENGTH = 128K
}

Both has space of 128 kB for program. But in default... you can't load bigger program than 64 kB... I can't see any configuration options in STM32CubeMX for Double / Single Bank... CCM SRAM is also ignored in CubeMX... Am I missing something?

Thank you for your help!

The linker script is not valid. It should have a flash length of 64K.

Optionally, it should have a second 64K region at 0x8100000. The two sections are not contiguous and there is no way to have them be treated as such by the linker.

If you feel a post has answered your question, please click "Accept as Solution".

Hello,

The linker script with 128K contiguous flash is valid for Single bank mode.

Yes, STM32CubeMx is missing the CCMSRAM.

For Dual bank mode, the upper 64K are after 0x08040000 (256K), and not 0x8100000.

Check Ref Man RM0440 for G4 series, table 7 Flash module for dual bank (table 8 for single bank mode).

But then, even if you have the right linker script, you must define sections to use this second flash Memory region.

And use this section in your code.

Rgds,

Laurent

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
gjepali
Associate II

In reference manual is this:

gjepali_0-1763624687713.png

https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf (site 96)

So if DBANK = 0, I could use all 128 kB flash. Addresses are consecutive without spaces (0x0800 0000 - 0x0807 FFFF for max capacity).

gjepali
Associate II

It is very confusing that the MCU has DBANK = 1 by default, i.e. it runs in dual bank mode, while STM32CubeMX and STM32Cube for VSCode generate linker script basically for single bank. That's how I understood it and it seems pointless to me. The compiler then compiles the program even if it is larger than one half of the flash memory. The user does not have the option to generate linker script for dual bank using ST tools.