Compliation failed for STM32G0B1RCT6 MCU with STM32cube framework

I am trying to write custom code(not for Marlin 3D Printer) for BTT SKR Mini E3 V3.0 with framework stm32cube.
To get started, I wrote LED Blink, which giving lot of compile error

Hardware

  1. MCU : STM32G0B1RCT6
  2. LED pin : PD8
  3. Schematics at link

Code

I used the STM32Cube IDE to generate the code,

Placed the complete at

Error log

C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c: In function 'HAL_RCCEx_GetPeriphCLKFreq':
<command-line>:0:11: error: expected identifier or '(' before numeric constant
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:614:12: note: in expansion of macro 'frequency'
   uint32_t frequency = 0U;
            ^~~~~~~~~
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:633:17: error: lvalue required as left operand of assignment
       frequency = LSE_VALUE;
                 ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:638:17: error: lvalue required as left operand of assignment
       frequency = LSI_VALUE;
                 ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:643:17: error: lvalue required as left operand of assignment
       frequency = HSE_VALUE / 32U;
                 ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:708:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:712:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:716:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:720:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:735:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:739:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:743:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:747:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:764:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:768:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:772:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:776:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:793:21: error: lvalue required as left operand of assignment
           frequency = (HSI_VALUE / 488U);
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:797:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:814:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:818:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:822:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:826:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:843:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:847:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:851:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:855:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:871:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:875:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:883:23: error: lvalue required as left operand of assignment
             frequency = (pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) >> RCC_PLLCFGR_PLLP_Pos) + 1U);
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:899:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:903:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:907:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:923:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:927:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:931:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:951:23: error: lvalue required as left operand of assignment
             frequency = (pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) >> RCC_PLLCFGR_PLLP_Pos) + 1U);
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:956:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:960:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:965:21: error: lvalue required as left operand of assignment
           frequency = EXTERNAL_I2S1_CLOCK_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:985:23: error: lvalue required as left operand of assignment
             frequency = (pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLP) >> RCC_PLLCFGR_PLLP_Pos) + 1U);
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:990:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetSysClockFreq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:994:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:999:21: error: lvalue required as left operand of assignment
           frequency = EXTERNAL_I2S2_CLOCK_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1016:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1020:21: error: lvalue required as left operand of assignment
           frequency = LSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1024:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1028:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1045:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1049:21: error: lvalue required as left operand of assignment
           frequency = LSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1053:21: error: lvalue required as left operand of assignment
           frequency = HSI_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1057:21: error: lvalue required as left operand of assignment
           frequency = LSE_VALUE;
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1078:23: error: lvalue required as left operand of assignment
             frequency = (pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos) + 1U);
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1083:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1103:23: error: lvalue required as left operand of assignment
             frequency = (pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos) + 1U);
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1108:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1128:23: error: lvalue required as left operand of assignment
             frequency = (pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos) + 1U);
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1136:23: error: lvalue required as left operand of assignment
             frequency = HSI48_VALUE;
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1144:23: error: lvalue required as left operand of assignment
             frequency = HSE_VALUE;
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1165:23: error: lvalue required as left operand of assignment
             frequency = (pllvco * plln) / ((READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos) + 1U);
                       ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1170:21: error: lvalue required as left operand of assignment
           frequency = HAL_RCC_GetPCLK1Freq();
                     ^
C:\Users\Asus\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c:1174:21: error: lvalue required as left operand of assignment
           frequency = HSE_VALUE;
                     ^
*** [.pio\build\nucleo_g0b1re\FrameworkHALDriver\Src\stm32g0xx_hal_rcc_ex.o] Error 1
=============================================================================== [FAILED] Took 5.10 seconds ===============================================================================

When you run the project task → advanced → verbose build, you see the compile invocation as

