Error in building the program, Error in build step #6 (Make): Make process exited with code 2 in STM32G474RE

Hello Everyone,

I hope this message finds you well.

I am currently working with a custom board based on the STM32G474RE microcontroller and attempting to program it using PLECS Coder. Unfortunately, I’m encountering an issue during the build and flashing process. Even a simple LED blinking test fails.

To clarify:

  • The custom board functions correctly when tested with STM32CubeIDE.
  • The PLECS simulation is also working properly, as the same test (blinking an LED) runs fine on a standard STM32G474RE board.
  • The issue arises when I try to connect and program my custom board via PLECS

I get this error :
Error in build step #6 (Make): Make process exited with code 2:
“C:/Users/Sajjad/Desktop/Coder_Targert/tsp_stm32/bin/c2p-gdb/c2p-gdb” load --server-cmd “"C:/Users/Sajjad/Desktop/Coder_Targert/tsp_stm32/bin/openocd/bin/openocd" -s "C:/Users/Sajjad/Desktop/Coder_Targert/tsp_stm32/bin/openocd/share/openocd/scripts" -f board/stm32g431.cfg” --server-start-delay 1000 --port 3333 --nvic 0x8000000 ./output_STM32G474RE/G474RE.elf
Architecture: arm
Unable to load binary “./output_STM32G474RE/G474RE.elf”. Unable to erase flash.
Healthy exit.
G474RE.mk:237: recipe for target ‘download’ failed

Open On-Chip Debugger 0.11.0 (2021-12-23-14:02)
Licensed under GNU GPL v2
For bug reports, read

Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V3J16M7B5S1 (API v3) VID:PID 0483:374F
Info : Target voltage: 3.292615
Info : stm32g4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32g4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting ‘gdb’ connection on tcp/3333
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x01000003 pc: 0xfffffffe msp: 0xffffffd8
Info : device idcode = 0x20036469 (STM32G47/G48xx - Rev ‘unknown’ : 0x2003)
Info : flash size = 512kbytes
Info : flash mode : dual-bank
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
Error: timed out while waiting for target halted
TARGET: stm32g4x.cpu - Not halted
in procedure ‘ocd_gdb_restart’
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
Error: timed out while waiting for target halted
Error executing event gdb-flash-erase-start on target stm32g4x.cpu:
TARGET: stm32g4x.cpu - Not halted
Error: Target not halted
Error: failed erasing sectors 0 to 9
Error: flash_erase returned -304
Info : dropped ‘gdb’ connection
make: *** [download] Error 1

Could you please help me identify what might be causing this issue? Is there a specific configuration required in PLECS or OpenOCD for custom STM32G4 boards?

Thank you in advance for your support.

Best regards,
Sajjad

Hello Sajjad,

Can you please run the following command and report back the output?

"C:/Users/Sajjad/Desktop/Coder_Targert/tsp_stm32/bin/openocd/bin/openocd" -s "C:/Users/Sajjad/Desktop/Coder_Targert/tsp_stm32/bin/openocd/share/openocd/scripts" -f board/stm32g431.cfg -c "init" -c "reset halt" -c "flash probe 0" -c "flash info 0" -c "shutdown"

Thanks,
Beat Arnet

Dear Bear,
thank you for you response
i have uploaded the result of command running and also i have uploaded the SC of Plecs configuration.

best regards
sajjad





Are you sure that you executed to entire command that I provided, including the -c arguments? I would have expected to see information about the flash and its protection settings.

i uploaded the new one
from # 15: 0x00007800 (0x800 2kB) not protected
to
#225: 0x00070800 (0x800 2kB) not protected
are the same, for this reason i did not take Screen shot between them.


Yesterday, the first time I ran the following command:
“C:/Users/Sajjad/Desktop/Coder_Targert/tsp_stm32/bin/openocd/bin/openocd” -s “C:/Users/Sajjad/Desktop/Coder_Targert/tsp_stm32/bin/openocd/share/openocd/scripts” -f board/stm32g431.cfg -c “init” -c “reset halt” -c “flash probe 0” -c “flash info 0” -c “shutdown” as you suggested.
I got the output shown in the first screenshot of the CMD window. i am sure that i did not anything, but after running the command again, I received the output in the second screenshot — and the board was successfully programmed. I was even able to use external mode via JTAG.

However, today I’m working with the board again and facing the same issue as before. No matter what I try, nothing seems to solve the problem.

the problem was solder jumper of NRST on my board
its soldering was weak.

Nice debugging! I am glad you figured it out.