7
31
Fork
You've already forked blackmagic
23

Feature: Add target for STM32WL3x #2198

Open
hallard wants to merge 1 commit from hallard/feature_stm32wl3 into main
pull from: hallard/feature_stm32wl3
merge into: blackmagic-debug:main
blackmagic-debug:main
blackmagic-debug:feature/bmda-remote-comms
blackmagic-debug:ALTracer/feature/aarch64-ident
blackmagic-debug:feature/better-meson-optimisation-handling
blackmagic-debug:feature/am335x-support
blackmagic-debug:feature/esp32-c3-support
blackmagic-debug:feature/cortex-ar-software-breakpoints
blackmagic-debug:feature/unit-testing
blackmagic-debug:feature/windows-usb-serial-interface-naming
blackmagic-debug:fix/bmp-external-spi
blackmagic-debug:ALTracer/feature/bluepillplus-platform
blackmagic-debug:ALTracer/feature/at32f43x-unrdp
blackmagic-debug:feature/const-correctness
blackmagic-debug:ALTracer/feature/fault_handlers
blackmagic-debug:ALTracer/feature/hazard3-ice40-support
blackmagic-debug:fix/ci-cleanup
blackmagic-debug:ALTracer/fix/gdb-10-12-thread
blackmagic-debug:ALTracer/feature/blackpill-f4-adc
blackmagic-debug:ALTracer/fix/cortex-desc-allocfail-report
blackmagic-debug:ALTracer/feature/spi-perf
blackmagic-debug:ALTracer/feature/calibrate_swd
blackmagic-debug:ALTracer/feature/blank-check
blackmagic-debug:feature/avr
blackmagic-debug:v2.0
blackmagic-debug:v1.9
blackmagic-debug:v1.10
blackmagic-debug:v1.8
hallard commented 2026年02月27日 13:53:41 +01:00 (Migrated from github.com)
Copy link

For the STM32WL3x, stm32wb0.c is the best place because:

  • Both are single-core Cortex-M0+ wireless MCUs
  • Both share the same flash controller at 0x40001000 with identical register layout and command codes (0x11/0x22/0x33/0xBB)
  • Same flash size formula: ((SIZE[15:0] + 1) << 2)
  • Same erase granularity (2KB sectors)
  • Both have the same write-then-poll pattern
  • avoid creating specific target and increase flash size

Detailed description

This PR add ability to use STM32WL3x targets

Your checklist for this pull request

Here below output of testing running demo

charles@office:debug$ arm-zephyr-eabi-gdb-py -ex 'set confirm off' -ex 'target extended-remote /dev/cu.usbmodem81D759AC1'
GNU gdb (Zephyr SDK 0.17.4) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=aarch64-build_apple-darwin23.6.0 --target=arm-zephyr-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://github.com/zephyrproject-rtos/sdk-ng/issues>.
Find the GDB manual and other documentation resources online at:
 <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Remote debugging using /dev/cu.usbmodem81D759AC1
(gdb) monitor swdp_scan
Target voltage: 3.3V
Available Targets:
No. Att Driver
 1 STM32WL3 M0+
(gdb) attach 1
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x10043d84 in ?? ()
(gdb) monitor erase_mass
Erasing device Flash: done
(gdb) file LCSC_BasicDemo.elf
Reading symbols from LCSC_BasicDemo.elf...
(gdb) load
Loading section .intvec, size 0xc0 lma 0x10040000
Loading section .text, size 0x6e90 lma 0x100400c0
Loading section .init, size 0x4 lma 0x10046f50
Loading section .fini, size 0x4 lma 0x10046f54
Loading section .ARM.exidx, size 0x8 lma 0x10046f58
Loading section .data, size 0x88 lma 0x10046f60
Start address 0x1004259c, load size 28648
Transfer rate: 3 KB/sec, 818 bytes/write.
(gdb) run
Starting program: LCSC_BasicDemo.elf 

Closing issues

For the STM32WL3x, stm32wb0.c is the best place because: - Both are single-core Cortex-M0+ wireless MCUs - Both share the same flash controller at 0x40001000 with identical register layout and command codes (0x11/0x22/0x33/0xBB) - Same flash size formula: ((SIZE[15:0] + 1) << 2) - Same erase granularity (2KB sectors) - Both have the same write-then-poll pattern - avoid creating specific target and increase flash size <!-- Filling this template is mandatory --> ## Detailed description This PR add ability to use STM32WL3x targets <!-- Explain the **details** for making this change. * Is a new feature implemented? * What existing problem(s) does the pull request solve? * How does the pull request solve these problems? Please provide enough information so that others can review your pull request. Information embedded in the description part of the commits doesn't count. --> ## 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)) * [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 Here below output of testing running demo ``` charles@office:debug$ arm-zephyr-eabi-gdb-py -ex 'set confirm off' -ex 'target extended-remote /dev/cu.usbmodem81D759AC1' GNU gdb (Zephyr SDK 0.17.4) 12.1 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-build_apple-darwin23.6.0 --target=arm-zephyr-eabi". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://github.com/zephyrproject-rtos/sdk-ng/issues>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word". Remote debugging using /dev/cu.usbmodem81D759AC1 (gdb) monitor swdp_scan Target voltage: 3.3V Available Targets: No. Att Driver 1 STM32WL3 M0+ (gdb) attach 1 Attaching to Remote target warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x10043d84 in ?? () (gdb) monitor erase_mass Erasing device Flash: done (gdb) file LCSC_BasicDemo.elf Reading symbols from LCSC_BasicDemo.elf... (gdb) load Loading section .intvec, size 0xc0 lma 0x10040000 Loading section .text, size 0x6e90 lma 0x100400c0 Loading section .init, size 0x4 lma 0x10046f50 Loading section .fini, size 0x4 lma 0x10046f54 Loading section .ARM.exidx, size 0x8 lma 0x10046f58 Loading section .data, size 0x88 lma 0x10046f60 Start address 0x1004259c, load size 28648 Transfer rate: 3 KB/sec, 818 bytes/write. (gdb) run Starting program: LCSC_BasicDemo.elf ``` ## Closing issues <!-- put "fixes #XXXX" here to auto-close the issue(s) that your PR fixes (if any). -->
dragonmux left a comment
Copy link

