{{pfw:banner.png}} ====== PIO (dis)assembler for RP2040 ====== ===== The idea: ===== ''PIO'' stand for **P**rogrammable **I**nput **O**utput. These are programmable state machines with a small shared program memory. Programs are built with only eight instructions. The behavior of those instructions can be modified with registers. We define a (standalone) ''PIO'' forth style (dis)assembler for the RP2040. It can be used for writing direct executable programs and exportable HEX programs. These HEX programs can be used in conjunction with the mini-PIO control program. {{ :pfw:one_pio_sm.jpg?500 |One PIO state machine}} ===== Implementation ===== The example code asumes a 32-bit machine that has 32-bit compile actions. It is also asumed that the code runs in RAM as noForth T on the RP2040 does. All PIO fuctionality can be used, and a PIO-module ''%%EXPORT%%'' function is provided. The PIO-assembler is (de)activated by the words ''%%{PIO%%'' and ''%%PIO}%%''. Missing words in Generic Forth are: +TO ( n "name" -- ) - Add n to the contents of the value "name" VOCABULARY ( "name" -- ) - Define a named wordlist ==== The structure of PIO opcodes ==== Pink = Opcode field Yellow = Delay and/or side set field Green = Destination field Blue = Data field {{pfw:set_jpg.jpg}} ==== All PIO instructions ==== ✦ PIO opcodes in, out, push, pull, mov, wait, irq, set, nop, pio, ✦ Optional arguments for each opcode [] side ✦ Conditionals x0<>? x--? y0<>? y--? x=y? pin? osre? ✦ Control structures if, else, then, begin, while, repeat, again, until, ✦ Labels one two one> two> ✦ PIO directives clean-pio =pio sm sync restart =org =set-pins =out-pins =side-pins opt =in-pin =jmp-pin =inputs =strength side-pindirs wrap-target wrap =steal =autopush =autopull =in-dir =out-dir clone =exec =clock-div =freq export ✦ PIO external tools (mini-PIO.f) tx-depth rx-depth >txf rxf> set-pio sm-on exec freq clock-div sync restart ✦ PIO disassembler & state machine data mpsee psee .fifo .sm ==== Usage example ==== An extra RS232 output driver in only 5 instructions! decimal : =BAUD ( b -- ) 8 * =freq ; \ Set baudrate for UART clean-pio \ Empty code space, start at zero 0 0 {pio \ Use state machine-0 on PIO-0 115200 =baud \ 115k2 26 1 =side-pins opt \ GPIO 26 for optional SIDE 26 1 =out-pins \ GPIO 26 for OUT & SET 26 1 =set-pins 1 pindirs set, \ Pin is output! wrap-target 7 [] 1 side pull, \ Stop bit, get data byte 7 [] 0 side 7 x set, \ Start bit begin, 1 pins out, \ Shift 8 bits out 6 [] x--? until, \ Until 8 bits are done wrap 0 =exec \ Start SM-0 code at address 0 pio} ==== UART control code ==== : PEMIT ( ch -- ) begin 0 tx-depth 3 < until 0 >txf ; : PTYPE ( a u -- ) 0 ?do count pemit loop drop ; : ABC ( -- ) s" ABC " ptype ; {{pfw:pio_uart.jpg}} | File name | Purpose | in Dropbox (external link) | | [[https://www.dropbox.com/s/edo8rk339awuerz/PIO%20assembler%20docs.pdf?dl=1|PIO-assembler docs.pdf]] | Documentation | [[https://www.dropbox.com/s/edo8rk339awuerz/PIO%20assembler%20docs.pdf?dl=0|PIO-assembler documentation]] | | [[https://www.dropbox.com/s/l39qwo088l6i8sm/PIO%20assembler%20overview.pdf?dl=1|PIO assembler overview.pdf]] | Documentation | [[https://www.dropbox.com/s/l39qwo088l6i8sm/PIO%20assembler%20overview.pdf?dl=0|PIO-assembler overview]] | | [[https://www.dropbox.com/s/65e148ce9lckt0j/PIO-assembler%20uni.f?dl=0| PIO-assembler uni.f]] | PIO-assembler | [[https://www.dropbox.com/s/boi1znyduiegdlu/PIO-assembler.f?dl=0|noForth PIO assembler]] | | [[https://www.dropbox.com/s/3kvf637vuy4ymhd/PIO-disassembler%20uni.f?dl=0| PIO-disassembler uni.f]] | PIO-disassembler | [[https://www.dropbox.com/s/rhilv9gr6b6vsx9/PIO-disassembler.f?dl=0|noForth PIO disassembler]] | | [[https://www.dropbox.com/s/gzfccww59e8ms6z/mini-PIO%20uni.f?dl=0|Mini-PIO uni.f]] | mini-PIO tool set | [[https://www.dropbox.com/s/lw638dy1udsz83h/mini-PIO.f?dl=0|noForth minimal PIO controller]] | [[en:pfw:welcome|Back to PFW page]] ==== Contributions ====

Alternative Implementations

[[en:pfw:welcome|Back to PFW page]]