Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Fix: minor deduplication in Puya driver - #2096

Merged
dragonmux merged 2 commits into
blackmagic-debug:mainfrom
ALTracer:fix/puya-dedup
Jul 21, 2025
Merged

Fix: minor deduplication in Puya driver#2096
dragonmux merged 2 commits into
blackmagic-debug:mainfrom
ALTracer:fix/puya-dedup

Conversation

@ALTracer

Copy link
Copy Markdown
Contributor

Detailed description

  • No new features.
  • The existing problem is code in puya_flash_prepare() is notably WET (or five-times), affecting BMF size in some configurations.
  • This PR tries to dry it a bit by picking the low-hanging fruit: epparaN is replaced by an array and a loop.

Not tested on any py32 devices which I don't have.
Discovered via staring at strings -n16 build-f411ce/blackmagic_blackpill_f411ce_firmware.bin | less output.

First commit doesn't affect BMF size, or saves 136 bytes when DEBUG_TARGET is enabled (in Farpatch or else). Consider this as preparation to enabling DEBUG_TARGET firmware-wide. Which is unlikely to happen in v2.0, so this can be tracked to v2.1.

Second commit brings minor savings of 32 bytes in release, or 64 with logging, probably by eliminating 4 extra calls to target_mem32_read32() and printf(). It does lose const-ness of eppara[5] but the scope is fairly small. I guess I could even optimize this to a 20-byte block read target_mem32_read() but it'd change behaviour, and I don't know how Puya flash controller reacts to it.

CC #1817 by @ArcaneNibble

Your checklist for this pull request

Closing issues

@dragonmux dragonmux added the Enhancement General project improvement label Mar 21, 2025
Comment thread src/target/puya.c Outdated
Comment thread src/target/puya.c Outdated

@dragonmux dragonmux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This LGTM, we'll get this merged when the v2.1 merge window opens. Thank you for the contribution!

@dragonmux dragonmux added this to the v2.1 release milestone Mar 22, 2025
@Badokas Badokas mentioned this pull request Apr 2, 2025
6 tasks
@dragonmux

Copy link
Copy Markdown
Member

Please rebase this on main and we'll get it merged now the v2.1 merge window has opened.

@ArcaneNibble

Copy link
Copy Markdown
Contributor

Am I still needed to test something here?

@ALTracer

Copy link
Copy Markdown
Contributor Author

Am I still needed to test something here?

Yes, I would prefer you took a test run of this 2096 and 2080 on any PY32F0 board you still have (and I still don't have any) -- the usual erase/flash/run, maybe reflash at five HSI scales to test voltage/frequency support.

@dragonmux

Copy link
Copy Markdown
Member

Given we're right at the start of the cycle, and as this code looks reasonable, we're going to merge this. If it turns out to be subtly wrong then a follow-up PR can be opened - we've got no problems with that.

@dragonmux
dragonmux merged commit 1b9e418 into blackmagic-debug:main Jul 21, 2025
36 checks passed
@ALTracer
ALTracer deleted the fix/puya-dedup branch February 21, 2026 21:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Enhancement General project improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants