@echo off
setlocal

set ELF_FILE=%1
set BASE_NAME=%~n1

echo 提取内部Flash段...
arm-none-eabi-objcopy -O binary --only-section=.isr_vector --only-section=.startup "%ELF_FILE%" "%BASE_NAME%_internal.bin"

echo 提取QSPI Flash段...
arm-none-eabi-objcopy -O binary --remove-section=.isr_vector --remove-section=.startup "%ELF_FILE%" "%BASE_NAME%_external.bin"

echo 烧录内部Flash...
pyocd flash --target=STM32H750XBHx --erase=auto -a 0x08000000 "%BASE_NAME%_internal.bin"

echo 烧录外部QSPI...
pyocd flash --target=STM32H750XBHx --erase=auto -a 0x90000000 "%BASE_NAME%_external.bin"

endlocal