[SOLVED] Uploading the bootloader with a Black Magic Probe

jbaumann
Sun Jul 15, 2018 8:17 pm
Hi,

is it possible to upload the bootloader using a Black Magic Probe? I tried this today and wasn’t able to do this.

I would be more than happy to add to the wiki information if some kind soul points me in the right direction, but currently I’m stumped.

I have Blue Pill boards, an STLink that has been changed to a Black Magic Probe, I can use GDB to upload elf files, but not the bin file that the bootloader (or e.g., the blink&count bootloader combination) comes in.

My main interest is in getting simple access to a serial communication over USB, but I think this is a problem of general interest.

Cheers, Joe


Rick Kimball
Mon Jul 16, 2018 1:55 am
why not recompile the bootloader and save the .elf file instead of turning it into a .bin?

Rick Kimball
Mon Jul 16, 2018 2:01 am
[jbaumann – Sun Jul 15, 2018 8:17 pm] –
My main interest is in getting simple access to a serial communication over USB, but I think this is a problem of general interest.

you don’t need the bootloader to have native usb in your sketches. you need to add -DSERIAL_USB to your bmp boards.txt file entry
genericSTM32F103C.menu.upload_method.BMPMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG -DSERIAL_USB


jbaumann
Tue Jul 17, 2018 11:32 am
Sometimes the simplest things are the best.

First I tried the -DSERIAL_USB and it works like a charm, nearly perfect. It seems, though, that the whole program starts only when I connect to the USB device. Before that the Blue Pill blinks hectically. This is not a big problem, but I would like to understand what it does…

Then I compiled the current version of the bootloader, uploaded the elf file using my BMP, and could see in the USB device list of my OSX computer that indeed the Bootloader seems to be present. My question here: Is there a drive for OSX that I can use for the bootloader?

Finally, one different question: On my OSX system the USB sub system quite often stops working i.e., no longer recognizes the devices I plug in. When that happens I normally reboot. But is there a simple way to reset/restart the USB subsystem (something like “systemctl restart USB”)?

Thanks a lot for helping me out :-)

Cheers, Joe


jbaumann
Tue Jul 17, 2018 12:38 pm
After resetting the USB subsystem (by rebooting) I was able to download from the Arduino IDE to the BluePill board using the Bootloader. Very nice.

For my purposes, though, using the USBSERIAL flag is the way to go. I’ve added a second BMP entry in the boards.txt so that I can simply switch between using USB Serial and not using it by selecting a different upload method.

One final question: How much memory is needed when I use this flag?

Cheers, Joe


Rick Kimball
Tue Jul 17, 2018 2:50 pm
[jbaumann – Tue Jul 17, 2018 12:38 pm] –
One final question: How much memory is needed when I use this flag?

Now that you have two entries in boards.txt, you should be able to tell us :)

Personally, I dislike the libmaple USB Serial implementation. It scans the input looking for trigger bytes to reset itself. It feels dirty. It sucks up CPU time constantly responding to USB heartbeats from the host. In addition, when you reset your board, you lose the /dev/ttyACMx it provides. I tend to use putty to connect to my boards. When you reload, the board resets and the host needs to enumerate the USB port again. Which means I have to restart putty. Yes I know the Arduino serial console takes care of this problem, but I feel stymied by it.

One of the huge advantages of using BMP when installed on a bluepill, is that /dev/ttyACM1 ( the second BMP device) provides a Virtual COM port on the USART2 pins (PA2/PA3). Because the BMP isn’t resetting itself the /dev/ttyACM1 port is consistent between uploads. You can connect the BMP PA2/PA3 to your PA9/PA10 pins on your target blue pill and use the BMP as though it was a USB TTY device. In fact, you can use the /dev/ttyACM1 without using BMP at all and you have a nice and free USB TTL dongle.

If I really want to do USB stuff with a bluepill, I tend to use the one that is part of libopencm3. (Of course, this means you aren’t using stm32duino)

BMP Note: (Just noticed that USART2 isn’t 5V tolerant, I should probably move it to USART3 so you can use it with 5V devices)


jbaumann
Tue Jul 17, 2018 4:04 pm
What you describe about the libmaple implementation doesn’t sound good. So, if I could use another USB library instead I would be happy.

But my setup currently employs Eclipse for editing, compilation and upload (based on the Arduino IDE configuration with the Sloeber plugin) and this uses/needs STM32duino. And to be honest I like STM32duino very much so far.

Libopencm3 looks to me to be still in beta stage, not in any way production-ready. Am I wrong there? And if it is so, could I use its USB library in my environment i.e., together with STM32duino?

Regarding the virtual tty: Since I have a STLink clone that I flashed with the BMP firmware, I do not have access to its PA2/PA3 pins. But OSX seems to be not as “proactive” with re-enumeration of the devices, so this is not as annoying as is the failure to recognize devices at all after a while…

Thanks again, Joe


Rick Kimball
Tue Jul 17, 2018 5:44 pm
My thoughts on the libmaple USB are certainly the minority opinion here. Everyone else loves the way the Maple Serial works and its USB bootloader. I really dislike the maple bootloader. It is why I created the black magic probe support. The good thing for you, you can use either.

libopencm3 has been around as long if not longer than the original libmaple stuff. libopencm3 is the core of the BMP device. If you feel comfortable with BMP you should be comfortable with libopencm3. Its first and primary platform was the stm32f1 chips. Mixing libopencm3 usb and libmaple would be a major effort. I wouldn’t suggest it, the libmaple USB is the way to go for most people.


Rick Kimball
Tue Jul 17, 2018 5:48 pm
[jbaumann – Tue Jul 17, 2018 4:04 pm] –
But my setup currently employs Eclipse for editing, compilation and upload (based on the Arduino IDE configuration with the Sloeber plugin) and this uses/needs STM32duino. And to be honest I like STM32duino very much so far.

BTW: Sloeber adds its own problems to all this stuff. If you have issues in the future, make sure you try a standard Arduino IDE before asking for help. In the past, we have helped people with issues only to find out they were using Sloeber and it was doing the wrong thing.


jbaumann
Tue Jul 17, 2018 7:12 pm
Sloeber: Don’t I know it… But Eclipse compared to the Arduino IDE is so much more comfortable (and I’Ve been using Eclipse for nearly 15 years). If there is a way to combine Eclipse and the Arduino IDE without Sloeber then I would be more than happy to try it. And yes, if I have any problems with Sloeber, I change back to the Arduino IDE (which is running all the time for exactly this purpose) and check against it…

I see two topics emerging from this discussion that are only remotely associated with the original topic:
– A development environment that support stm32duino, and maybe libopencm3. Aah, I see there is a thread describing a minimal installation without Sloeber. I’ll test that.
– The best way to utilize the USB connectivity of most STM32 boards (ease of use vs. low overhead, functionality etc.)

So, where could I start a discussion of the second part?

Cheers, Joe


Rick Kimball
Tue Jul 17, 2018 8:18 pm
[jbaumann – Tue Jul 17, 2018 7:12 pm] –
So, where could I start a discussion of the second part?

How about Ideas and Suggestions ? viewforum.php?f=17


Leave a Reply

Your email address will not be published. Required fields are marked *