Arduino bootloader development

Post Reply
geocheats2
Posts: 6
Joined: Sat Aug 28, 2021 8:52 pm

Arduino bootloader development

Post by geocheats2 »

Hello to everyone

I bought this board https://github.com/FYSETC/FYSETC-SPIDER v2.2 in order to use it in a custom application and not as a 3D printer controller

In my application i would like to have it connected to a PC over usb and get the data of the usb cdc serial but i can't seem to be able to find a bootloader that works as a cdc usb serial and flashing without having to bridge BOOT0 to vcc and reboot the board in order to expose the STM32 Bootloader.

I also bought some Ethernet to SPI adapters and i would like to be able to update the firmware over the air.

From what i gathered i need to develop a custom bootloader with a block defined as an OTA "partition".

Could you please point me to any documentation that you may have in mind in order to port stm32duino or any other alike bootloader to my board?

George
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Arduino bootloader development

Post by ag123 »

based on the schematics
https://github.com/FYSETC/FYSETC-SPIDER ... %20SCH.pdf
it uses the on-chip usb and the boot0 pin is on a header.
so all you need is set boot0
reset and you can upload firmware using the on-chip usb over DFU
no additional boot loader is needed.
you can use stm32 cube programmer for that
https://www.st.com/en/development-tools ... eprog.html

any other boot loaders are custom developments and not any part of a standard stm32 chip or board.
it isn't too difficult to learn how to program the on-chip flash (using registers), check the ref manual.
once you figured it out, i'd guess you could write a 'boot loader' say that lives in 'high memory', so that you code can jump to that fixed location when you want to load firmware, and it can even simply receive data over usb serial and write to 0x8000000 start of flash.
That is what in essence is a "boot loader"

for the rest search around the web e.g. hid bootloader etc, those are custom developments (by others) and they don't follow any particular standards.
it is their own designs and protocol.

In your sketch, if you want usb (CDC) serial, you need to select that from the menu when building the sketch.

search also in the ref manual for a 'soft boot0', i.e. something that you sketch can set so that at a next call into HAL_NVIC_SystemReset();
it drops into DFU mode. then it saves you the extra step of manually setting boot0.
But you need to program your sketch yourself to do that.
geocheats2
Posts: 6
Joined: Sat Aug 28, 2021 8:52 pm

Re: Arduino bootloader development

Post by geocheats2 »

ag123 wrote: Fri Jun 24, 2022 6:51 am based on the schematics
https://github.com/FYSETC/FYSETC-SPIDER ... %20SCH.pdf
it uses the on-chip usb and the boot0 pin is on a header.
so all you need is set boot0
reset and you can upload firmware using the on-chip usb over DFU
no additional boot loader is needed.
you can use stm32 cube programmer for that
https://www.st.com/en/development-tools ... eprog.html
I already did this and it seems to upload but my blink sketch didn't actually blink, but i guess i must have had the led pin misconfigured
ag123 wrote: Fri Jun 24, 2022 6:51 am any other boot loaders are custom developments and not any part of a standard stm32 chip or board.
it isn't too difficult to learn how to program the on-chip flash (using registers), check the ref manual.
once you figured it out, i'd guess you could write a 'boot loader' say that lives in 'high memory', so that you code can jump to that fixed location when you want to load firmware, and it can even simply receive data over usb serial and write to 0x8000000 start of flash.
That is what in essence is a "boot loader"
That seems really interesting do you have any "project" in mind that might use this logic?


ag123 wrote: Fri Jun 24, 2022 6:51 am for the rest search around the web e.g. hid bootloader etc, those are custom developments (by others) and they don't follow any particular standards.
it is their own designs and protocol.
So you don't recommend trying to port those bootloaders to my mcu.

ag123 wrote: Fri Jun 24, 2022 6:51 am In your sketch, if you want usb (CDC) serial, you need to select that from the menu when building the sketch.
For the usb i have this set on my platformio.ini

