Detailed description
Background
Thanks to the BMP mainline's debugging support for riscv32, HPMicro chips can now be debugged without any modifications. HPMicro is a Chinese company that uses Andes D45 or D25 cores in its products, which comply with the RISC-V Debug Specification version 0.13. As a result, BMP works with these chips out of the box.
However, BMP currently lacks support for Flash programming on these chips. To address this, I have added Flash support for four HPMicro chip families based on the open-source implementations from OpenOCD and the HPM SDK:
- HPM53xx
- HPM67xx
- HPM68xx
- HPM6Pxx
Technical Details
All HPMicro chips use external Flash. The vendor provides a unified ROM API that enables convenient Flash erase and write operations.
One thing to note is that users may have different pin assignments and XPI controller instance configurations. Therefore, I extended the xpi_cfg command to allow users to customize the Flash configuration before programming.
The detailed implementation can be found in src/target/hpm_xpi.c
The implementation of this part references the official OpenOCD download algorithm support provided by HPMicro:
https://github.com/hpmicro/hpm_sdk/tree/main/samples/openocd_algo
BMDA(stlink_v2) Test
blackmagic ^_^ >:./build/blackmagic -tj
Black Magic Debug App v2.0.0-479-g8dfdd8f3-dirty
for Black Magic Probe, ST-Link v2 and v3, CMSIS-DAP, J-Link, FTDI (MPSSE) and WCH-Link
Using 1d50:6018 DFD496DE Black Magic Debug
Black Magic Probe (ST-Link/v2) v2.0.0-479-g8dfdd8f3-dirty
Running in Test Mode
Target voltage: 3.31V
Speed set to 6.000MHz for JTAG
Resetting TAP
Change state to Shift-DR
Scanning out ID codes
Return to Run-Test/Idle
Change state to Shift-IR
Scanning out IRs
Return to Run-Test/Idle
Change state to Shift-DR
Return to Run-Test/Idle
ID code 0x1000563d: Andes Tech RISC-V DTM.
RISC-V debug v0.13/v1.0 DMI
RISC-V debug v0.13 DM
Hart has 4 data registers and 8 progbuf registers
Attempting 128-bit read on misa
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
Attempting 64-bit read on misa
CSR access failed: 3
CSR access failed: 3
CSR access failed: 3
Attempting 32-bit read on misa
Hart 0: 32-bit RISC-V (arch = 80000025), rv32igcb ISA (exts = 0090112f), vendor = 61e, impl = 410
Hart has 8 trigger slots available
-> riscv32_probe
*** 1 HPM53xx rv32igcb
RAM Start: 0x00000000 length = 0x40000
RAM Start: 0x00080000 length = 0x40000
RAM Start: 0xf0400000 length = 0x8000
Flash Start: 0x80000000 length = 0xfff0000 blocksize 0x1000
BMF(stlink_v2) Test
hello_world ^_^ >:gdb-multiarch -nx build/output/demo.elf -ex "tar ext /dev/ttyACM0" -ex "mon j" -ex "att 1" -ex "load"
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 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 "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
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"...
Reading symbols from build/output/demo.elf...
Remote debugging using /dev/ttyACM0
Target voltage: 3.32V
Available Targets:
No. Att Driver
1 HPM53xx rv32igcb
Attaching to program: /home/firefly/Documents/Code/hpm_workspace/hello_world/build/output/demo.elf, Remote target
0x20017a50 in ?? ()
Loading section .nor_cfg_option, size 0x10 lma 0x80000400
Loading section .boot_header, size 0x90 lma 0x80001000
Loading section .start, size 0x48 lma 0x80003000
Loading section .vectors, size 0x360 lma 0x80003048
Loading section .text, size 0xb4d8 lma 0x800033a8
Loading section .eh_frame, size 0x28 lma 0x8000e880
Loading section .data, size 0x1c8 lma 0x8000e8a8
Start address 0x80003000, load size 47888
Transfer rate: 10 KB/sec, 886 bytes/write
Your checklist for this pull request
Closing issues
<!-- Filling this template is mandatory -->
## Detailed description
### Background
Thanks to the BMP mainline's debugging support for riscv32, HPMicro chips can now be debugged without any modifications. HPMicro is a Chinese company that uses Andes D45 or D25 cores in its products, which comply with the **RISC-V Debug Specification version 0.13**. As a result, BMP works with these chips out of the box.
However, BMP currently lacks support for Flash programming on these chips. To address this, I have added Flash support for four HPMicro chip families based on the open-source implementations from OpenOCD and the HPM SDK:
- HPM53xx
- HPM67xx
- HPM68xx
- HPM6Pxx
### Technical Details
All HPMicro chips use external Flash. The vendor provides a unified **ROM API** that enables convenient Flash erase and write operations.
One thing to note is that users may have different pin assignments and XPI controller instance configurations. Therefore, I extended the `xpi_cfg` command to allow users to customize the Flash configuration before programming.
The detailed implementation can be found in `src/target/hpm_xpi.c`
The implementation of this part references the official OpenOCD download algorithm support provided by HPMicro:
[https://github.com/hpmicro/hpm_sdk/tree/main/samples/openocd_algo](https://github.com/hpmicro/hpm_sdk/tree/main/samples/openocd_algo)
### BMDA(stlink_v2) Test
```bash
blackmagic ^_^ >:./build/blackmagic -tj
Black Magic Debug App v2.0.0-479-g8dfdd8f3-dirty
for Black Magic Probe, ST-Link v2 and v3, CMSIS-DAP, J-Link, FTDI (MPSSE) and WCH-Link
Using 1d50:6018 DFD496DE Black Magic Debug
Black Magic Probe (ST-Link/v2) v2.0.0-479-g8dfdd8f3-dirty
Running in Test Mode
Target voltage: 3.31V
Speed set to 6.000MHz for JTAG
Resetting TAP
Change state to Shift-DR
Scanning out ID codes
Return to Run-Test/Idle
Change state to Shift-IR
Scanning out IRs
Return to Run-Test/Idle
Change state to Shift-DR
Return to Run-Test/Idle
ID code 0x1000563d: Andes Tech RISC-V DTM.
RISC-V debug v0.13/v1.0 DMI
RISC-V debug v0.13 DM
Hart has 4 data registers and 8 progbuf registers
Attempting 128-bit read on misa
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
Attempting 64-bit read on misa
CSR access failed: 3
CSR access failed: 3
CSR access failed: 3
Attempting 32-bit read on misa
Hart 0: 32-bit RISC-V (arch = 80000025), rv32igcb ISA (exts = 0090112f), vendor = 61e, impl = 410
Hart has 8 trigger slots available
-> riscv32_probe
*** 1 HPM53xx rv32igcb
RAM Start: 0x00000000 length = 0x40000
RAM Start: 0x00080000 length = 0x40000
RAM Start: 0xf0400000 length = 0x8000
Flash Start: 0x80000000 length = 0xfff0000 blocksize 0x1000
```
### BMF(stlink_v2) Test
```bash
hello_world ^_^ >:gdb-multiarch -nx build/output/demo.elf -ex "tar ext /dev/ttyACM0" -ex "mon j" -ex "att 1" -ex "load"
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 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 "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
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"...
Reading symbols from build/output/demo.elf...
Remote debugging using /dev/ttyACM0
Target voltage: 3.32V
Available Targets:
No. Att Driver
1 HPM53xx rv32igcb
Attaching to program: /home/firefly/Documents/Code/hpm_workspace/hello_world/build/output/demo.elf, Remote target
0x20017a50 in ?? ()
Loading section .nor_cfg_option, size 0x10 lma 0x80000400
Loading section .boot_header, size 0x90 lma 0x80001000
Loading section .start, size 0x48 lma 0x80003000
Loading section .vectors, size 0x360 lma 0x80003048
Loading section .text, size 0xb4d8 lma 0x800033a8
Loading section .eh_frame, size 0x28 lma 0x8000e880
Loading section .data, size 0x1c8 lma 0x8000e8a8
Start address 0x80003000, load size 47888
Transfer rate: 10 KB/sec, 886 bytes/write
```
<!--
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://codeberg.org/blackmagic-debug/blackmagic/src/CODE_OF_CONDUCT.md)
* [x] I've read the [guidelines for contributing](https://codeberg.org/blackmagic-debug/blackmagic/src/CONTRIBUTING.md) to this repository
* [x] It builds for hardware native (see [Building the firmware](https://codeberg.org/blackmagic-debug/blackmagic?tab=readme-ov-file#building-the-firmware))
* [x] It builds as BMDA (see [Building the BMDA](https://codeberg.org/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
<!-- put "fixes #XXXX" here to auto-close the issue(s) that your PR fixes (if any). -->