I am designing a PCB with stm32f4 controller in it. I was designed arduino boards in my past. I am researching for STM32 flashing a code or bootload in datasheets. If I am not wrong with a only 4 pin (SWCLK, SWDIO, GND, 3V3) no extra component on PCB we can FLASH and Bootload our stm32 with a ST-LINK v2. I am trying the simple and small as possible because of the PCB placed on the small place. I see some writings say this MCUs are internally bootloaded. I was flash bootload on arduino MCUs with a help of external MCU. I guess don't need it on STMs. Can you guide me. Thank you.
-
\$\begingroup\$ It depends what you need. Do you want to always use the SWD cable so you never need any bootloader? Do you always want to use the system bootloader so you don't need custom bootloader? Do you always want to use a custom bootloader? \$\endgroup\$– JustmeCommented Dec 26, 2023 at 10:01
-
\$\begingroup\$ Thanks. I will always use ST-LINK to programming a MCU. For example I use CH340G to programming my ATMega2560 on the PCB via USB port. Without Bootloader I cannot upload a code on MCU in this scenario. But in the STM I meet with ST-LNK stuff if I use ST-LINK (SWDIO, SWO, SWCLK) there is no need for BOOTLOAD isn't it. \$\endgroup\$– MSBCommented Dec 26, 2023 at 10:18
2 Answers
If you always use ST-Link for code upload, you don't need a bootoader of any kind.
However, you don't say which exact MCU you have, but if your MCU supports USB through the system bootloader, you might find it easier than to always use the ST-Link.
Although the ST-Link allows you to debug code so put whatever interfaces you want.
You can enter System bootloader mode as follows:
- typical method is to BOOT0 switch. simply reliable, but you need additional hardware components likes switches, or jumper pins.
- Jump from the user software to the bootloader. It doesn't require additional hardware design, but it's a little tricky. for example, the firmware is corrupted, there may be no way to enter bootloader mode.
...anyway, once you have entered bootloader mode, you can download the firmware by choosing between UART, CAN, I2C, SPI or DFU via USB.