What is I2C SPI custom script programming in REVELPROG-IS?
Custom script programming for I2C or SPI bus in case of REVELPROG is a some kind of "bus pirate" tool for serial communication. This tool is still in developement phase but it is already powerful and functional. With REVELPROG-IS Customs Script tool there is possibility to execute any commands in any sequence with precise delays on SPI or I2C bus. You can write script to execute commands for unclocking device, read and write hidden (or not) registers, change sector protection bits, write OTP registers and much more.
In practice it is also very useful tool for electronic enginners and embedded programmers, because there is possibility to communicate with any serial (I2C or SPI) device. External device or module can be also powered from REVELPROG-IS (1.0 - 5.0V with 0.1V threshold). Only few connection lines are required for communication (4 wires for SPI or 2 wires for I2C + optional 2 wires for external device power supply).
Script construction
Typical script consists of:
- script header - information about software version,
- hardware settings - voltage selection (VPP), bus selection (I2C/SPI) and communication speed,
- operations (1 to n).
Each operation constists of:
- operation parameters: number of bytes to read/write, delay settings,
- instruction- sequence of bytes for single instruction,
- data to write (optional) - sequence of optional bytes for write after single instruction
Each script has to have at least one operation defined
Example construction of typical script with header (software version v.1.6.0), hardware settings (SPI bus, 3.3V voltage, slowest speed) and single operation with 1-byte 9Fh command.
Code: Select all
// example script construction
#SCRIPT HEADER;
SCRIPT:v1.6.0;
#HARDWARE SETTINGS;
HW:SPI,3.3V,SLOW;
#OPERATION;
SW:0,0,1,3,5,5,10,0,100,1000;
INSTR:9F;
Script syntax:
- hash character "#" defines sections, e.g. #SCRIPT HEADER; (header), #HARDWARE SETTINGS; (hardware settings), #OPERATION; (for each operation),
- semicolon ";" placed at the end of each command,
- colon ":" placed directly after command words, e.g. SCRIPT: (script version), HW: (hardware settings), SW: (software settings - operation parameters), INSTR: (instruction), DATA: (write data);
- comma "," separates parameters for each command (eg. between "INSTR:" and ";" comma separates instruction bytes)
- double slash "//" precedes comments which are ignored by script executor
Script maker
Script maker will help you prepare multiple operations with correct syntax.
Software settings for single instruction:
- WREN (Write Enable) + number of bytes to write in single operation,
- RDEN (Read Enable) + number of bytes to read in single operation,
- DBO (Delay Before Operation) - optional delay in miliseconds before operation,
- DAI (Delay After Instruction) - optional delay in miliseconds after instruction,
- DAW (Delay After Write) - optional delay in miliseconds after write,
- DAO (Delay After Operation) - optional delay in miliseconds after operation,
- BSYO (Busy Operation) - maximum time in miliseconds for write end (e.g. maximum wait time for busy flag in FLASH SPI or for ACK in I2C devices)
- TOUT (Timeout) - maximum PC timeout in miliseconds for operation end (it is recommended to set timeout greater than sum of all other delays).
Operation code generated by script maker from above example::
Code: Select all
#OPERATION;
SW:0,0,1,3,5,5,10,0,100,500;
INSTR:9F;
As you can see SW parameters are equal to script maker parameters:
Code: Select all
SW:WREN[0-1], WriteLength[0-255], RDEN[0-1], ReadLength[0-255], DBO[0-250], DAI[0-250], DAW[0-250], DAO[0-250], BSYO[0-n], TOUT[0-n];
Please note that:
- read and write length are 0 based (0 means 1 byte, 255 means 256 bytes)
- with WREN = 0 writelength is ignored, with RDEN = 0 readlength is ignored.
- "SW:" and "HW:" byte format is decimal
- "INSTR:" and "DATA:" byte format is hexadecimal
edit: please check scriptmaker changes since v1.8.5 (possibility to repeat operations and import data from buffer):
viewtopic.php?f=32&t=280&p=3657#p3657
Script execution sequence
1. SET HW (BUS, VPP, SPEED)
2. EXECUTE OPERATION 1 (SET SW -> DBO -> INSTR -> DAI -> WRITE -> DAW -> BSYO -> READ -> DAO)
3. EXECUTE OPERATION 2
4. ...
5. EXECUTE OPERATION N
6. RESET HARDWARE
Remarks
Script execution is not immune for syntax error at the moment - you should check syntax carefuly before execution because you may be not informed about execution errors and program may be unstable. Please remember about all syntax elements
In next posts I'll show few script examples.