arm-none-eabi-gcc -o .pio\build\nucleo_g0b1re\FrameworkHALDriver\Src\stm32g0xx_hal_rcc_ex.o -c -mthumb -mcpu=cortex-m0plus -Os -ffunction-sections -fdata-sections -Wall -nostdlib -DPLATFORMIO=60118 -DSTM32G0 -DSTM32G0xx -DSTM32G0B1xx -DG0 -DUSE_HAL_DRIVER -DF_CPU=64000000L; -Dchange -DMCU -Dfrequency -Isrc -Iinclude -IC:\Users\Max\.platformio\packages\framework-stm32cubeg0\Drivers\CMSIS\Include -IC:\Users\Max\.platformio\packages\framework-stm32cubeg0\Drivers\CMSIS\Device\ST\STM32G0xx\Include -IC:\Users\Max\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Inc -IC:\Users\Max\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src -IC:\Users\Max\.platformio\packages\framework-stm32cubeg0\Drivers\CMSIS\DSP\Include C:\Users\Max\.platformio\packages\framework-stm32cubeg0\Drivers\STM32G0xx_HAL_Driver\Src\stm32g0xx_hal_rcc_ex.c

There you can clearly see the problem

-DF_CPU=64000000L; -Dchange -DMCU -Dfrequency 

is being passed as compile flags. Specifically, -Dfrequency defines the word frequency to “nothing”, whitespace, destroying code that tries to declare a variable called frequency. as so happens in the STM32G0 RCC HAL code.

This macro comes from the inline .ini comment

So after removing both inline comments, we can compile normally

Linking .pio\build\nucleo_g0b1re\firmware.elf
Checking size .pio\build\nucleo_g0b1re\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 44 bytes from 147456 bytes)
Flash: [          ]   0.7% (used 3488 bytes from 524288 bytes)
Building .pio\build\nucleo_g0b1re\firmware.bin
====== [SUCCESS] Took 8.22 seconds ======

This is a bit tricky because you likely copied from the documentation, but that put it in separate lines, so there is no problem there.

https://docs.platformio.org/en/latest/boards/ststm32/nucleo_g0b1re.html#configuration

Maybe the evaluation of the .ini for the board_build.f_cpu should be re-evaluate here to avoid this problem? CC @ivankravets.

As per your comment I have update .ini file, complied & uploaded successfully, but code is not working(LED is not blinking)

But same code I have complied upload via STM32Cube IDE, LED blink is working perfectly.
This Code I have upload in the same repo in other branch link

Since I am using the STM32G0B1RCT6 MCU, how to configure properly in the PlatformIO env?

The chip being RC instead of RE should not make much of a difference, because the Flash is just bigger.

Then you should be able to debug the code inside the debugger. Just open the debugging sidebar and press the play button. Does it reach the main() function? If not, press the pause button. Where is it stuck?

Yes, to make the thing proper.
How to set this flash size to 256KB in PlatformIO? Currently default setting is 512kB

Test Case

  1. [Working] Full Erase MCU Memory → STM32Cube IDE(flashing the code) → PlatformIO (re-flashing the code) → LED is blink fine
    Attached the log below(1).
  2. [Not Working] Full Erase MCU Memory → PlatformIO (flashing the code) → LED is not blink → debug result attached below(2)

(2) Debug result from PlatformIO

It is not reaching the main() loop function.

(1) STM32Cube IDE Flashing log output

Log output file:   C:\Users\Asus\AppData\Local\Temp\STM32CubeProgrammer_a14788.log
ST-LINK SN  : 0669FF3238504B3043214728
ST-LINK FW  : V2J46M31
Board       : STM32F4DISCOVERY
Voltage     : 2.95V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x467
Revision ID : Rev A
Device name : STM32G0B0xx/B1xx/C1xx
Flash size  : 512 KBytes
Device type : MCU
Device CPU  : Cortex-M0+
BL Version  : 0x92

Opening and parsing file: ST-LINK_GDB_server_a14788.srec


Memory Programming ...
  File          : ST-LINK_GDB_server_a14788.srec
  Size          : 5.40 KB 
  Address       : 0x08000000 



Erasing memory corresponding to sector 0:
Erasing internal memory sectors [0 2]
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:00.246



Verifying ...




Download verified successfully 


Shutting down...
Exit.

(1) PlatformIO Flashing log output

RAM:   [          ]   0.0% (used 44 bytes from 147456 bytes)
Flash: [          ]   0.7% (used 3496 bytes from 524288 bytes)
.pio\build\nucleo_g0b1re\firmware.elf  :

section             size        addr

.isr_vector          188   134217728

.text               3420   134217916

