I'm facing trouble with STM32CubeProgrammer for upgrading FUS and programming the Wireless stack and my application into STM32WB55CG. I could upgrade FUS (V1.2.0), and do stack (V1.20.0) and application programming. But my application won't start even if I checked "Run After programming"! I fully follow these instructions:
https://wiki.st.com/stm32mcu/wiki/Connectivity:STM32WB_FUS
https://stm32-quest.com/Mission2_reviewed.pdf
After that, I decided to use STM32_Programmer_CLI to make this process automated and fix the problem by applying some commands to execute the code after programming, so I wrote this Batch(.bat) script for Windows CMD:
@echo off
cls
SETLOCAL EnableDelayedExpansion
:: Configuration - Update these paths to match your environment
set STM32_PROGRAMMER="C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe"
set PROG_ARGS=-c port=SWD freq=4000
set DEVICE=STM32WB55CG
:: Firmware paths - Update these to your specific firmware versions
set FUS_BIN=".\STM32WB5x_FUS_fw.bin"
set WIRELESS_STACK_BIN=".\stm32wb5x_BLE_Stack_full_fw.bin"
set APPLICATION_BIN=".\Merged.hex"
:: FUS and Wireless Stack versions to verify (update to your target versions)
set TARGET_FUS_VERSION=1.2.0
set TARGET_WIRELESS_STACK_VERSION=1.20.0
echo.
echo ==============================================
echo STM32WB55CG Firmware Upgrade Process
echo ==============================================
echo.
:: Step 0: Ensure FUS is running (delete wireless stack if needed)
echo.
echo.
echo [0/5] ------------------------ Checking FUS state -----------------------
echo Try to sart FUS
%STM32_PROGRAMMER% %PROG_ARGS% -startfus
if errorlevel 1 (
echo Start FUS failed!
pause
exit /b 1
)
%STM32_PROGRAMMER% %PROG_ARGS% -fusgetstate | find "FUS_STATE_RUNNING" >nul
if errorlevel 1 (
echo FUS is not running. Attempting to revert...
echo Deleting wireless stack to activate FUS...
%STM32_PROGRAMMER% %PROG_ARGS% -fwdelete
if errorlevel 1 (
echo Warning: Wireless stack delete failed - trying to continue anyway
)
)
:: Step 1: Upgrade FUS (Firmware Upgrade Service)
echo.
echo.
echo [1/5] --------------------- Upgrading FUS firmware ----------------------
%STM32_PROGRAMMER% %PROG_ARGS% mode=UR -ob nSwboot0=0 nboot1=1 nboot0=1 -fwupgrade %FUS_BIN% 0x080EC000 firstinstall=1
if errorlevel 1 (
echo FUS upgrade failed!
echo Possible solutions:
echo 1. Power cycle the board and try again
echo 2. Check if another debugger is connected
echo 3. Verify your FUS bin file is correct
pause
exit /b 1
)
:: Step 2: Verify FUS version
echo.
echo.
echo [2/5] ----------------------- Verifying FUS version -----------------------
%STM32_PROGRAMMER% %PROG_ARGS% -fusgetstate
if errorlevel 1 (
echo FUS version verification failed!
pause
exit /b 1
)
:: Step 3: Upgrade Wireless Stack
echo.
echo.
echo [3/5] ----------------------- Upgrading Wireless Stack -----------------------
%STM32_PROGRAMMER% %PROG_ARGS% mode=UR -ob nSWboot0=0 nboot1=1 nboot0=1 -fwupgrade %WIRELESS_STACK_BIN% 0x080CE000 firstinstall=0
if errorlevel 1 (
echo Wireless Stack upgrade failed!
pause
exit /b 1
)
:: Step 5: Program & Verify Application
echo.
echo.
echo [4/5] ----------------------- Programming Application -----------------------
%STM32_PROGRAMMER% %PROG_ARGS% -hardRst
:: 1. Disable PCROP & WRP
%STM32_PROGRAMMER% %PROG_ARGS% -ob PCROP1A_STRT=0 PCROP1A_END=0 PCROP1B_STRT=0 PCROP1B_END=0
%STM32_PROGRAMMER% %PROG_ARGS% -ob WRP1A_STRT=0 WRP1A_END=0 WRP1B_STRT=0 WRP1B_END=0
:: 2. Mass erase (optional but recommended)
%STM32_PROGRAMMER% %PROG_ARGS% -mass_erase
%STM32_PROGRAMMER% %PROG_ARGS% mode=UR -ob nSWboot0=0 nboot1=1 nboot0=1 -d %APPLICATION_BIN% 0x08000000 -v -s
if errorlevel 1 (
echo Application programming failed!
pause
exit /b 1
)
:: Step 4: start Wireless Stack version
echo.
echo.
echo [5/5] ------------------------ start Wireless Stack ------------------------
%STM32_PROGRAMMER% %PROG_ARGS% -startwirelessstack
if errorlevel 1 (
echo Wireless Stack start failed!
pause
exit /b 1
)
:: 3. Verify application is running
timeout /t 2 >nul
%STM32_PROGRAMMER% %PROG_ARGS% -r32 0x08000000 4
if errorlevel 1 (
echo ERROR: Application not running!
echo Performing emergency recovery...
%STM32_PROGRAMMER% %PROG_ARGS% -ob nSWBOOT0=0x1
timeout /t 1 >nul
%STM32_PROGRAMMER% %PROG_ARGS% -ob nSWBOOT0=0x0
%STM32_PROGRAMMER% %PROG_ARGS% -rst
)
%STM32_PROGRAMMER% %PROG_ARGS% -ob displ
echo.
echo ==============================================
echo Firmware upgrade completed successfully!
echo ==============================================
echo.
pause
But this code still won't work, and my main application didn't start. What did I lose here?