STM32F103C8 and Fast Bootloader

STM32duino bootloader aka Maple bootloader
User avatar
fpiSTM
Posts: 746
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: STM32F103C8 and Fast Bootloader

Post by fpiSTM »

In order to handle the magic sequence to switch in BL mode the USB CDC have to be enabled. Note that this never been tested with the fast bootloader.

About the unknown device, well maybe the USB PU resistor issue which has a wrong value, this should be 1.5K.

And you need this driver:
https://github.com/rogerclarkmelbourne/ ... rivers/win

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Yes, I have a 1.5k pull up on D+. Based on the fact that at one point I did get both the Maple COM port and the DFU device to show up in Device Manager I think that indicates that the hardware is OK.

I was able to access my board over SWD so I flash the generic_boot20_pc13.bin bootloader onto the board and it now appears as Maple Serial Device again.

I'll first test with a simple Blink sketch but which CDC do I choose? CDC no Generic Serial or CDC generic Serial supersede U(S)ART?

User avatar
fpiSTM
Posts: 746
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: STM32F103C8 and Fast Bootloader

Post by fpiSTM »

CDC generic Serial supersede U(S)ART to use "Serial"
CDC no Generic Serial means you have to use "SerialUSB" name instead of Serial which is mapped on an Hardware USART if enabled.

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Thanks for the explanation. It seems the next issue I am facing is the limited flash in the STM32F103C8.

I ran the blink sketch with and without the CDC and I calculated that using CDC takes 10,888 Flash and 2,960 of RAM.

My program without USB compiles to 50,684 and 1,496 which should leave me enough room but the compiler is complaining that I don't have enough room. 50684 + 10888 = 61,572 so it looks like I should have enough room?

What are my options at this point? Of course I could try to trim down my program but I'm sure how much space I really need to free up since right now it looks like I should have enough room.

ag123
Posts: 475
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: STM32F103C8 and Fast Bootloader

Post by ag123 »

try the connventional (non-fast) boot loader as that is somewhat simplier and more likely to work. note that after you installed the boot loader you would see a com port. that com port is actually a blink sketch roger added so that the magic sequence can be triggered.

then build your blink sketch with USB-CDC replace u(S)-ART so that Serial becomes default usb-cdc serial.
if you still encounter issues installing your blink sketch, first check your serial port. that serial port should point to the port that you found after the boot loader is installed.
if that still didn't work, you can try this but only with the conventional (3s delay) usb dfu boot loader.
- first 'verify' the sketch so that it gets built.
- get ready to click the download/install button,
- press reset on your board ( pc13 led start blinking)
- click that download/install button, you have 3 sec when the led start blinking
( i eventually tuned that procedure to typing the command and hit enter after i toggle reset on the board
viewtopic.php?p=3657#p3657 )

if you successfully installed your sketch, and after you did a reset. you would see the comm port again. this time this comm port is from your USB-CDC, you have built into the sketch. you can try getting an CB, RB or RC board, check the specs, those normally has more flash (and possibly more sram as well)

other options are try to play around with the compile optimization flags, and exclude some things it may possibly get smaller binaries
and you can try out this cool stuff on the elf file (that normally is found in the arduino temporary build directory)
http://www.sikorskiy.net/prj/amap/
it is possible to reduce the elf / bin size by excluding symbols that you don't use
this is normally hard to do if you have a rather elaborate app
Last edited by ag123 on Thu Jul 16, 2020 6:32 pm, edited 2 times in total.

User avatar
fpiSTM
Posts: 746
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: STM32F103C8 and Fast Bootloader

Post by fpiSTM »

Hum, I think I know why ld warn you and not Arduino.
In fact the compute of Arduino does not take in account the size of the bootloader but the linker script yes.
I have to see if the Arduino computation take in account the BL size, in platform.txt this is what being extracted:
https://github.com/stm32duino/Arduino_C ... #L145-L147

Code: Select all

## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=^(?:\.text|\.data|\.rodata)\s+([0-9]+).*
And I guess Arduino uses the full size define in the boards.txt
https://github.com/stm32duino/Arduino_C ... s.txt#L873

Code: Select all

GenF1.menu.pnum.BLUEPILL_F103C8.upload.maximum_size=65536
So I think your binary is not valid.
What you can try is to disable the U(S)ART support in the menu if you do not use HardwareSerial.
You can also try to use the BluePill F103CB (or C8 with 128k) targert. Several bluepill with C8 have in fact 128K.

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

I am running the generic_boot20_pc13.bin boot loader if that's what you mean by "conventional". The board now enumerates a STM Serial port now (before it came up as Maple).

In my simple test I found that the flash usage was the same for CDC supersede and CDC no generic.

I can flash the simple Blink sketch but my new issue now is that since I have to enable CDC it is taking too much flash space. As my numbers showed in the last post it looks to me that there is enough room but the compiler says that there isn't.

Yes, I know that there is a CB version which has 128k of flash but of course it also costs more money so I'd like to see why the compiler doesn't think I have enough code space.

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

fpiSTM wrote:
Thu Jul 16, 2020 6:28 pm
So I think your binary is not valid.
What you can try is to disable the U(S)ART support in the menu if you do not use HardwareSerial.
You can also try to use the BluePill F103CB (or C8 with 128k) targert. Several bluepill with C8 have in fact 128K.
Sorry, I'm not sure what you mean by "binary is not valid". I think what you pointed out though is the console isn't showing me the space that the boot loader is taking up and that's why I am out of room.

I'm not using UART on this board but I do have debug messages being sent to the serial port. Would those message still come through if I disabled " U(S)ART Support"?

I have read about some parts being marked with C8 but really they are CB parts. DO I test this by just selecting Generic F103CB as my board or is there something else I need to do?

ag123
Posts: 475
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: STM32F103C8 and Fast Bootloader

Post by ag123 »

the boot loader occipies 0x2000 bytes (8 KB), so your app installs at 0x8002000. so you are left with 56 kB
you can check out the hid boot loader which accordingly is smaller but i've never tried that out.

try that amap thing, if too much is included in the binary, i'd guess a way is to figure out what you can exclude, e.g. setting various defines etc
then exploring the c++ c optiimizations flags helps. then i think there is LTO optimization which is selectable in the STM32 core, but LTO may break some stuff

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

So in order to be able to use the USB on the STM32F103C8 I need to sacrifice 8kB for the bootloader and then another ~10k for the USB code so my available program space drops from 64k to ~46k or I lose 1/3 of my program space?

Post Reply

Return to “USB bootloader”