Flashing the P2 using SWD with custom application


I am developing an application which uses a P2 module. The board only has an SWD interface, not a USB header so DFU updates are not possible.

I have read the documentation linked here: https://docs.particle.io/reference/developer-tools/jtag/ and I believe that the process is:

  1. Write custom application;
  2. Generate a firmware.bin file containing the custom application;
  3. Use the hex file generator (https://docs.particle.io/tools/developer-tools/hex-generator/) which will append the custom application to the required firmware components and generate an Intel Hex file at the correct location, i.e take the following *.bin files and make a monolithic hex file:

system-part1.bin loaded at address 0x60000
bootloader.bin loaded at address 0x4000
prebootloader-part1.bin loaded at address 0x14000
custom_firmware.bin loaded at address ????

This hex file can then be flashed to the P2 module.

The documentation https://docs.particle.io/reference/developer-tools/jtag/ which says:

At this point, the device will reboot, but the user firmware binary (tinker) has not been flashed. Since the address varies, it's often easier to flash this using USB in DFU mode:

particle usb dfu
particle flash --usb p2/tinker.bin

As I described, the board I am developing on does not have a USB header, I can only program it using SWD. So once I have a hex file containing absolute addresses, how do I flash that to the P2 module?
I have spent a bit of time investigating the options and have successfully loaded the *.bin files described above, I just don't know of the appropriate OpenOCD command for the RTL872x. The nRF family have a few examples, but not the Realtek part used in the P2.

I have tried the following command after appending my firmware file using the Hex generator:

bash-5.0$ bin/openocd -s share/openocd/scripts/ -f interface/cmsis-dap.cfg -f target/rtl872x_km4_debug.cfg -c "init" -c "flash write_image /home/foo/development/photon_workbench/test_project/ParticleTest/image.hex" -c "reset" -c "exit"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2022-03-25-17:31)
Licensed under GNU GPL v2
For bug reports, read
Info : CMSIS-DAP: SWD  supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: FW Version = 0254
Info : CMSIS-DAP: Serial# = 070000814a46be801431313030313736a5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x6ba02477
Info : [rtl872x.cpu] Cortex-M55 r1p0 processor detected
Info : [rtl872x.cpu] target has 2 breakpoints, 1 watchpoints
Info : starting gdb server for rtl872x.cpu on 3333
Info : Listening on port 3333 for gdb connections
  flash bank bank_id driver_name base_address size_bytes chip_width_bytes
            bus_width_bytes target [driver_options ...]
  flash banks
  flash init
  flash list
gdb_flash_program ('enable'|'disable')
program <filename> [address] [pre-verify] [verify] [reset] [exit]

This looks like the arguments passed to the OpenOCD flash image_write command are missing.
Does this mean I need to extend the target/rtl872x_km4_debug.cfg file?

Thank you for any help you can offer.

You need to use the special flashing following the instructions here.

However you should also read the thread below which explains how to get the firmware start address for the user firmware if you want to flash that manually.

I did find that posting after I asked the question. I have now successfully flashed the new application and it runs. Is it maybe worth adding this snippet to the documentation for P2 development?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.