This looks interesting but needs some clean-up - see the notes below.

It feels like you used an LLM to help you write some of these comments and changes, and that troubles us - some of the changes over-explain using datasheet nomenclature we were intentionally avoiding, while in other places comments get removed that were placed to show intent. Please don't use "AI" tooling to help with PRs to this repo, they don't help and just make more work for you and us. Consider this a warning about the use of such tools and please review the contribution guidelines accordingly.

This looks interesting but needs some clean-up - see the notes below. It feels like you used an LLM to help you write some of these comments and changes, and that troubles us - some of the changes over-explain using datasheet nomenclature we were intentionally avoiding, while in other places comments get removed that were placed to show intent. Please don't use "AI" tooling to help with PRs to this repo, they don't help and just make more work for you and us. Consider this a warning about the use of such tools and please review the contribution guidelines accordingly.
@ -169,2 +217,3 @@
target_mem32_write32(target, status_reg, target_mem32_read32(target, status_reg));
/* Wake the flash controller from sleep mode */
target_mem32_write32(target, STM32WB0_FLASH_COMMAND, STM32WB0_FLASH_COMMAND_WAKEUP);
/* Wait for the wakeup command to execute */

Why is this comment getting removed? Please don't remove it.

Why is this comment getting removed? Please don't remove it.
@ -133,4 +155,4 @@
target->mass_erase = stm32wb0_mass_erase;
target->enter_flash_mode = stm32wb0_enter_flash_mode;
const uint32_t signature = target_mem32_read32(target, STM32WB0_FLASH_FLASH_SIZE);

This read cannot be done reliably before the DEEPSTOP2 write - this is why things were ordered how they were. Otherwise there's a good chance that the WDT kills the target before we can read the Flash size information out.

This read cannot be done reliably before the DEEPSTOP2 write - this is why things were ordered how they were. Otherwise there's a good chance that the WDT kills the target before we can read the Flash size information out.
@ -96,3 +122,3 @@
flash->length = length;
flash->blocksize = STM32WB0_FLASH_SECTOR_SIZE;
flash->writesize = STM32WB0_FLASH_PAGE_SIZE;
flash->writesize = writesize;

We know the struct member is called writesize, but because of how it is used in context, we think the parameter is better called page_size.

We know the struct member is called `writesize`, but because of how it is used in context, we think the parameter is better called `page_size`.
@ -143,1 +185,4 @@
{
/* WL3x polls the raw interrupt status; WB0x polls the masked status register */
const uint32_t status_reg =
(target->part_id == ID_STM32WL3) ? STM32WL3_FLASH_IRQRAW : STM32WB0_FLASH_STATUS;

The parens here are not required - == binds tighter than ? binds tighter than =, thus the order of operations is already guaranteed by C by writing const uint32_t status_reg = target->part_id == ID_STM32WL3 ? STM32WL3_FLASH_IRQRAW : STM32WB0_FLASH_STATUS;

The parens here are not required - `==` binds tighter than `?` binds tighter than `=`, thus the order of operations is already guaranteed by C by writing `const uint32_t status_reg = target->part_id == ID_STM32WL3 ? STM32WL3_FLASH_IRQRAW : STM32WB0_FLASH_STATUS;`
@ -179,3 +228,2 @@
/*
* Take address bits [17:2] and put them in the controller address register as the start
* of the sector we want erased, the instruct the controller to start the erase
* Compute the word address relative to the flash bank base and write it to the

Ditto for this use of "word", which we expressly tried to avoid using when writing the original comment because it's so utterly meaningless without addition context.

Ditto for this use of "word", which we expressly tried to avoid using when writing the original comment because it's so utterly meaningless without addition context.
@ -193,3 +242,2 @@
/* Start by telling the controller the first address we want to program */
target_mem32_write32(target, STM32WB0_FLASH_ADDRESS, (dest - STM32WB0_FLASH_BANK_BASE) >> 2U);
/* Start by telling the controller the first word address to program */

"word" here doesn't mean anything useful, please don't use the term. Is that 16-bit, 32-bit, etc? it's not even clear from ST's own literature as it depends on the part and the Flash configuration.. that is exactly why we stay away from that terminology. (STM32U5 runs a 128-bit Flash "word" size for example)

Please prefer u32 or whatever suitable type, if not just saying something like "32-bit block".

"word" here doesn't mean anything useful, please don't use the term. Is that 16-bit, 32-bit, etc? it's not even clear from ST's own literature as it depends on the part and the Flash configuration.. that is exactly why we stay away from that terminology. (STM32U5 runs a 128-bit Flash "word" size for example) Please prefer `u32` or whatever suitable type, if not just saying something like "32-bit block".
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin hallard/feature_stm32wl3:hallard/feature_stm32wl3
git switch hallard/feature_stm32wl3
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!2198
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "hallard/feature_stm32wl3"

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?