This is for the hardware version >= V1.2 that use the stm32 as its mcu, you can easily see the hardware version string on the sensor.
Flash the sensor is not recommended because this is only for the older bdsensor version and also there is no new firmware since February 2024
1.Connect the STlinkV2 to BDsensor, that may require you to solder the wires or a burning fixture(1.25MM or 1.27MM spacing,5Pin)
the SDA and CLK on the BDsensor are not for STlink, so don’t connect SDA/CLK to the SWDIO/SWCLK on the STlink.
2, Flash the firmware into BDsensor with STM32CubeProgrammer
STM32CubeProgrammer
V1.2stm32_20240211.hex
–> start ProgrammingIf the STM32CubeProgrammer does not work for you, you can try this STM32 Batch Programer.exe
The latest firmware V1.2stm32_20240211.hex
is in https://github.com/markniu/Bed_Distance_sensor/tree/new/hex/V1.3_STM32