Example Scripts
Bundled with MultiProg under scripts/examples/:
| Script | What it does |
|---|---|
hello.lua | Show config and memory regions |
bsh_pmm.lua | Read model string from MCU buffer, export S19 with model name |
read_and_verify.lua | Read firmware and verify against target |
batch_flash.lua | Full programming cycle with timer |
firmware_analysis.lua | Analyze firmware: ARM vectors, strings, CRC, flash usage |
hex_patch.lua | Find / replace, fill, checksums |
mass_production.lua | Batch flashing with serial numbers and CSV log |
target_search.lua | Search targets in database by keyword |
search_and_compare.lua | Multi-pattern search + target comparison |
create_target.lua | Create custom target with connection diagram |
create_tgsn_target.lua | Create TGSN-specific target |
renesas_nec_checksum.lua | SUM-RL78 calculator (see Checksum scripts) |
stm32_g0_g4_export_mot.lua | Export STM32 G0 / G4 buffer to .mot for J-Link |
stm32f7_option_bytes_stvp_convert.lua | Convert STM32F7 Option Bytes ↔ STVP S19 |
extended_ops_smoke.lua | Smoke test for extended write / erase ops |
debug_test.lua | Debugger 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)
- Try Lua in browser: https://www.lua.org/demo.html
- Lua tutorial: https://www.lua.org/pil/contents.html (Programming in Lua, free online edition)
Local install (Windows)
- Download from https://github.com/rjpcomputing/luaforwindows (Lua for Windows — includes editor).
- Or install via Scoop:
scoop install lua. - Run
lua54.exein terminal for interactive mode.
Key differences from other languages
- Arrays start at index 1 (not 0).
~=for "not equal" (not!=)...for string concatenation (not+).localkeyword for local variables (without it, variables are global).nilinstead ofnull.- Tables are the only data structure (used as arrays, dictionaries, objects).
#tablegives 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)