.rodata               64   134221336

.ARM.extab             0   134221400

.ARM                   0   134221400

.preinit_array         0   134221400

.init_array            4   134221400

.fini_array            4   134221404

.data                 12   536870912

.bss                  32   536870924

._user_heap_stack   1540   536870956

.ARM.attributes       40           0

.comment             126           0

.debug_frame         108           0

Total               5538
<lambda>(["upload"], [".pio\build\nucleo_g0b1re\firmware.elf"])
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, mbed, serial, stlink
CURRENT: upload_protocol = stlink
openocd -d2 -s C:\Users\Asus\.platformio\packages\tool-openocd/openocd/scripts -f interface/stlink.cfg -c "transport select hla_swd" -f target/stm32g0x.cfg -c "program {.pio\build\nucleo_g0b1re\firmware.elf}  verify reset; shutdown;"
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 2000 kHz
Info : STLINK V2J46M31 (API v2) VID:PID 0483:374B
Info : Target voltage: 2.938746
Info : [stm32g0x.cpu] Cortex-M0+ r0p1 processor detected
Info : [stm32g0x.cpu] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32g0x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
[stm32g0x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x1fff5ba4 msp: 0x20003948
** Programming Started **
Info : device idcode = 0x10006467 (STM32G0B/G0Cx - Rev A : 0x1000)
Info : RDP level 0 (0xAA)
Info : flash size = 512 KiB
Info : flash mode : dual-bank
Info : Padding image section 1 at 0x08000e6c with 4 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x08000e70 .. 0x08000fff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
shutdown command invoked
============================================================================== [SUCCESS] Took 2.64 seconds ==============================================================================
 *  Terminal will be reused by tasks, press any key to close it. 

So where is it when you press the pause button?

Paused at the Line 59 Reset_Handler

Actually whole debug option are hanged, nothing is working. No response while clicking the pause or restart button.
I have physically disconnected the debugger board to restart the debugging process.

When you flash the .pio/build/<env>/firmware.bin using STM32CubeProgrammer instead of OpenOCD, does it work?

It is working, when flashing with STM32cube Programmer.

I am totally surprised :scream_cat:, Why this is happening?

File location:

Flashing via STM32Cube Programmer

Logs
21:44:07 : Opening and parsing file: firmware.bin
21:44:07 : Memory Programming ...
21:44:07 :   File          : firmware.bin
21:44:07 :   Size          : 3.57 KB 
21:44:07 :   Address       : 0x08000000 
21:44:07 : Erasing memory corresponding to sector 0:
21:44:07 : Erasing internal memory sectors [0 1]
21:44:07 : Download in Progress:
21:44:07 : File download complete
21:44:07 : Time elapsed during download operation: 00:00:00.194
21:44:07 : Verifying ...
21:44:07 : Read progress:
21:44:07 : Download verified successfully 
21:44:55 : Disconnected from device.

In STM32CubeProgrammer, when looking into the Option Bytes (“OB”), is there a bit set for “Dual-Page Flash” or “Single Bank Flash”?

If OpenOCD assumes single-bank but the device is set to dual-bank, or vice-versa, there will be problems.

May be the same as

Dual Flash, but OpenOCD follow the same, please check the logs below.
Still why it is happening?

OpenOCD

Did you try with single bank flash just to check it?

Yes, I tried now with single bank flash. LED Blink is working…

How to solve this problem?

If OpenOCD could upload the firmware fine with the device now set to single bank, and it couldn’t properly upload that same firmware when it was set to dualbank, it’s a problem with OpenOCD.

There is a possibility that PlatformIO’s OpenOCD version is behind, or OpenOCD still has the bug.

You can test with the device set back to “dual bank” and the latest OpenOCD binary version as packaged by

https://github.com/xpack-dev-tools/openocd-xpack/releases

with the command invocation is shown in project tasks → Advanced → Verbose upload. If the latest binary works, then PlatformIO needs a package update.

Or, file an issue at https://github.com/platformio/platform-ststm32/issues and let them investigate.

Created the issue at Flashing via PlatformIO (OpenOCD) is not working for STM32G0B1RCT6 · Issue #848 · platformio/platform-ststm32 · GitHub