4
\$\begingroup\$

Until now I was always using Arduino Nano Boards, which had the proper bootloader installed so that programming via the ArduinoIDE was easy and fast. Just plug it in via USB, wait for Windows to install the driver, open ArduinoIDE and there you go.

Now I have a project which demands more powerful and versatile peripheral devices via SPI and CAN. Therefore I chose a STM32 as an ARM microprocessor.

Now what's confusing me:

  1. Somehow you don't Plug'n'Play with those, at least on self made custom PCBs. There are many applications I found that used a SWD connection via a "ST-Link" (is this the programmer/"bridge" establishing the connection between PC and actual microprocessor?).

Can I program the STM32 easily by pluging it to a ST-Link and program it via any ARM-compatible IDE like mBed for example? (Like I would with an Arduino and ArduinoIDE?)

  1. Most of the microcontroller do have a USB interface onboard, where you can directly connect USB_DM and USB_DP with a USB port. Can I also program a STM32 via the USB interface by connecting it directly to a PC?

Would it be recognised by a PC and IDE like a Arduino would or are there other steps I would have to do in order to have a ""Plug'n'Play"-like programming with the STM32 via USB?

Some explanations on how to programm those ARM microprocessors (like the STM32) would be really helpful to me, because I get too confused with all the programming methods.

\$\endgroup\$
3
  • \$\begingroup\$ Perhaps this information is of use. \$\endgroup\$
    – Syed
    Nov 8, 2021 at 11:51
  • \$\begingroup\$ Thank you. I've also found that one in my research. But this is specially made for the ArduinoIDE. What if I want to program it via USB and a IDE for ARM-microcontrollers, like mBed or MXCube. Do I have to do the same procedure? \$\endgroup\$
    – Dakalaom
    Nov 8, 2021 at 11:54
  • \$\begingroup\$ AN4879 appnote "USB hardware and PCB guidelines using STM32 MCUs \$\endgroup\$
    – Syed
    Nov 8, 2021 at 12:00

1 Answer 1

4
\$\begingroup\$

via a "ST-Link" (is this the programmer/"bridge" establishing the connection between PC and actual microprocessor?)

Exactly; it's a debugging adapter. The debugging interface ("SWD", single wire debug, on the STM32) allows for writing the flash memory.

Can I program the STM32 easily by pluging it to a ST-Link and program it via any ARM-compatible IDE like mBed for example?

The tooling needs to know how to program your specific chip. But usually that just means your IDE uses a software tool (often, OpenOCD) to do the flashing; just as your IDE is not your compiler, but uses a compiler (e.g. clang, gcc) to convert source code to machine code.

Most IDEs will bring, or know how to bring in, such a flashing software.

Most of the microcontroller do have a USB interface onboard, where you can directly connect USB_DM and USB_DP with a USB port. Can I also program a STM32 via the USB interface by connecting it directly to a PC?

That very much depends on the individual STM32 model. Some come with a USB bootloader that allows for that. You'll have to read the product page of the STM32 in question!

Would it be recognised by a PC and IDE like a Arduino would or are there other steps I would have to do in order to have a ""Plug'n'Play"-like programming with the STM32 via USB?

Can't tell you - depends on the existence and type of said bootloader, and your IDE.

Notice that you might be a bit surprised by the useful things that you can actually do if you have a debugger attached - Arduino is quite bad in its debugging experience. So, for development, chances are that using an STLinkv2 (or clone thereof) will be your preferred way, anyways! (These things are cheap. Worst case, you buy a cheap STM32 Nucleo eval board and use the one that's integrated there – you can take of three jumpers and connect your own board via cables.)

The USB bootloader (and I²C or SPI or UART bootloaders some devices have) are really more meant for production or field updates, where you'd want to plug thousand boards in and load finished firmware, not for development. (again, the original Arduino is less comfortable than what most engineers are used working with: you can do things like halt your program where it is, modify code or data memory or the state of some peripheral, and continue running and so on. Debugging.)

Some explanations on how to programm those ARM microprocessors (like the STM32) would be really helpful to me, because I get too confused with all the programming methods.

Download ST's IDE then and read/watch a tutorial by ST then.

\$\endgroup\$
3
  • \$\begingroup\$ In the datasheet, it says: "Boot modes: At startup, Boot0 pin and Boot1 option bit are used to select one of three boot options: • Boot from user Flash • Boot from system memory • Boot from embedded SRAM The boot loader is located in the system memory. It is used to reprogram the Flash memory by using USART1 (PA9/PA10), USART2 (PD5/PD6) or USB (PA11/PA12) through DFU (device firmware upgrade)." In order to program the STM32 via USB I need to put it in DFU mode and then can programm it via USB, correct? \$\endgroup\$
    – Dakalaom
    Nov 8, 2021 at 12:13
  • \$\begingroup\$ correct, with the right DFU loading sofware, but again, and I want to stress that: you really want to have a debugging adapter (ST-Link), it makes life easier while developing software. The arduino typical write-compile-flash-fails-write LED blink or UART printf debugging code-compile-flash-… cycle of Arduino is terrible and will not work out for you in the long run if you're dealing with things that actually are more complex than the Arduino framework allows you to do. The USB-DFU mechanism is not for development, it's for manufacturing and field updates. \$\endgroup\$ Nov 8, 2021 at 12:18
  • \$\begingroup\$ You (probably, and hopefully!) are starting with a simple eval board (ST Nucleo?), and that even includes an ST-Link! \$\endgroup\$ Nov 8, 2021 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.