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

Feature: Implement SPI support for blackpill-f4 #1525

Merged
merged 3 commits into from
Jul 15, 2023

Conversation

ALTracer
Copy link
Contributor

@ALTracer ALTracer commented Jun 27, 2023

Detailed description

This PR implements support for the internal (on-board) SPI Flash found on the Blackpill series boards, mirroring the work done for "native" (BMP).

  • A new feature was implemented in Feature: SPI remote protocol #1499 for accessing probe-attached SPI flash chips via BMP remote protocol (and desktop cross-platform bmpflash client).
  • However, it only implements SPI platform code for native hardware, providing no-op stubs for all the other platforms.
  • I propose implementing platform_spi_init/deinit/chip_select/xfer for blackpill-f4 hardware, which I own and test on.

This change results in +320 +448 bytes flash footprint for blackpill-f4x1cx. Testing included sfdp and read from onboard w25q64 to desktop dualboot host (Linux Mint 21.1, Windows 11) using latest manually compiled bmpflash/substrate/fmt/libusb-1.0.
Read speed of 8MiB flash chip: Linux 200KiB/s, Win11 175KiB/s. File seems to match remains of NuttX SmartFS I kept there from previous development tests.

Misc. notes:

  • At APB2=96MHz and SPI1 DIV8, line clock frequency should be 12MHz which is reasonable (native/F1 uses APB1=36;/8=4.5MHz for EXT SPI1 and APB2=72;/8=9Mhz for AUX SPI2).
  • w25q64 datasheet states the chip supports accesses at clock frequency, when powered from 3.3v, in Standard SPI mode, 03h Read Data up to 50MHz and 0Bh Fast Read up to 104MHz.
  • I might add SPI2 on PB12/13/14/15 (F4 APB1=48Mhz) later as external/aux/etc. bus, these pins are not claimed yet. Added SPI2 with same divisor, 48/8=6MHz.
  • Other WeAct Studios designed hardware (BluePill Plus) also has SOIC-8 footprints on the bottom of PCB, so this PR might be useful in case somebody implements SPI support for that hardware later. It even maps that to the same GPIOs and HW SPI.

Your checklist for this pull request

  • I've read the Code of Conduct
  • I've read the guidelines for contributing to this repository
  • It builds for hardware native (make PROBE_HOST=native) -- changes another platform
  • It builds as BMDA (make PROBE_HOST=hosted) -- not applicable
  • I've tested it to the best of my ability
  • My commit messages provide a useful short description of what the commits do

Closing issues

No issues raised on SPI functionality by users of blackpill-f4 boards, because it was absent from platform code.

Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

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

This is looking good, but there are a few stylistic things to fix and a few queries about how things are being done we'd like answered before we can merge. Nice work though!

As a side note in the future: Your PR description goes to great lengths to talk about speed, testing, etc, but at no point does it actually describe as a single easily read paragraph what this PR implements and does. In the future, please start the description with something like:

This PR implements support for the internal (on-board) SPI Flash found on the Blackpill series boards, mirroring the work done for "native" (BMP).

If you open with something like that, it'll help provide context before you drop into technical details that are more a curiosity than providing us with information needed to review the PR itself.

src/platforms/common/blackpill-f4/blackpill-f4.c Outdated Show resolved Hide resolved
src/platforms/common/blackpill-f4/blackpill-f4.c Outdated Show resolved Hide resolved
src/platforms/common/blackpill-f4/blackpill-f4.c Outdated Show resolved Hide resolved
src/platforms/common/blackpill-f4/blackpill-f4.c Outdated Show resolved Hide resolved
@dragonmux dragonmux added this to the v1.10 milestone Jun 28, 2023
@dragonmux dragonmux added Enhancement General project improvement Foreign Host Board Non Native hardware to runing Black Magic firmware on labels Jun 28, 2023
@ALTracer
Copy link
Contributor Author

Applied suggested changes from first review pass, awaiting additional review comments or approval; then I will {fast-forward fork's main, rebase this PR, squash three commits into one}. Please don't merge this as-is until then, because a) fixups present; b) honestly SPI1 & SPI2 is a single feature.

@dragonmux
Copy link
Member

We'll aim to review the new code today then. Please do not squash the commits - as they are right now is better for git bisect, and git blame and allowing us to better follow the diff and peel one of them off if it ever needs reverting.

We very explicitly want 3 commits here because it's not about "by feature", it's about small atomic changes that are easily reviewed, etc.. the commits as they are, are a bit big anyway. Ideally we'd want them to be even more granular.

@dragonmux dragonmux changed the title Feature: Implement SPI1 for blackpill-f4 onboard NOR flash Feature: Implement SPI support for blackpill-f4 Jul 14, 2023
Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

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

There are a couple of small things that need tweaking, and once tweaked and keeping this as 3 separate commits (please), we're happy to merge this.

src/platforms/common/blackpill-f4/blackpill-f4.c Outdated Show resolved Hide resolved
src/platforms/common/blackpill-f4/blackpill-f4.c Outdated Show resolved Hide resolved
@ALTracer
Copy link
Contributor Author

For edits in this review would you like a new commit or amending?
I usually squash-rebase the (fixup) commits after reviews, but you always have the final say as the reviewer and maintainer.

@dragonmux
Copy link
Member

Amends please, both changes are quite small and clean up the diffs

* Inline macros into calls, dropping intermediate variables
* Duplicate gpio setup calls into respective branches
* Remove a couple comments
@ALTracer
Copy link
Contributor Author

Run-tested (sfdp & read) both before and after fast-forward rebase. Works for int bus, raises a proper error for ext bus without me connecting them with 4 duponts). Ready for merge to upstream.

Afterthoughts: there's no LED indication of SPI activity as blackpill has a single LED. BMF doesn't touch IDLE_RUN during remote-spi, and I don't touch PC13 in platform spi code. For now rely on bmpflash reporting progress or general PC performance monitors.

Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

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

LGTM, merging.

@dragonmux dragonmux merged commit 6c07eec into blackmagic-debug:main Jul 15, 2023
6 checks passed
@ALTracer ALTracer deleted the blackpill-f4-spi branch November 22, 2023 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement General project improvement Foreign Host Board Non Native hardware to runing Black Magic firmware on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants