Skip to main content

v2n-gd32-swd-flash

Host-driven SWD bit-bang to the on-module GD32G553 over three GPIOs (SWDIO + SWCLK + NRST, all required). Attaches from the Renesas RZ/V2N host, reads SW-DP IDCODE, halts the Cortex-M33, erases a flash sector, writes + verifies a scratch pattern, and releases the core.

This is the recovery / first-flash path for the on-module bridge — works even when the application-bootloader OTA path is unreachable (corrupt bridge image, factory first-flash, dev-board bring-up). No external probe required.

Three ways to flash the bridge​

PathToolingWhen
External SWD probeSEGGER J-Link directly (-device GD32G553MEY7TR, requires J-Link software ≥ V9.46); OpenOCD / pyOCD fallbacks for CMSIS-DAP / ST-Link. Not reachable through a plain tan flash — see below.Bricked-device recovery on the bench. Alp Lab programs the part in production with its own tooling.
OTA Path-A (over the bridge itself)OTA_BEGIN → OTA_WRITE_CHUNK → OTA_VERIFY (SHA-256) → OTA_COMMIT, A/B slots with rollbackIn-field firmware update of a working bridge — the normal path, declared as update_channel: alp_ota_spi_bridge.
Host SWD bit-bang (this example)Three Renesas GPIOs, no probeRecovery when the bridge image is corrupt and no probe is attached. Unaffected by the tan change below.

Source: examples/v2n/v2n-gd32-swd-flash/.

tan flash no longer programs the GD32 bridge​

Corrects an earlier version of this page

This page previously presented the external-probe swd_probe backend driven by tan flash as "the primary path". That is no longer true. The six E1M-X gd32_bridge helper entries (E1M-V2N101, E1M-V2N102, E1M-V2N103, E1M-V2M101, E1M-V2M102, E1M-V2M103) declare no local flash path at all any more: flash_method: swd_probe and its flash_args were removed outright. GD32 programming is out of tan's scope. update_channel: alp_ota_spi_bridge is retained.

The J-Link / SWD flow itself still exists — it is the physical recovery path, and the host bit-bang route this example demonstrates is untouched. What changed is that neither is reachable through a plain tan flash.

Every gd32_bridge entry is flash_policy: recovery_only: Alp Lab programs the part in production, and a customer flash is only ever bricked-device recovery with Alp Lab-supplied binaries. tan flash checks that policy ahead of any flash_method presence and declines the entry with status skipped and rc -1:

flash: helper 'gd32_bridge' is programmed by Alp Lab in production and is customer-flashable only to recover a bricked device...; skipping. Field updates arrive over update_channel: alp_ota_spi_bridge. To recover a bricked device deliberately, re-run with --helper gd32_bridge --recover.

To take the recovery path deliberately, pass --helper gd32_bridge --recover. Note also that no prebuilt bridge binary ships in the repo — build it yourself from the separate alplabai/gd32-bridge-firmware repository (the firmware tree moved out of alp-sdk in v0.17.0), or wait for an Alp Lab firmware release.

flash_policy is a required key on every helper_firmware[] entry now (som-preset-v2.schema.json, helper_firmware_entry.required = ["name","chip","flash_policy"]). Its values are customer / factory / recovery_only, with no absent-means-customer default. flash_policy, flash_method and update_channel are three independent axes — the old mutual exclusion between flash_method and update_channel was deleted.

