bootloader seems to get overwritten

STM32duino bootloader aka Maple bootloader
tcurdt
Posts: 4
Joined: Sat Feb 25, 2023 11:02 pm

bootloader seems to get overwritten

Post by tcurdt »

I have flashed the bootloader to a bluepill.

Code: Select all

$ st-info --probe
Found 1 stlink programmers
  version:    V2J17S4
  serial:     54FF67064882565217411887
  flash:      65536 (pagesize: 1024)
  sram:       20480
  chipid:     0x0410
  descr:      F1xx Medium-density
$ st-flash write generic_boot20_pc13.bin 0x8000000
...
2023-02-25T17:29:37 INFO common.c: Flash written and verified! jolly good!
Now when I connect to the usb serial I see the following message in a loop:

Code: Select all

Congratulations, you have installed the STM32duino bootloader
See https://github.com/rogerclarkmelbourne/STM32duino-bootloader


For more information about Arduino on STM32
See https://www.stm32duino.com
That looks like the bootloader and the welcome sketch works correctly.


Now I upload a simple sketch that blinks and write "Hello" on the serial via pio.

Code: Select all

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = dfu
Which works (once I updated the dfu-util).

Code: Select all

$ pio run -t upload
...
Download done.
DFU state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
Resetting USB to switch back to runtime mode
But when I restart the bluepill - the sketch is running but the usb serial is gone.
I suspect the upload overwrote the bootloader?

I then assumed the sketch should be located at 0x8002000 and tried the following to no avail:

Code: Select all

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = dfu
board_upload.offset_address = 0x2000
Still the usb serial disappears after the first upload.

Any pointers on what I might be missing?
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: bootloader seems to get overwritten

Post by GonzoG »

Bootloader has nothing to do with USB Serial.
If you want to have USB Serial you need to enabled it for your program.

And if you flashed your program using ST-Link or USB-TTL converter (Serial bootloader), you've overwritten USB bootloader.
tcurdt
Posts: 4
Joined: Sat Feb 25, 2023 11:02 pm

Re: bootloader seems to get overwritten

Post by tcurdt »

I have flashed the `generic_boot20_pc13.bin` with an st-link - which wrote a bootloader and a sketch (printing to the serial).

Now this provided a USB serial on the host that:

- provides the serial from the sketch over USB
- a way to flash a new sketches via USB

The 2nd flash wasn't via st-link, nor was it via USB-to-TTL (like a FT232RL), instead I flashed via USB.

And to my understanding the ability to flash via USB is enabled by the USB bootloader.

That is not the case?
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: bootloader seems to get overwritten

Post by Bakisha »

I don't know how to deal with PIO, but with Arduino IDE, once you flashed "generic_boot20_pc13.bin" via serial or st-link, you'll get COM port (and it will be named "COM10 Maple Mini"). Port number may be different in your case.
At this point use you must use USB to upload sketch ( if st-link or serial is used to upload sketch, bootloader will be overwritten with your sketch).
If you are using roger/steve core, select "stm32duino bootloader" as upload method (port is also "COM10 Maple Mini" ).
If you are using ST core, you must set "Mapple DFU Bootload 2.0" and, at this point, "COM10 Maple Mini" port. But, once sketch is uploaded, that port will disappear and you'll need to change to different port (COM11 in my case, you number will be different).
If there is no "COM11", that means "USB support -> CDC" is not selected from menu ( but you can still upload sketch by manually press reset button on bluepill) or there is problem with driver (go to device manager and see is there problems with drivers and their port number).
tcurdt
Posts: 4
Joined: Sat Feb 25, 2023 11:02 pm

Re: bootloader seems to get overwritten

Post by tcurdt »

Thanks for that input.
Bakisha wrote: Mon Feb 27, 2023 4:12 pm I don't know how to deal with PIO, but with Arduino IDE, once you flashed "generic_boot20_pc13.bin" via serial or st-link, you'll get COM port (and it will be named "COM10 Maple Mini"). Port number may be different in your case.
At this point use you must use USB to upload sketch ( if st-link or serial is used to upload sketch, bootloader will be overwritten with your sketch).
That's clear. But when I upload via USB, the bootloader get overwritten as well - it seems.
At least the USB serial disappears on the host.
This might be more related to PIO though.

But it's why I posted here to understand what the expected behaviour is.

