Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add st-flash flash target #9964

Merged
merged 2 commits into from
Aug 12, 2020
Merged

Conversation

sigprof
Copy link
Contributor

@sigprof sigprof commented Aug 7, 2020

Description

Add support for flashing the firmware via the st-flash utility from the STLink Tools package (https://github.com/stlink-org/stlink).

The ST-LINK CLI utility used by the st-link-cli target is proprietary and Windows-only; the st-flash utility is open source (BSD 3-clause), and the STLink Tools package (called stlink, or sometimes stlink-tools) is available in many Linux distributions and in Homebrew for Mac OS.

I tested this with some STM32 development boards:

  • STM32F103C8T6 “Bluepill” with the STM32duino user bootloader (the bootloader remains intact after flashing the handwired/onekey/bluepill firmware over ST-LINK)
  • STM32F401CCU6 “Blackpill”
  • STM32F411CEU6 “Blackpill”

The main reason for this PR is that some of the STM32F401CCU6 “Blackpill” boards sold on AliExpress apparently suffer from a combination of design deficiency and suboptimal component quality, and the builtin DFU bootloader on them is unreliable to the point of being unusable, so flashing them over ST-LINK seems to be much easier than trying to make the DFU bootloader start up properly by heating up the MCU. The problem is that the designer of those boards decided to use a 25 MHz crystal for HSE, and the builtin DFU bootloader attempts to determine the HSE frequency using the builtin HSI RC oscillator as a reference, which could actually work properly if the HSI frequency was within ±1% of 16 MHz, as written in the datasheet; however, apparently on some chips the factory calibration of HSI is much worse, and if the error is more than about 2% (for the 25 MHz crystal), the HSE frequency detection does not work properly, and then DFU gets lots of USB errors and does not work. Running the actual QMK firmware on those boards is not a problem, however, because the firmware uses a static PLL configuration for the 25 MHz crystal, and a wrong HSI frequency does not matter.

Other “Blackpill” board versions (STM32F411CEU6 and the updated STM32F401CEU6) could potentially have the same problem (they have the same 25 MHz HSE crystal).

I targeted the PR to develop, as requested in the new PR checklist, but the base of the branch is also suitable for master, if you decide that the change is trivial enough to be added there directly.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Add support for flashing the firmware via the `st-flash` utility from
the STLink Tools package (https://github.com/stlink-org/stlink).
@tzarc tzarc requested review from tzarc and a team August 8, 2020 01:15
@tzarc tzarc self-assigned this Aug 8, 2020
@tzarc
Copy link
Member

tzarc commented Aug 8, 2020

For the record, I've also struck the annoying DFU problem with the F401's (maybe 1 in 8 successful boots to DFU), but the F411's I've got have all worked fine even with the 25MHz crystal.

Copy link
Member

@tzarc tzarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F103, F401, F411 all good.

@tzarc tzarc requested a review from a team August 8, 2020 02:15
@tzarc tzarc removed their assignment Aug 8, 2020
@sigprof
Copy link
Contributor Author

sigprof commented Aug 9, 2020

I found another place where the available flashing tools (somewhat confusingly named “bootloaders”) are listed — the qmk flash -b output, so I added st-flash there too (the -bl st-flash option worked even without that changes, only the help output was affected).

Copy link
Member

@noroadsleft noroadsleft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@noroadsleft noroadsleft merged commit 6a8cbaa into qmk:develop Aug 12, 2020
@noroadsleft
Copy link
Member

Thanks!

noroadsleft pushed a commit that referenced this pull request Aug 27, 2020
* Add `st-flash` flash target

Add support for flashing the firmware via the `st-flash` utility from
the STLink Tools package (https://github.com/stlink-org/stlink).

* Add `st-flash` to the `qmk flash -b` output
noroadsleft pushed a commit that referenced this pull request Aug 29, 2020
* Add `st-flash` flash target

Add support for flashing the firmware via the `st-flash` utility from
the STLink Tools package (https://github.com/stlink-org/stlink).

* Add `st-flash` to the `qmk flash -b` output
@sigprof sigprof deleted the add-st-flash-support branch September 2, 2020 20:38
nicocesar pushed a commit to nicocesar/qmk_firmware that referenced this pull request Sep 6, 2020
* Add `st-flash` flash target

Add support for flashing the firmware via the `st-flash` utility from
the STLink Tools package (https://github.com/stlink-org/stlink).

* Add `st-flash` to the `qmk flash -b` output
drashna pushed a commit to zsa/qmk_firmware that referenced this pull request Sep 30, 2020
* Add `st-flash` flash target

Add support for flashing the firmware via the `st-flash` utility from
the STLink Tools package (https://github.com/stlink-org/stlink).

* Add `st-flash` to the `qmk flash -b` output
kjganz pushed a commit to kjganz/qmk_firmware that referenced this pull request Oct 28, 2020
* Add `st-flash` flash target

Add support for flashing the firmware via the `st-flash` utility from
the STLink Tools package (https://github.com/stlink-org/stlink).

* Add `st-flash` to the `qmk flash -b` output
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
* Add `st-flash` flash target

Add support for flashing the firmware via the `st-flash` utility from
the STLink Tools package (https://github.com/stlink-org/stlink).

* Add `st-flash` to the `qmk flash -b` output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants