Skip to main content

BSH PMM: read model & export

A practical scenario: you have a board with an R5F2136CA MCU, you've read the firmware, and now you want to save it as an S19 file named after the model string stored in flash.

Setup​

  1. Select target R5F2136CA (R8C/36A) in MultiProg.
  2. Connect to the board and click Read to read the firmware into the buffer.
  3. Open Script Console, select bsh_pmm from Examples, click Run.

What the script does​

  1. Checks that the selected target is supported (currently R5F2136CA).
  2. Scans all memory regions to find the one containing address 0xF650.
  3. Reads 13 bytes at 0xF650 — this is where the model string is stored (e.g. SKS40E02RU/05).
  4. Verifies the bytes are printable ASCII.
  5. Replaces / with _ in the model name (for a valid filename).
  6. Opens a Save dialog with a suggested filename: SKS40E02RU_05_R5F2136CA.s19.
  7. Exports the Flash region as Motorola S19.

Key API functions used​

-- Get selected target name
local cfg = mp.config.get() -- cfg.target = "R5F2136CA (R8C/36A)"

-- Find region containing our address
local info = mp.memory.get_region_info("Flash") -- {start_address=0x4000, size=...}

-- Read 13 bytes at absolute MCU address 0xF650
local bytes = mp.memory.read_at("Flash", 0xF650, 13)

-- Convert to string, check ASCII
local model = mp.utils.bytes_to_string(bytes) -- "SKS40E02RU/05"
local ok = mp.utils.is_ascii(bytes) -- true

-- Save dialog with suggested filename
local path = mp.ui.save_file_dialog("Export", "SKS40E02RU_05_R5F2136CA.s19", "Motorola S19 (*.s19)")

-- Export region to file
mp.memory.export_region("Flash", path)

To add support for another MCU, add an entry to the SUPPORTED table in the script with the target name, model address, byte length, and short name.