The upload mode I used with pio is "DFU"
And I am wondering what upload styles the "stm32duino bootloader" and "Mapple DFU Bootload 2.0" use under the hood.
I would suspect they also use DFU - but writing at the different/proper location?

Once I know that detail it probably best to continue this question over in the PIO community.
Bakisha wrote: Mon Feb 27, 2023 4:12 pm But, once sketch is uploaded, that port will disappear and you'll need to change to different port (COM11 in my case, you number will be different).
If there is no "COM11", that means "USB support -> CDC" is not selected from menu ( but you can still upload sketch by manually press reset button on bluepill) or there is problem with driver (go to device manager and see is there problems with drivers and their port number).
That parts reads a bit confusing. Why does the port change? Does it change on every update?
Or are you saying there is one port for the flashing and another for the serial monitor?
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: bootloader seems to get overwritten

Post by Bakisha »

tcurdt wrote: Mon Feb 27, 2023 5:14 pm
That parts reads a bit confusing. Why does the port change? Does it change on every update?
Or are you saying there is one port for the flashing and another for the serial monitor?
No, it will do only once, when you upload your first sketch on just flashed bootloader. Every upload after that is done "COM11".
It's core thing. ST core use generic USB CDC (and it have drivers installed when you installed STM Cube Programmer), Roger/Steve core use Maple Mini driver. Bootloader is just sketch compiled on Roger/Steve core, so it report itself to host as "Maple Mini".
"stm32duino bootloader" and "Mapple DFU Bootload 2.0" is same thing, called differently.
From a quick search, my guess you'll need

Code: Select all

build_flags =
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
so it build with usb serial port visible...
As i said before, USB COM port is just convenient for uploading, without it, reset is need for board to enter in bootloader mode. Or you could use jumper on BOOT1 to enter bootloader mode (led with flash fast), but don't forget to switch back jumper once sketch is uploaded...
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: bootloader seems to get overwritten

Post by GonzoG »

tcurdt wrote: Mon Feb 27, 2023 1:27 pm I have flashed the `generic_boot20_pc13.bin` with an st-link - which wrote a bootloader and a sketch (printing to the serial).

Now this provided a USB serial on the host that:

- provides the serial from the sketch over USB
- a way to flash a new sketches via USB
....
No. USB bootloader does not enable Serial USB in your sketches. It's just a bootloader - a program that loads on boot and allows you to flash your program. If you haven't enabled USB Serial in your sketch, there won't be USB Serial.


Using USB bootloader you cannot overwrite bootloader.
There is no DFU mode (hardware USB bootloader) on F103. You have only SWD (ST-Link) or serial bootloader.
tcurdt
Posts: 4
Joined: Sat Feb 25, 2023 11:02 pm

Re: bootloader seems to get overwritten

Post by tcurdt »

GonzoG wrote: Tue Feb 28, 2023 11:38 pm
No. USB bootloader does not enable Serial USB in your sketches. It's just a bootloader - a program that loads on boot and allows you to flash your program. If you haven't enabled USB Serial in your sketch, there won't be USB Serial.

Using USB bootloader you cannot overwrite bootloader.
There is no DFU mode (hardware USB bootloader) on F103. You have only SWD (ST-Link) or serial bootloader.
I am starting to wonder if something got lost in translation here.

I wrote the `generic_boot20_pc13.bin` via st-link and then uploaded a new build via USB (via DFU). 🤷‍♂️
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = dfu
And when you write "and allows you to flash your program" , well, it allows that via USB.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: bootloader seems to get overwritten

Post by ag123 »

you need to ensure that you have selected USB (CDC) Serial in your sketch as your default Serial device.
then your Serial would be USB Serial.
and you can test that with things like

Code: Select all

void loop() {
  Serial.println("hello world");
  delay(1000);
}
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: bootloader seems to get overwritten

Post by GonzoG »

tcurdt wrote: Wed Mar 01, 2023 12:50 am I am starting to wonder if something got lost in translation here.

I wrote the `generic_boot20_pc13.bin` via st-link and then uploaded a new build via USB (via DFU). 🤷‍♂️
You uploaded program using USB bootloader, not DFU.
You used dfu-util. That's just a name of application.
tcurdt wrote: Wed Mar 01, 2023 12:50 am And when you write "and allows you to flash your program" , well, it allows that via USB.
Yes, it does. But it does not use USB Serial for this.
Post Reply

Return to “USB bootloader”