8
33
Fork
You've already forked blackmagic
23

Feature: Arterytek option bytes and more part IDs #1803

Merged
ALTracer merged 6 commits from feature/at32f4-ob-partid into main 2024年11月09日 05:54:44 +01:00
ALTracer commented 2024年04月19日 22:23:02 +02:00 (Migrated from github.com)
Copy link

Detailed description

  • This is a new feature.
  • Currently there's no easy way to extend SRAM of AT32F403A via monitor option commands because EOPB0 is out of reach for the normal 16-byte driver.
  • The PR solves it by conditionally bumping the option byte ranges.

Past first commit see my work of adding yet more part ID lists for other families in AT32F4 lineup. This is probably getting unmanageable, so I started incorporating F_SIZE and "Product ID" readouts from UID (in their DESig analog). If this is fine, e.g. does not result in problems for RDP1-enabled targets, then all such lists can be dropped or gated under ENABLE_DEBUG to not hog precious BMF flash -- it only needs to know flash parameters (banks, sector size, total size), not exact package & pinout. I may move this to a separate PR (and a split translation unit) as no users have probably asked for F421, F413 or F425. F423 and F402/F405 are plain unimplemented (F405 with USB HS PHY would be nice to have though). I have none of these chips to test on.

Your checklist for this pull request

Closing issues

Allows operating Arterytek User System Data, including Flash Access Protection enable/disable ops.

## Detailed description * This is a new feature. * Currently there's no easy way to extend SRAM of AT32F403A via `monitor option` commands because EOPB0 is out of reach for the normal 16-byte driver. * The PR solves it by conditionally bumping the option byte ranges. Past first commit see my work of adding yet more part ID lists for other families in AT32F4 lineup. This is probably getting unmanageable, so I started incorporating F_SIZE and "Product ID" readouts from UID (in their DESig analog). If this is fine, e.g. does not result in problems for RDP1-enabled targets, then all such lists can be dropped or gated under ENABLE_DEBUG to not hog precious BMF flash -- it only needs to know flash parameters (banks, sector size, total size), not exact package & pinout. I may move this to a separate PR (and a split translation unit) as no users have probably asked for F421, F413 or F425. F423 and F402/F405 are plain unimplemented (F405 with USB HS PHY would be nice to have though). I have none of these chips to test on. ## Your checklist for this pull request * [x] I've read the [Code of Conduct](https://github.com/blackmagic-debug/blackmagic/blob/main/CODE_OF_CONDUCT.md) * [x] I've read the [guidelines for contributing](https://github.com/blackmagic-debug/blackmagic/blob/main/CONTRIBUTING.md) to this repository * [x] It builds for hardware native (see [Building the firmware](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-firmware)) ...and overflows flash * [x] It builds as BMDA (see [Building the BMDA](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-app)) * [x] I've tested it to the best of my ability * [x] My commit messages provide a useful short description of what the commits do ## Closing issues Allows operating Arterytek User System Data, including Flash Access Protection enable/disable ops.
dragonmux left a comment
Copy link

Please can you rebase this on main and run clang-format. We'll do a proper review at that point rather than just a quick cursory as we're anticipating it's pretty close to already being mergable.

Apologies this one slipped through the cracks and we failed to review it at all till now.

Please can you rebase this on `main` and run `clang-format`. We'll do a proper review at that point rather than just a quick cursory as we're anticipating it's pretty close to already being mergable. Apologies this one slipped through the cracks and we failed to review it at all till now.

All #define's should go at the top of the file after the #include block please.

All `#define`'s should go at the top of the file after the `#include` block please.
ALTracer commented 2024年09月29日 22:47:46 +02:00 (Migrated from github.com)
Copy link

Rebased and clang-formatted.
I only wanted 48 option bytes for AT32F403A (especially RDP1 and EOPB0). Even that impl is bad -- it would affect GD32F1 etc. because of TOPT_32BIT criteria. The stm32f1-generic flash driver does not record option byte region size. If you have any better ideas -- I'll try to edit them in for a minor but effective change (no large driver-scope refactoring).
I would rather migrate/move the rest of chips/targets into at32f43x.c sometime in the future, but that should be made more generic as well to handle that. And it'd shrink the stm32f1.o (always compiled).

Rebased and clang-formatted. I only wanted 48 option bytes for AT32F403A (especially RDP1 and EOPB0). Even that impl is bad -- it would affect GD32F1 etc. because of TOPT_32BIT criteria. The stm32f1-generic flash driver does not record option byte region size. If you have any better ideas -- I'll try to edit them in for a minor but effective change (no large driver-scope refactoring). I would rather migrate/move the rest of chips/targets into at32f43x.c sometime in the future, but that should be made more generic as well to handle that. And it'd shrink the stm32f1.o (always compiled).
dragonmux left a comment
Copy link

