STM32F103C8 and Fast Bootloader

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

Re: STM32F103C8 and Fast Bootloader

Post by fpiSTM »

If you don't use any USART you can safely disable the USART support. I guess all your debug print are Serial.print... So with USB CDC enabled you will get them from the USB CDC port.
About the C8/CB well you didn't tell which target you select in the menu? BluePill or Generic F103Cx?
it was very closed except for pin number ordering. So which board you have ? A bluepill or a custom F103Cx?

When I told your binary is not valid, I would means that the linker script define the correct maximum size available for your app: 65k - 8K (bl size) so your app could not fit that's all.
If you select the CB then this will fit. You can check with the STLink how many Flash you have.

Finally it is possible to reduce the size by disabling some other feature but first try without the U(S)ART support.
FYI, here how to removed some feature if not needed.
https://github.com/stm32duino/wiki/wiki ... tes-of-ram

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

Re: STM32F103C8 and Fast Bootloader

Post by fpiSTM »

GeorgeIoak wrote:
Thu Jul 16, 2020 6:45 pm
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?
Yes :?
I know the USB support is huge and hope to reduce it by using an other stack (ex Tiny USB?)
But if your board have 128K then this will solve your issue.

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

Re: STM32F103C8 and Fast Bootloader

Post by fpiSTM »

You can also share you sketch and then I can see tomorrow if I can reduce it easily, if this can help.

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

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Thank you again for your time helping me with this, it is appreciated.

When I connect over SWD and using the ST-Link it reports:

Code: Select all

11:57:56 : ST-LINK SN : 081601013212364D434B4E00
11:57:56 : V2J35S7
11:57:56 : Connected via SWD.
11:57:56 : SWD Frequency = 4,0 MHz.
11:57:56 : Connection mode : Connect Under Reset.
11:57:56 : Debug in Low Power mode enabled.
11:57:56 : Device ID:0x410 
11:57:56 : Device flash Size : 64KBytes
11:57:56 : Device family :STM32F10xx Medium-density
So it looks like I wasn't lucky and got a CB device marked as a C8?

I did change the serial port to disabled and changed to a BluePill F103CB board for a test and that allowed me to compile and I ended up with :

Code: Select all

Sketch uses 58472 bytes (44%) of program storage space. Maximum is 131072 bytes.
Global variables use 4188 bytes (20%) of dynamic memory, leaving 16292 bytes for local variables. Maximum is 20480 bytes.
But if I only have 64k of flash 58472 + 8k for the boot loader space means I'm still just above 64k and my program won't fit.

This is a custom board I designed that uses the F103C8 and has both the 8MHz crystal and 32.768kHz crystal attached

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

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Attached is my sketch. I started development on a STM32F405 Feather from Adafruit but my program was compiling well under 64k so I thought it was safe to drop down to a STM32F103C8 and save some money.

The code is a bit ugly and I haven't tried to trim it at all but from the tests we've run today it looks like I have to try and cut it down by at least 2k in order for it to fit.
Attachments
STM32F103C8_ILI9341_TFT_eSPI.zip
(4.26 KiB) Downloaded 46 times

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

Re: STM32F103C8 and Fast Bootloader

Post by fpiSTM »

The main advantage of the F405 is that it have a built in BL which include the USB support not the F1. Moreover the HAL is not the same and I think the F1 one is a little huge. I will check your sketch.
About the CB/C8 in fact BP are sold as a C8 not a CB but often in fact it has more flash, don't ask me why I don't know I lean this on this forum :)

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

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Yes, the F405 would be a good solution but it comes at a price of course! So I'm hoping this can work with the F103C8.

So are you saying that even if the part is marked as a C8 and it reports to be a C8 with 64k flash it still might actually have the full 128k flash?

Is there are harm in setting the board to a 103CB in the IDE and trying to flash or will it cause big problems if it ends up that I only have 64k and I tried to write beyond that space?

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

Re: STM32F103C8 and Fast Bootloader

Post by ag123 »

i'd guess you may like to check out the hid boot loader, specs are impressive 2k flash
https://github.com/stm32duino/wiki/wiki ... -22-hid-bl
but i've never tried that myself
i'd guess it is likely possible to optimize the size further but the effort can be huge.
among the things to try are like LTO (link time optimization i'd guess?) which accordingly can give very small binaries but that it sometimes removes too much (i read something like it removes the weaked irq functions thus apps may crash if those are used etc)

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

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Looking at the HID boot loader it seems that I just need to download the file and I can load it using ST-Link over SWD. Then I just change the upload method from Maple DFU to HID and that's it? Did I miss anything?

It's at least worth a try to see if that works.

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

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Well I decided to give HID a try and it seems to have worked. I used the ST-LINK uploader tool to load the HID boot loader. The I enabled the serial port again, chose Generic F103C8 as my board and used the Arduino IDE to flash the board.

For reference, here's the console output:

Code: Select all

Sketch uses 60712 bytes (92%) of program storage space. Maximum is 65536 bytes.
Global variables use 4456 bytes (21%) of dynamic memory, leaving 16024 bytes for local variables. Maximum is 20480 bytes.

+-----------------------------------------------------------------------+
|         HID-Flash v2.2.1 - STM32 HID Bootloader Flash Tool            |
|     (c)      2018 - Bruno Freitas       http://www.brunofreitas.com   |
|     (c) 2018-2019 - Vassilis Serasidis  https://www.serasidis.gr      |
|   Customized for STM32duino ecosystem   https://www.stm32duino.com    |
+-----------------------------------------------------------------------+

> Trying to open the [COM8]...
> Toggling DTR...
> Searching for [1209:BEBA] device...
##
> [1209:BEBA] device is found !
> Sending <reset pages> command...
> Flashing firmware...
. 1024 Bytes
. 2048 Bytes
. 3072 Bytes
. 4096 Bytes
. 5120 Bytes
. 6144 Bytes
. 7168 Bytes
. 8192 Bytes
. 9216 Bytes
. 10240 Bytes
. 11264 Bytes
. 12288 Bytes
. 13312 Bytes
. 14336 Bytes
. 15360 Bytes
. 16384 Bytes
. 17408 Bytes
. 18432 Bytes
. 19456 Bytes
. 20480 Bytes
. 21504 Bytes
. 22528 Bytes
. 23552 Bytes
. 24576 Bytes
. 25600 Bytes
. 26624 Bytes
. 27648 Bytes
. 28672 Bytes
. 29696 Bytes
. 30720 Bytes
. 31744 Bytes
. 32768 Bytes
. 33792 Bytes
. 34816 Bytes
. 35840 Bytes
. 36864 Bytes
. 37888 Bytes
. 38912 Bytes
. 39936 Bytes
. 40960 Bytes
. 41984 Bytes
. 43008 Bytes
. 44032 Bytes
. 45056 Bytes
. 46080 Bytes
. 47104 Bytes
. 48128 Bytes
. 49152 Bytes
. 50176 Bytes
. 51200 Bytes
. 52224 Bytes
. 53248 Bytes
. 54272 Bytes
. 55296 Bytes
. 56320 Bytes
. 57344 Bytes
. 58368 Bytes
. 59392 Bytes
. 60416 Bytes
. 61440 Bytes

> Done!
> Sending <reboot mcu> command...
> Searching for [COM8] ...
> [COM8] is found !
> Finish
I still get the STM Serial Port and the board resets and comes back. No jumper setting, no manual reset, and I am getting serial output from my print statements in the sketch. I'm pushing the limits of the flash but I still have 8% free without trying to free up any space.

I'm still curious about getting the USB bootloader working but at least I have a solution for now.

Post Reply

Return to “USB bootloader”