Code Monkey home page Code Monkey logo

stm32_hid_bootloader's Introduction

STM32_HID_bootloader

Notice

This software is experimental and a work in progress. Under no circumstances should these files be used in relation to any critical system(s). Use of these files is at your own risk.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Summary

This is a driverless (no USB drivers needed, even on Windows) USB HID bootloader for STM32F10x and STM32F4xx devices.

It doesn't use ST libraries since they are bloated and buggy. Only CMSIS and some required system files and macros have been used from ST provided SDK.

This allowed for a very small bootloader 4 KB 2 KB on STM32F10x devices. On STM32F4xx devices there is no point to make the bootloader much smaller than 16 KB because the first flash page is already 16 KB.

This repo is based on bootsector's stm32-hid-bootloader repository but is customized to follows the Arduino_Core_STM32 Core requirements. The source files (Bootloader and CLI) can be compiled on Windows, Linux or Mac.

For your convenience, you can find here the hid-flash tool for these three platforms and the F1 and F4 firmware binaries.

Installing the HID bootloader to STM32 devices

(ST-Link version)

  1. Download the latest HID Bootloader release
  2. Download the texane stlink according to your operating system (Windows, MacOSX, Linux)
  3. Extract the texane stlink to your hard disk. You will need the file st-flash (it is into the bin folder).
  4. Copy into that folder the HID Bootloader file (xxx.bin) according to your board. e.g. hid_generic_pc13.bin file is for BluePill board, hid_maple_mini.bin is for Maple Mini board etc. The on-board LED is connectet to the PC13 pin.
  5. Connect BOOT-0 and BOOT-1 pins (or on-board jumpers) to GND ('0' on BluePill board)
  6. Type on Windows CMD (or Linux terminal) st-flash.exe write hid_generic_pc13.bin 0x8000000 for programming the HID Bootloader firmware to a BluePill board.
  7. Apply the Arduino_STM32_patch from here in case of using Roger's Core (select the zip file according to your Operating System).
  8. Select from Arduino IDE Tools > Board > [your_stm32_board]
  9. Select Tools > Upload method > HID Bootloader 2.1 or newer
  10. You are ready !

Normally, both BOOT-0 and BOOT-1 must be connected to '0'. If you connect BOOT-1 pin to 3.3V (or '1' on BluePill boards), the board will stay in HID Bootloader mode.

(Serial Dongle version)

  1. Download the latest HID Bootloader release
  2. Download the stm32flash from Roger's Clark Github repo.
  3. Extract the stm32flash to your hard disk.
  4. Copy into that folder the HID Bootloader file (xxx.bin) according to your board. e.g. hid_generic_pc13.bin file is for BluePill board, hid_maple_mini.bin is for Maple Mini board etc The on-board LED is connectet to the PC13 pin.
  5. Set BOOT-0 pin to '1' (3.3V) and reset the board
  6. Type on Windows CMD (or Linux terminal) stm32flash.exe -g 0x8000000 -b 115200 -w hid_generic_pc13.bin COM2 or stm32flash -g 0x8000000 -b 115200 -w hid_generic_pc13.bin /dev/ttyS0 for programming the HID Bootloader firmware to a BluePill board.
  7. Apply the Arduino_STM32_patch from here in case of using Roger's Core (select the zip file according to your Operating System).
  8. Select from Arduino IDE Tools > Board > [your_stm32_board]
  9. Select Tools > Upload method > HID Bootloader 2.1 or newer
  10. You are ready !

CLI folder

cli folder contains the source code for creating the command line tool hid-flash tool. This bootloader should't have any compiler restrictions, so it should work with any GCC ARM toolchain version (latest is always recommended!). Just run 'make' on that folder.

The hid-flash binary tool (executable) is also included in the latest HID Bootloader release

Linux udev setup:

To use the HID bootloader without root permissions the following udev rule needs to be installed to the /etc/udev/rules.d/99-stm32_hid_bl.rules