There are a couple of remaining review notes to deal with, and once they've been sorted we're happy for this to merge.

There are a couple of remaining review notes to deal with, and once they've been sorted we're happy for this to merge.

This is a useful tidbit to know but we don't see how it relates to the line after it or how it impacts things. Please flesh this out as a comment perhaps around line 424 as part facts and how they reflect onto the implementation.

This is a useful tidbit to know but we don't see how it relates to the line after it or how it impacts things. Please flesh this out as a comment perhaps around line 424 as part facts and how they reflect onto the implementation.
@ -467,0 +585,4 @@
case 0x008bU: // TSSOP20
case 0x0093U: // QFN28
// Flash (6): 32 KiB / 1 KiB per block
stm32f1_add_flash(target, 0x08000000, 32U * 1024U, 1U * 1024U);

The extra parens here are superfluous and can be dropped - same on line 607 for the clause after the &&. They suppress the GCC warning about accidental assignment that we want here.

The extra parens here are superfluous and can be dropped - same on line 607 for the clause after the `&&`. They suppress the GCC warning about accidental assignment that we want here.
@ -475,11 +673,49 @@ bool at32f40x_probe(target_s *target)
const uint32_t idcode = target_mem32_read32(target, STM32F1_DBGMCU_IDCODE);

This doesn't appear to check any ID codes before going "yeah, sure, it's a AT32F425"?

This doesn't appear to check any ID codes before going "yeah, sure, it's a AT32F425"?
ALTracer (Migrated from github.com) reviewed 2024年10月02日 20:24:16 +02:00
ALTracer (Migrated from github.com) commented 2024年10月02日 20:24:16 +02:00
Copy link

This line prefixes the (new) linkage of stm32f1_cmd_list which contains an entrypoint to stm32f1_cmd_option which I mangled badly to edit all 48 option bytes.

This line prefixes the (new) linkage of `stm32f1_cmd_list` which contains an entrypoint to `stm32f1_cmd_option` which I mangled badly to edit all 48 option bytes.
ALTracer (Migrated from github.com) reviewed 2024年10月02日 20:25:55 +02:00
@ -475,11 +673,49 @@ bool at32f40x_probe(target_s *target)
const uint32_t idcode = target_mem32_read32(target, STM32F1_DBGMCU_IDCODE);
ALTracer (Migrated from github.com) commented 2024年10月02日 20:25:55 +02:00
Copy link

Correct, because the checking was done by its caller against 0x5009_2??? series. This function is implemented simpler because my theory is F_SIZE might be enough for BMD purposes.

Correct, because the checking was done by its caller against `0x5009_2???` series. This function is implemented simpler because my theory is F_SIZE might be enough for BMD purposes.
ALTracer (Migrated from github.com) reviewed 2024年10月02日 20:32:33 +02:00
@ -467,0 +585,4 @@
case 0x008bU: // TSSOP20
case 0x0093U: // QFN28
// Flash (6): 32 KiB / 1 KiB per block
stm32f1_add_flash(target, 0x08000000, 32U * 1024U, 1U * 1024U);
ALTracer (Migrated from github.com) commented 2024年10月02日 20:32:32 +02:00
Copy link

Removed two pairs of parens for project_id.

Removed two pairs of parens for project_id.
ALTracer commented 2024年10月02日 20:45:43 +02:00 (Migrated from github.com)
Copy link

While I don't think it ends good for GD32 in current form, I'd like to ask to if(!strcmp(target->driver, "AT32")) instead of TOPT so both would work as expected.
Rebased away the addition of AT32F405/F402 (HS USB) because their FPEC is at 0x40023C00 like F435/F437, not 0x40022000 as this driver is hardcoded to work on. Same for AT32F423 (three series, FPEC at incompatible offset, unsupported here).

While I don't think it ends good for GD32 in current form, I'd like to ask to `if(!strcmp(target->driver, "AT32"))` instead of TOPT so both would work as expected. Rebased away the addition of AT32F405/F402 (HS USB) because their FPEC is at 0x40023C00 like F435/F437, not 0x40022000 as this driver is hardcoded to work on. Same for AT32F423 (three series, FPEC at incompatible offset, unsupported here).

Ah, okie - in that case perhaps prefix this with NB: or so to indicate that you're delivering some extra information?

Ah, okie - in that case perhaps prefix this with `NB: ` or so to indicate that you're delivering some extra information?
ALTracer (Migrated from github.com) reviewed 2024年10月11日 22:58:33 +02:00
ALTracer (Migrated from github.com) commented 2024年10月11日 22:58:32 +02:00
Copy link

Moved up.

