cancel
Showing results for 
Search instead for 
Did you mean: 

Swap bank using jlink on stm32H573 not working

Hi everyone, 

History:
I am running from bank 0 and I start an upgrade after the upgrade I do a bank swap and the application starts running from bank 1.

Problems:
Now I use a debugger to flash the .elf file in the micro-controller. But the code does not boot up. I open stm32 programmer uncheck the swap bank and re-flash the code and then the code runs.

What I want:

I want to uncheck the swap bank flag so that I am always in bank 0 when I flash my binary on the µC. I need to do it because I want to connect it in a CI/CD pipeline and I dont want the system to break.
I want a script that ideally works jlink.exe to reset only the swap bank bit and not touch any other bit in the register

My .jlink script:

device STM32H573AI
si SWD
speed 4000
connect

// Step 1: Check FLASH_SECSR for BSY, DBNE, WBNE bits (manual step, not supported in .jlink script)

// Step 2: Clear error flags in FLASH_SECCR
w4 0x4002202C, 0xFFFFFFFF
// Step 3: Unlock FLASH and OPTION BYTES
w4 0x40022008, 0x45670123
w4 0x40022008, 0xCDEF89AB
w4 0x4002200C, 0x08192A3B
w4 0x4002200C, 0x4C5D6E7F


// Step 4: Clear SWAP_BANK bit in FLASH_OPTSR_PRG
w4 0x40022054, 0x00000000
Sleep 10 
// Step 5: Set OPTSTRT bit in FLASH_OPTCR
w4 0x40022014, 0x00000001
Sleep 10
// Step 6: Reset the MCU
r
g
exit

 I will be really thankful if someone can point out what I do wrong and even better provide me with a working script to swap banks using jlink.exe and a .jlink file

0 REPLIES 0