Skip to main content

Example Scripts

Bundled with MultiProg under scripts/examples/:

ScriptWhat it does
hello.luaShow config and memory regions
bsh_pmm.luaRead model string from MCU buffer, export S19 with model name
read_and_verify.luaRead firmware and verify against target
batch_flash.luaFull programming cycle with timer
firmware_analysis.luaAnalyze firmware: ARM vectors, strings, CRC, flash usage
hex_patch.luaFind / replace, fill, checksums
mass_production.luaBatch flashing with serial numbers and CSV log
target_search.luaSearch targets in database by keyword
search_and_compare.luaMulti-pattern search + target comparison
create_target.luaCreate custom target with connection diagram
create_tgsn_target.luaCreate TGSN-specific target
renesas_nec_checksum.luaSUM-RL78 calculator (see Checksum scripts)
stm32_g0_g4_export_mot.luaExport STM32 G0 / G4 buffer to .mot for J-Link
stm32f7_option_bytes_stvp_convert.luaConvert STM32F7 Option Bytes ↔ STVP S19
extended_ops_smoke.luaSmoke test for extended write / erase ops
debug_test.luaDebugger demo: breakpoints, variable inspection

Learning Lua

Lua is a small, fast, easy-to-learn scripting language. If you want to learn or test Lua outside MultiProg:

Online (no install)

Local install (Windows)

  1. Download from https://github.com/rjpcomputing/luaforwindows (Lua for Windows — includes editor).
  2. Or install via Scoop: scoop install lua.
  3. Run lua54.exe in terminal for interactive mode.

Key differences from other languages

  • Arrays start at index 1 (not 0).
  • ~= for "not equal" (not !=).
  • .. for string concatenation (not +).
  • local keyword for local variables (without it, variables are global).
  • nil instead of null.
  • Tables are the only data structure (used as arrays, dictionaries, objects).
  • #table gives the length of an array-like table.
  • No semicolons needed.

Quick Lua cheatsheet

-- Variables
local x = 42
local name = "MultiProg"
local ok = true

-- Strings
local s = "Hello " .. "World" -- concatenation
local len = #s -- length
local sub = string.sub(s, 1, 5) -- "Hello"

-- Tables (arrays)
local arr = {10, 20, 30}
for i, v in ipairs(arr) do print(i, v) end

-- Tables (dictionaries)
local cfg = {target = "STM32", power = "3v3"}
print(cfg.target)

-- Functions
local function add(a, b) return a + b end

-- If / else
if x > 10 then
print("big")
elseif x > 0 then
print("small")
else
print("zero or negative")
end

-- For loop
for i = 1, 10 do print(i) end

-- While
while x > 0 do x = x - 1 end

-- Multiple return values
local ok, err = mp.backend.connect()

-- String formatting
local s = string.format("Value: 0x%04X (%d bytes)", 0xFF, 16)