What it shows​

  1. gd32_swd_init(&swd) takes no pin handles (changed in alp-sdk v0.17.0): the driver opens its own three pads through the platform glue, because the portable alp_gpio_open() refuses their reserved ids. It answers ALP_ERR_NOT_READY if the board does not publish the pads, and the example exits cleanly with a log message rather than wedging the host.
  2. gd32_swd_init asserts NRST first (an output with an initial LOW level, so the shared open-drain net is never driven high), then configures SWDIO + SWCLK as outputs at the SWD idle state. For the whole SWD session the supervisor closes the SPI bridge link and answers bridge commands with ALP_ERR_BUSY.
  3. gd32_swd_connect line-resets the link, performs the JTAG-to-SWD switch sequence, reads DPIDR, then arms halt-on-reset, releases NRST and confirms the core halted (connect-under-reset — no application code runs; on failure NRST is asserted again). It logs the IDCODE against GD32_SWD_GENERIC_CM33_R0P1_IDCODE (0x6BA02477) — informational only. Read the warning below before you act on that comparison.
  4. gd32_swd_halt puts the Cortex-M33 into debug-halt via DHCSR DBGKEY + C_HALT.
  5. gd32_swd_flash_erase erases the enclosing 2 KiB sector.
  6. gd32_swd_flash_write programs a 64-byte ramp pattern.
  7. gd32_swd_flash_verify reads it back via AHB-AP memory reads.
  8. gd32_swd_reset_and_run disarms halt-on-reset and releases the core via an NRST pulse — the only reset; recovery without NRST is not supported. gd32_swd_deinit then returns SWDIO/SWCLK to inputs and ends the session.

The generic IDCODE is UNVERIFIED on the GD32 — do not make a mismatch fatal​

Neither candidate IDCODE has been measured on a GD32

<alp/chips/gd32_swd.h>'s GD32_SWD_GENERIC_CM33_R0P1_IDCODE 0x6BA02477u (named GD32_SWD_EXPECTED_IDCODE before alp-sdk v0.17.0) is the generic ADIv5 SW-DP IDCODE for a Cortex-M33 r0p1 SW-DPv2. It comes from the core's generic expectation, not from a probe on a GD32G553. An earlier version of this page called it "the GD32G553's documented value" — it is not.

ValueWhat it is
0x6BA02477The generic Cortex-M33 r0p1 expectation — and, separately, the bench-measured SW-DP ID of the V2N CM33 DAP (a different target on the same board)
0x0BE12477The only other GD32 candidate on record, with no bench transcript or datasheet behind it

An earlier version of this page tabled 0x0BE12477 as the bench-measured GD32 value. That was not a measurement, and the SDK now says so. Whether a real GD32G553 answers either value is unknown, so a comparison against the macro proves nothing either way. gd32_swd_connect() deliberately does not treat a mismatch as fatal, and neither should your code. A production test that wants to refuse on a mismatch must compare against a value measured on its own board.

board.yaml​

som:
sku: E1M-V2N101

preset: e1m-x-evk

cores:
a55_cluster:
os: "off" # A55 cluster intentionally off — M33-SM is the SWD host
m33_sm:
# os: omitted → topology default (m33_sm → zephyr).
app: ./src
peripherals:
- gpio

chips:
- gd32_swd

diagnostics:
log_level: info

GD32 in-field reflash uses SWD-from-host, not factory-ISP / BOOT0. The earlier BOOT0 plan was dropped in favour of a software SWD bit-bang from the Renesas host — SWD works regardless of GD32 firmware state, where factory-ISP would depend on the GD32 boot ROM staying intact.

The GD32_SWDIO / GD32_SWCLK / GD32_NRST link is entirely module-internal: it runs between the Renesas host and the GD32 supervisor inside the SoM, and no part of it is exposed on the E1M-X edge connector. The pad assignments behind it are not part of the customer contract and are not published — they can change across a hardware revision without breaking form-fit-function compatibility. Drive the link through the SDK (<alp/chips/gd32_swd.h>, or tan flash --helper gd32_bridge --recover), never against a pad number.

warning
GD32_NRST shares the primary PMIC reset net

The one consequence that reaches an integrator: the reset line is shared with the primary PMIC reset out, so it is driven open-drain — pulled low to assert reset, released to HiZ, with an external pull-up returning it to the released state. A driver that pushes it high actively fights the PMIC. The SDK's gd32_swd backend already does this correctly; anything re-implementing the sequence must too.

See also​

Questions about this page? Email contact@alplab.ai