This HID bootloader does not load the Arduino sketch, why

Bootloader for STM32F103 and STM32F4xx micro-controllers
No special driver is required. Support for Windows, Linux and Mac Operating System
Rekog
Posts: 13
Joined: Mon Jun 28, 2021 6:10 pm

This HID bootloader does not load the Arduino sketch, why

Post by Rekog »

Ive downloaded this bootloader from
https://github.com/Serasidis/STM32_HID_Bootloader

How can I make it work with Arduino sketch ?

Else this bootloader configured with serial communication does load the Arduino sketch:
https://github.com/rogerclarkmelbourne/ ... bootloader

Here's my sketch:

Code: Select all

#define LED_BUILTIN PB11

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: This HID bootloader does not load the Arduino sketch, why

Post by stevestrong »

You have to select the corresponding bootloader in Arduino menu when uploading the sketch.
Rekog
Posts: 13
Joined: Mon Jun 28, 2021 6:10 pm

Re: This HID bootloader does not load the Arduino sketch, why

Post by Rekog »

stevestrong wrote: Thu Jul 01, 2021 2:26 pm You have to select the corresponding bootloader in Arduino menu when uploading the sketch.
Where is that option ?

Else I forgot to says that it makes the board unfunctional after uploading the sketch with hid flash
dfq.png
dfq.png (4.76 KiB) Viewed 11949 times
Also is there a way to merge the Arduino sketch with this HID bootloader, like we already do with the Serial bootloader ?

I used the same method, calling merge.exe but it's not working at all.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: This HID bootloader does not load the Arduino sketch, why

Post by stevestrong »

Rekog wrote: Tue Jul 06, 2021 12:52 pm Where is that option ?
Tools -> Upload method -> HID bootloader 2.0
Rekog wrote: Tue Jul 06, 2021 12:52 pmElse I forgot to says that it makes the board unfunctional after uploading the sketch with hid flash
Well, it depends whether do you use USB serial or not in your sketch.
Which board do you have?
Rekog
Posts: 13
Joined: Mon Jun 28, 2021 6:10 pm

Re: This HID bootloader does not load the Arduino sketch, why

Post by Rekog »

Yes it was I used, HID bootloader 2.0.

The board is a STM32F103C8Tb.

I do not use USB serial in the sketch as you can see, I just try to turn on/off a digital port.

This board do accept the upload of HID bootloader, also my customized HID bootloader, but it doesn't accept my Arduino sketch.

I wonder how can I program it if what Arduino generate isn't compatible with my board.

Ive compared the device memory (bootloader section) before and after the Arduino upload and it's the same, despite the device become unrecognizable after the upload, make no sense at all.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: This HID bootloader does not load the Arduino sketch, why

Post by stevestrong »

It is normal that the board is not recognizable over USB after uploading your sketch if you do not use USB serial in your sketch.
What do you expect?
The HID interface is only active at reset time very shortly just to check whether there is already a user program in flash or not.
If so, then it jumps to it and runs it.
If not, then it waits for an upload instruction.

The next time you want to upload a sketch you have to either:
- reset manually the board short before the upload process starts, or
- set BOOT1 jumper to 1 and reset the board - this way the HID bootloader will wait for any upload instruction and will not execute automatically the program available in flash, but wait for ulpoad instruction. Then, when finished, you have to set BOOT1 again to 0 and reset the board.

For best experience I recommend to use USB serial in your sketch, so that the HID bootloader can automatically be called over USB serial when new sketch shall be uploaded.
Rekog
Posts: 13
Joined: Mon Jun 28, 2021 6:10 pm

Re: This HID bootloader does not load the Arduino sketch, why

Post by Rekog »

Still not working else the sketch is actually written in the device memory after upload with Arduino, but it just mess all the board that make it unrecognizable.

Image

And what do you mean by not using Serial in my sketch, why should I use serial function if I only want an HID device and digital port management.

Code: Select all

#define LED_BUILTIN PB11

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: This HID bootloader does not load the Arduino sketch, why

Post by ag123 »

the 'secret' is in the ldscript files, normally that (the program begin address) is associated with the 'upload' method, hence selecting a different 'upload' method or bootloader chooses a different ldscript and hence a different program address.
it shouldn't be too hard to review platform.txt or boards.txt to see how they are linked and select the appropriate 'upload' method
but this is mainly so that the compiler would build the binaries for that start address.

and when you install the sketch firmware, u'd need to select the correct install address as well. normally that is taken care by the 'upload method' or more correctly the 'boot loader' (that is preinstalled in the device, e.g. hid bootloader). however, if you use things like st-link, u'd need to specify the correct address. i think the hid bootloader requires a desktop side utility hidflash to install the firmware over to the hid bootloader

and one more thing, if you do not want to use usb serial, that's ok but press reset on the board and click download in the ide or run the install utility (e.g. hidflash) on the command line in the next second. that 'auto reset' code is built into the USB Serial device, if you remove it, then u'd need to reset it manually.
Rekog
Posts: 13
Joined: Mon Jun 28, 2021 6:10 pm

Re: This HID bootloader does not load the Arduino sketch, why

Post by Rekog »

Yes, the st-link upload the bootloader at 0x08000000

Image

Image

It shouldn't be that address ?

Also the arduino upload it to the correct address, just after the bootloader

Code: Select all

#define FLASH_BASE            ((uint32_t)0x08000000) /*!< FLASH base address in the alias region */
#define BOOTLOADER_SIZE	(2 * 1024)						// Bootloader size
#define USER_PROGRAM	(FLASH_BASE + BOOTLOADER_SIZE)	// HID Bootloader takes 2 kb flash

funct_ptr UserProgram = (funct_ptr)*(volatile uint32_t*)(USER_PROGRAM);
Image

And USER_PROGRAM is equal to 0x08000800

So the Arduino sketch has a problem.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: This HID bootloader does not load the Arduino sketch, why

Post by ag123 »

0x8000000 is start of flash, if you want to use that, then you won't have the 'boot loader'
you might as well just stick with st-link if you have a st-link
Post Reply

Return to “STM32 HID bootloader”