Code: Select all

build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC -D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE
file but it doesn't seem to work because on normal boot i don't get any sound like a new device has been plugged in and i don't see anything on my device manager
ag123 wrote: Fri Jun 24, 2022 6:51 am search also in the ref manual for a 'soft boot0', i.e. something that you sketch can set so that at a next call into HAL_NVIC_SystemReset();
it drops into DFU mode. then it saves you the extra step of manually setting boot0.
But you need to program your sketch yourself to do that.
I guess i can call this function right from inside my sketch?

btw, thanks for all the info it made things clearer
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Arduino bootloader development

Post by ag123 »

for '3rd party' boot loaders i.e. not there in a bare stm32
some of them are like those discussed e.g. in this sub
viewforum.php?f=58
https://github.com/Serasidis/STM32_HID_Bootloader

Some of these are personal developments in which the authors contributed them as open sourced projects.
I did not use them, so I'm not able to comment more about them.

I'm quite happy with the trouble of all that 'boot0' manual toggles as the board I used
https://stm32-base.org/boards/STM32F401 ... -Pill-V1.2
the boot0 is simply a toggle button which I can easily access, and typically it (the board) is just on my desk.

So I'd just toggle it manually and later flash away.
I used dfu-util as I'm in Linux
http://dfu-util.sourceforge.net/
But I'd think stm32 cube programmer works just well and it is the means directly supported in the 'official' STM core. I used dfu-util as the other is bulkier kind of, while dfu-util is a little 'utility' in a single small file < 1 MB, so I'd place it 'anywhere convenient'. This may not be true in Windows. stm32 cube programmer has in addition features to update firmware in ST-link dongles. Oh and st-link (v2) dongles are pretty much a 'must have', to do anything 'deeper' with stm32.
https://www.adafruit.com/product/2548
https://octopart.com/st-link%2Fv2-stmic ... 57793?r=sp
it can be used to flash firmware too and this doesn't need that boot0 button. But it'd still need wires to be connected.

I'm not using platformIO, Hence, I can't comment about it. But do note that the 'official' repository is here
https://github.com/stm32duino/Arduino_Core_STM32
Other platforms, when they use / derive from this, may have adapted it to add other things that may be a feature in those cores e.g. in PlatformIO. But they are not necessarily the same as the 'official' source. Which is mainly tested on the Arduino IDE 1.8.x

I'm also looking out for that 'soft boot0', I think the stm32f4xx and above probably have that feature. This is literally the "short cut" that instead of writing a boot loader, I'm thinking of using my sketch to 'set soft boot0' then run HAL_NVIC_SystemReset() to go to the built-in on chip boot loader.
It do saves a lot of hassle.

But in the mean time, I'm using that internal/on chip (usb DFU) boot loader which needs toggling of the boot0 pins.
it works adequately well.

In terms of writing to the internal flash, look in the ref manual for the chapters on flash memory.
I actually used it successfully as storage for one of my own apps, a logger kind of.
Once you figure it out, I'd think writing a 'boot loader' is simply finding a way to receive the 'data' and writing it to the "right" places.
Putting the 'boot loader' in 'high' memory is a typical strategy as the normal start of flash is 0x8000000.
So to be a 'boot loader' it needs to sit outside the block where it is erasing and writing over it, hence the 'high memory' design.
I think if you bother to dig around github etc, there are probably some implementations. Though it may not be for stm32duino.

But all these are still a 'hassle', so try to find the 'short cut' e.g. that 'soft boot0', dig thru the ref manual, If you found it to update comments here as well :)
That would save all the trouble, as the USB DFU boot loader is basically built-in on chip.

But I noted that quite commonly, after flashing, I'd need to do a reset, i.e. NRST.
I'd think it is partly as I used a public domain dfu-util utility which may not have codes that use specific stm32 features.
Post Reply

Return to “STM32F4 based boards”