STM32 force boot mode via USB? - Page 1
Forum section: electronics / general

author: dobsonr741
author_rank: Frequent Contributor
timestamp: February 10, 2023, 05:41:17 am
content: New to STM32, wonder if STM32 can do what Raspberry Pi Pico can do:The dfu-tool equivalent picotool -f allows picotool to force the device into BOOTSEL mode if a cooperative USB stack is running on the device. Is there such a USB CDC class for the STM?Asking as I don’t like to boot/reset button pushes, I want the successful build go right into the flash without manual action, as I am used to it on the Pico.

author: wek
author_rank: Frequent Contributor
timestamp: February 10, 2023, 08:42:30 am
content: I don't know the RPiPi, but the answer is probably no.STM32 built-in bootloaders in some STM32 (those which have USB, with some exceptions) do contain DFU bootloader (i.e. DFU class, not "USB CDC class"). The bootloader activation depends on STM32 model and option bits settings, but most of them when in pristine state require either a pin or two to be pulled to a certain state, or FLASH to be clear, during reset/power-on.Details per STM32 family can be found in AN2606.The built-in bootloader caters for several options, which means, that some pins have to be "quiet" during bootloader entry, otherwise the incorrect interface is activated.JW

author: Sauli
author_rank: Contributor
timestamp: February 10, 2023, 03:03:30 pm
content: Not sure what you are trying to do, but it is possible to jump from application to ROM bootloader and from ROM bootloader to application. For the first case you need to have some event (command from PC) to trigger the jump and for the second case the software on the PC must send a Leave DFU mode command to the ROM bootloader.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: February 10, 2023, 03:25:47 pm
content: Turns out it’s been discussed here before:https://www.eevblog.com/forum/microcontrollers/is-there-any-agreed-upon-ways-to-enter-bootloader-mode-from-usb/The goal is the “No Button Bootloader”. The board is plugged into USB. Nothing else, no SWD. To support a simple code change/build/run on device workflow with one button click or command, then watch printf output right away.The Arduino core seems to have the 1200 baud hack. I wonder if the CubeF1 stack has it.

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 10, 2023, 05:16:02 pm
content: Actually, you can manually jump into the bootloader from user code.

author: wek
author_rank: Frequent Contributor
timestamp: February 10, 2023, 07:26:17 pm
content: Quote from: dobsonr741 on February 10, 2023, 03:25:47 pmAs others said, you can start the default bootloader from code. But if you've botched the code, then...And as I've said above, the default bootloader has its limitations, too.So, at the end of the day, there are so many caveats, that the answer is no.However, it's definitively doable with a custom-written bootloader.OTOH, why.JW

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 10, 2023, 07:56:34 pm
content: AFAIK, some bootloader versions checked the vector @0x8000000 and start bootloader if invalid (Not containing 0x2000xxxx).

author: dobsonr741
author_rank: Frequent Contributor
timestamp: February 10, 2023, 09:56:18 pm
content: The question is not if it can be done. It's clearly done in stm32duino, both in tools and the CDC class:https://github.com/stm32duino/Arduino_Tools/pull/44/fileshttps://github.com/stm32duino/Arduino_Core_STM32/pull/710I'm looking to find out if the same feature was added/somebody tried add it to the Cube stack. I do not want to use the Arduino stack.

author: paulca
author_rank: Super Contributor
timestamp: February 18, 2023, 01:03:13 pm
content: My question is... why?I see this all over the web. Arduino users want to move to the STM32, so they buy a blue pill or a black pill or whatever and then spend the next 3 months of their lives trying to make it an arduino.The USB is NOT FOR PROGRAMMING the device. It's for your application to use as a USB port. Pause there and re-read that as many times as you need. The Aruino cannot do USB. It's USB port is purely for power and programming via UART IC. The STM32 however can enable a full USB stack in the MCU itself. This allows you make things like programmers, USB Audio devices, USB UARTs ad.inf.Wasting all that time and effort to make the USB port program the device like an arduino is a waste IMHO.Just buy an STLink dongle. Stop wasting your time. It's not an arduino. You will thank me.By the way I was guilty of this. I bought an STM32 Bluepill. Followed several guides on how to boot it from USB or program it with the Ardy FW/IDE. All I got was "No response from device". It went back on the shelf for nearly 2 years. A lot of people told me to just buy a programmer for it. I already had 3 different programmers and about 6 different UART USB adapaters and they were always causing issues, I just didn't want yet another programmer!It was only on a whim I was looking back into MCU stuff and decided to search for "other STM32 boards" and the first item in Amazon was an F411 Blackpill + STLink dongle for £6.99. The next item was two F411s + a dongle for £10, next day. So I bought the pair.Having plugged that STLink dongle into the 3 or 4 STM32 boards I had by that stage and all of them worked with a single click to program from Eclipse (CubeIDE) AND... I could stop and step debug, dissammble, even go poking around in all the hardware registers while it's running. I have never looked back and never ever felt like I need a USB Serial programmer for anything ever again.

author: tooki
author_rank: Super Contributor
timestamp: February 19, 2023, 02:41:12 pm
content: Quote from: paulca on February 18, 2023, 01:03:13 pmNote to self: get around to buying some STM32 Nucleo boards. They have the STLink built in. (In some models, it can even be snapped off and used for other devices.)Anyone got suggestions as to their favorite Nucleo models and why?

author: paulca
author_rank: Super Contributor
timestamp: February 19, 2023, 06:12:33 pm
content: Quote from: tooki on February 19, 2023, 02:41:12 pmAs always it depends. In terms of STM32 MCUs, the F411, which comes in both BlackPill breadboard style 3rd party or as a Nucleo board is a good middle ground to start with.The downside is, it's a Nucleo 64. That's fine if you need a lot of pins and a lot of peripherals, otherwise the "double sided hedgehog" platform is more an inconvenience.The Nucleo32s are great too. I think they do an L456 or something in that format which is a pretty decently powerful micro that will go to sleep and sip uAmps in all manor of different ways.Honestly, The nucleo boards are fine and pretty resonably priced for the maker market. However they don't offer much beyond a few buttons and a few LEDs.The STM32 Discovery boards is where you get cool hardware integrated but the prices are £100+.For that reason I tend to steer towards the smaller, 3rd party modules. They end up with nearly 100 pins, but they take up less space.