| 1 |
### STM32 via ST-Link |
| 2 |
|
| 3 |
Nucleo and Discovery boards typically include a built-in ST-Link programmer. |
| 4 |
|
| 5 |
A `.bin` or `.hex` file can be flashed using [st-flash](https://github.com/stlink-org/stlink). |
| 6 |
|
| 7 |
```bash |
| 8 |
# Optional erase to clear existing filesystem. |
| 9 |
st-flash erase |
| 10 |
|
| 11 |
# Flash .bin |
| 12 |
st-flash write firmware.bin 0x08000000 |
| 13 |
# or, flash .hex |
| 14 |
st-flash --format ihex write firmware.hex |
| 15 |
``` |
| 16 |
|
| 17 |
A `.hex` file can be flashed using [STM32 Cube Programmer](https://www.st.com/en/development-tools/stm32cubeprog.html). |
| 18 |
|
| 19 |
```bash |
| 20 |
STM32_Programmer.sh -c port=SWD mode=UR dLPM -d firmware.hex -v -hardRst |
| 21 |
``` |
| 22 |
|
| 23 |
### STM32 via DFU |
| 24 |
|
| 25 |
Boards with USB support can also be programmed via the ST DFU bootloader, using e.g. [dfu-util](http://dfu-util.sourceforge.net/) or [pydfu.py](https://github.com/micropython/micropython/blob/master/tools/pydfu.py). |
| 26 |
|
| 27 |
To enter the bootloader the `BOOT0` pin can be connected to `VCC` during reset, or you can use `machine.bootloader()` from the MicroPython REPL. |
| 28 |
|
| 29 |
```bash |
| 30 |
dfu-util --alt 0 -D firmware.dfu |
| 31 |
``` |