Flash and run a .hex file on a different Microcontroller with bigger flash from the same Cortex family
Datasheet says the MCUs are fully compatible, only memory size is different. The compiler should only use different linker script to change the RAM and Flash memory sizes. The compiled binaries should be identical, and you can also verify this.