# STM32_HID_bootloader
ATTRS{idProduct}=="beba", ATTRS{idVendor}=="1209", MODE:="666" 

You might need to reboot or run udevadm control --reload-rules and replug your device to use it as a normal user after installing.

Windows examples:

[YOUR_HDD_PATH]\STM32_HID_bootloader\cli>make clean Clears the previous generated files [YOUR_HDD_PATH]\STM32_HID_bootloader\cli>make Creates the hid-flash.exe file

Bootloader folder

bootloader folder contains the source code for creating the hid_bootloader.bin file that is burned into the STM32F103 flash memory. Currently, only STM32F103 MCU is supported. Making the hid_bootloader.bin

Examples:

STM32F10x

[YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F1>make clean Clears the previous generated files [YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F1>make generic-pc13 Creates the hid_bootloader.bin file, assigning the LED to pin PC13. Edit the make_all.bat file to see all supported pin options.

If you want to use a High Density Device such as *STM32F103RCT6, then you have to add an extra argument to the make command.

Example: [YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F1>make generic-pd2 PAGE_SIZE=2048 Creates the hid_bootloader.bin file, assigning the LED to pin PD2. Edit the make_all_hd.bat file to see all supported pin options.

STM32F4xx

[YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F4>make clean Clears the previous generated files [YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F4>make Creates the hid_bootloader.bin file

After compiling, the binary file can be found in:

[YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F4\build\hid_bootloader.bin

Screenshot

stm32_hid_bootloader's People

Contributors

arksine avatar marsoft avatar martonmiklos avatar serasidis avatar squonk42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

stm32_hid_bootloader's Issues

SKR Pro Bootloader USB Problem

Hello.

Regarding: Klipper3d/klipper#2949 (comment)

With st link i erased now the chip, flashed the bootloader, power down the system, add the jumper for Boot1 and power up the system.

No usb device but i see now with dmesg some USB Errors from the HID Bootloader. System is Ubuntu 20 running at a ASUS mainboard.

[329671.688194] hid-generic 0003:1209:BEBA.00BD: hiddev0,hidraw2: USB HID v1.11 Device [www.serasidis.gr STM32 HID bootloader] on usb-0000:00:14.0-3/input0
[329671.689955] usb 1-3: USB disconnect, device number 122
[329672.116761] usb 1-3: new full-speed USB device number 123 using xhci_hcd
[329672.268916] usb 1-3: device descriptor read/all, error -71
[329672.880768] usb 1-3: new full-speed USB device number 124 using xhci_hcd
[329673.288811] usb 1-3: device descriptor read/64, error -71
[329674.008803] usb 1-3: device descriptor read/64, error -71
[329674.116851] usb usb1-port3: attempt power cycle
[329674.976803] usb 1-3: new full-speed USB device number 125 using xhci_hcd
[329674.997813] usb 1-3: config 1 interface 0 altsetting 0 endpoint 0x1 has an invalid bInterval 32, changing to 4
[329674.998410] usb 1-3: New USB device found, idVendor=1209, idProduct=beba, bcdDevice= 3.00
[329674.998415] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[329674.998419] usb 1-3: Product: STM32 HID bootloader
[329674.998422] usb 1-3: Manufacturer: www.serasidis.gr
[329674.998424] usb 1-3: SerialNumber: 1234567890
[329675.004172] hid-generic 0003:1209:BEBA.00BE: hiddev0,hidraw2: USB HID v1.11 Device [www.serasidis.gr STM32 HID bootloader] on usb-0000:00:14.0-3/input0
[329675.100892] usb 1-3: USB disconnect, device number 125
[329675.532821] usb 1-3: new full-speed USB device number 126 using xhci_hcd
[329675.681004] usb 1-3: device descriptor read/all, error -71
[329676.292821] usb 1-3: new full-speed USB device number 127 using xhci_hcd
[329676.696844] usb 1-3: device descriptor read/64, error -71
[329677.416929] usb 1-3: Device not responding to setup address.
[329677.624865] usb 1-3: Device not responding to setup address.
[329677.832842] usb 1-3: device not accepting address 127, error -71
[329677.832929] usb usb1-port3: attempt power cycle
[329678.484857] usb 1-3: new full-speed USB device number 2 using xhci_hcd
[329678.505645] usb 1-3: config 1 interface 0 altsetting 0 endpoint 0x1 has an invalid bInterval 32, changing to 4
[329678.506250] usb 1-3: New USB device found, idVendor=1209, idProduct=beba, bcdDevice= 3.00
[329678.506255] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[329678.506258] usb 1-3: Product: STM32 HID bootloader
[329678.506262] usb 1-3: Manufacturer: www.serasidis.gr
[329678.506264] usb 1-3: SerialNumber: 1234567890
[329678.512255] hid-generic 0003:1209:BEBA.00BF: hiddev0,hidraw2: USB HID v1.11 Device [www.serasidis.gr STM32 HID bootloader] on usb-0000:00:14.0-3/input0
[329678.512488] usb 1-3: USB disconnect, device number 2
[329678.936859] usb 1-3: new full-speed USB device number 4 using xhci_hcd
[329679.093113] usb 1-3: device descriptor read/all, error -71
[329679.704873] usb 1-3: new full-speed USB device number 5 using xhci_hcd
[329680.108891] usb 1-3: device descriptor read/64, error -71

libusb-1.0 is there a version suitable for other debian os

I can not use the HID flash in Klipper on Beaglebone Black or Orangepi zero, works a treat on a RPI tho.
I get the same problems on non RPI

hid-flash requires libusb-1.0, please install with:
sudo apt-get install libusb-1.0

sudo apt-get install libusb-1.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libusb-1.0-0' for regex 'libusb-1.0'
Note, selecting 'libusb-1.0-0-dev' for regex 'libusb-1.0'
Note, selecting 'libusb-1.0-doc' for regex 'libusb-1.0'
libusb-1.0-0 is already the newest version (2:1.0.22-2).
libusb-1.0-0-dev is already the newest version (2:1.0.22-2).
libusb-1.0-doc is already the newest version (2:1.0.22-2).

Seems there is no libusb-1.0 for other Debian variants only libusb-1.0-0 which your script does not recognize?

Usb doesn't show after flashing on either w10 or linux

Hi, I tried flashing your hid bootloader on my skr 1.2 pro using an st-link v2 in various ways but couldn't get the board recognized with either w10 or my pi, the st-link works and if I flash back the stock bootloader I can see the board on both systems. I also tried compiling from the files in the F4 folder still with no success. I tried with both bt0 and bt1 to gnd, both to 3.3, bt0 only to 3.3, bt1 only to 3.3, flashing and then using a jumper to 3.3. Board to st link is 3.3->3.3, gnd->gnd, rst->rst, jtck->swc and jtd->swd.

Using the method listed here up to step 6
This is what the stock outputs

c:\stlink-1.7.0-x86_64-w64-mingw32\bin>st-flash.exe write pro.bin 0x8000000
st-flash 1.7.0
2021-05-17T19:05:21 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
file pro.bin md5 checksum: 5ca97ea16df364d893b852ef7b8659e, stlink checksum: 0x0e7b1b85
2021-05-17T19:05:21 INFO common.c: Attempting to write 1048576 (0x100000) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Sector:0x0 Size:0x4000 2021-05-17T19:05:22 INFO common.c: Flash page at addr: 0x08000000 erased
EraseFlash - Sector:0x1 Size:0x4000 2021-05-17T19:05:22 INFO common.c: Flash page at addr: 0x08004000 erased
EraseFlash - Sector:0x2 Size:0x4000 2021-05-17T19:05:22 INFO common.c: Flash page at addr: 0x08008000 erased
EraseFlash - Sector:0x3 Size:0x4000 2021-05-17T19:05:23 INFO common.c: Flash page at addr: 0x0800c000 erased
EraseFlash - Sector:0x4 Size:0x10000 2021-05-17T19:05:24 INFO common.c: Flash page at addr: 0x08010000 erased
EraseFlash - Sector:0x5 Size:0x20000 2021-05-17T19:05:26 INFO common.c: Flash page at addr: 0x08020000 erased
EraseFlash - Sector:0x6 Size:0x20000 2021-05-17T19:05:28 INFO common.c: Flash page at addr: 0x08040000 erased
EraseFlash - Sector:0x7 Size:0x20000 2021-05-17T19:05:29 INFO common.c: Flash page at addr: 0x08060000 erased
EraseFlash - Sector:0x8 Size:0x20000 2021-05-17T19:05:31 INFO common.c: Flash page at addr: 0x08080000 erased
EraseFlash - Sector:0x9 Size:0x20000 2021-05-17T19:05:33 INFO common.c: Flash page at addr: 0x080a0000 erased
EraseFlash - Sector:0xa Size:0x20000 2021-05-17T19:05:35 INFO common.c: Flash page at addr: 0x080c0000 erased
EraseFlash - Sector:0xb Size:0x20000 2021-05-17T19:05:37 INFO common.c: Flash page at addr: 0x080e0000 erased
2021-05-17T19:05:37 INFO common.c: Finished erasing 12 pages of 131072 (0x20000) bytes
2021-05-17T19:05:37 INFO common.c: Starting Flash write for F2/F4/F7/L4
2021-05-17T19:05:37 INFO flash_loader.c: Successfully loaded flash loader in sram
2021-05-17T19:05:37 INFO flash_loader.c: Clear DFSR
2021-05-17T19:05:37 INFO flash_loader.c: Clear CFSR
2021-05-17T19:05:37 INFO flash_loader.c: Clear HFSR
2021-05-17T19:05:37 INFO common.c: enabling 32-bit flash writes
2021-05-17T19:05:50 INFO common.c: Starting verification of write complete
2021-05-17T19:06:00 INFO common.c: Flash written and verified! jolly good!

and this is what yours outputs

c:\stlink-1.7.0-x86_64-w64-mingw32\bin>st-flash.exe write hid_bootloader_skr_pro.bin 0x8000000
st-flash 1.7.0
2021-05-17T19:37:15 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
file hid_bootloader_skr_pro.bin md5 checksum: 274a67768af64627278e5e5a639467, stlink checksum: 0x0018915d
2021-05-17T19:37:15 INFO common.c: Attempting to write 16168 (0x3f28) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Sector:0x0 Size:0x4000 2021-05-17T19:37:15 INFO common.c: Flash page at addr: 0x08000000 erased
2021-05-17T19:37:15 INFO common.c: Finished erasing 1 pages of 16384 (0x4000) bytes
2021-05-17T19:37:15 INFO common.c: Starting Flash write for F2/F4/F7/L4
2021-05-17T19:37:15 INFO flash_loader.c: Successfully loaded flash loader in sram
2021-05-17T19:37:15 INFO flash_loader.c: Clear DFSR
2021-05-17T19:37:15 INFO common.c: enabling 32-bit flash writes
2021-05-17T19:37:15 INFO common.c: Starting verification of write complete
2021-05-17T19:37:16 INFO common.c: Flash written and verified! jolly good!

I tried with st-flash, stm32cube and stm32 st-link utility, but I can't seem to find a way to get yours seen either from the pi or my laptop, am I missing something?

The only way to have it show was to keep the bt1-3.3 jumper and pressing the reset button and then it shows as Bus 001 Device 021: ID 1209:beba Generic serasidis.gr STM32 HID Bootloader
but even then it can't be flashed by klipper.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.