Moved up.

Once the single outstanding review note has been sorted, we're happy to get this merged. This is looking really good.

Once the single outstanding review note has been sorted, we're happy to get this merged. This is looking really good.
ALTracer (Migrated from github.com) reviewed 2024年10月12日 17:27:28 +02:00
ALTracer (Migrated from github.com) commented 2024年10月12日 17:27:27 +02:00
Copy link

Expanded oneline comment to carry more meaning.

Expanded oneline comment to carry more meaning.
ALTracer commented 2024年10月12日 17:33:54 +02:00 (Migrated from github.com)
Copy link

Replaced the option byte size dispatch check from TOPT 32-bit writes (shared with Gigadevices) to direct strncmp. This triggers correctly, 48 bytes (24 halfwords) for AT32F403A/407, but still 16 bytes (8 halfwords) for GD32F103 etc.
Did not register cmd_option for older F403 or newer F413, as I cannot test on them. Did not register it for F415 either, because it has 1024 not 48 bytes.
Added a few more families very likely compatible with STM32F1 flash driver. They all have UID/F_SIZE unreadable under RDP1, so need part ID tables. I started to notice a pattern "part ID <=> flash density", but the optimization would be handled in a follow-up PR, if ever.
Please review again.

Replaced the option byte size dispatch check from TOPT 32-bit writes (shared with Gigadevices) to direct strncmp. This triggers correctly, 48 bytes (24 halfwords) for AT32F403A/407, but still 16 bytes (8 halfwords) for GD32F103 etc. Did not register cmd_option for older F403 or newer F413, as I cannot test on them. Did not register it for F415 either, because it has 1024 not 48 bytes. Added a few more families very likely compatible with STM32F1 flash driver. They all have UID/F_SIZE unreadable under RDP1, so need part ID tables. I started to notice a pattern "part ID <=> flash density", but the optimization would be handled in a follow-up PR, if ever. Please review again.
dragonmux left a comment
Copy link

Having properly re-reviewed this, there's just one thing we found. Please address it and rebase on main then we'll approve this for merge.

Having properly re-reviewed this, there's just one thing we found. Please address it and rebase on `main` then we'll approve this for merge.
@ -459,11 +519,149 @@ static bool at32f41_detect(target_s *target, const uint16_t part_id)
target->part_id = part_id;

This preprocessor logic makes the #else part moot - please don't include dead code if at all possible. If what's needed can be achieved with just this 16-bit register read, then let's do that instead of having a large part ID switch-case.

This preprocessor logic makes the `#else` part moot - please don't include dead code if at all possible. If what's needed can be achieved with just this 16-bit register read, then let's do that instead of having a large part ID switch-case.
ALTracer (Migrated from github.com) reviewed 2024年10月28日 22:52:59 +01:00
@ -459,11 +519,149 @@ static bool at32f41_detect(target_s *target, const uint16_t part_id)
target->part_id = part_id;
ALTracer (Migrated from github.com) commented 2024年10月28日 22:52:58 +01:00
Copy link

No, there is a major problem of us not knowing flash size when RDP1 is active. Part IDs allow that. I would rather delete the easy two-liner and postpone it to the refactor, relying on part ID tables like all other routines (this table is thankfully small). We previously argued that read-locked flash should not be added anyways, just the option byte erase handler; but it's not implemented for 512 byte region.

No, there is a major problem of us not knowing flash size when RDP1 is active. Part IDs allow that. I would rather delete the easy two-liner and postpone it to the refactor, relying on part ID tables like all other routines (this table is thankfully small). We previously argued that read-locked flash should not be added anyways, just the option byte erase handler; but it's not implemented for 512 byte region.
@ -459,11 +519,149 @@ static bool at32f41_detect(target_s *target, const uint16_t part_id)
target->part_id = part_id;

Okay, in that case please document that in the code to explain why the preprocessor logic exists and the conditions required for its removal.

Okay, in that case please document that in the code to explain why the preprocessor logic exists and the conditions required for its removal.
ALTracer (Migrated from github.com) reviewed 2024年11月01日 19:00:38 +01:00
@ -459,11 +519,149 @@ static bool at32f41_detect(target_s *target, const uint16_t part_id)
target->part_id = part_id;
ALTracer (Migrated from github.com) commented 2024年11月01日 19:00:38 +01:00
Copy link

Inverted macro to gate the easy path and added TODO comments.

Inverted macro to gate the easy path and added TODO comments.
dragonmux left a comment
Copy link

LGTM, all items addressed. Merging. Thank you for the contribution!

LGTM, all items addressed. Merging. Thank you for the contribution!
Sign in to join this conversation.
No reviewers
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic!1803
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "feature/at32f4-ob-partid"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?