From 3c0781b69e17902e0e676da61e68a553f42f7f72 Mon Sep 17 00:00:00 2001 From: NitiKaur Date: Wed, 7 Jul 2021 02:40:32 +0530 Subject: [PATCH 01/31] brief overwiew with explaination of each command --- docs/rp2/pio.rst | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 docs/rp2/pio.rst diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst new file mode 100644 index 0000000000000..c4af19f8dd117 --- /dev/null +++ b/docs/rp2/pio.rst @@ -0,0 +1,79 @@ +.. _rp2_pio: + +RP2040 has standard hardware support like I2C, SPI and UART for communication +protocols with standard devices. For devices where we do not have hardware +support for such protocols or where there is a requirement of more I/O +channels, PIO(Programmable Input Ouput) comes intp play. Also, typical +micropython devices make use of a technique called bit banging which is pins +are rapidly turned on and off to transmit data. This makes the entire process +very slow as the processor concentrates on bit banging rather than exceuting +any other process. However, PIO sllows it to carry on with the bit banging +process while the processor resources are used for executing some other work. + +Along with the two main cotex - MO+ processing cores, RP2040 has two PIO +blocks each of which has four state machines. These state machines take +process data in FIFO (FIrst-In-First-Out) format. When these state machines +are free, they will put in data from the queue and execute the instruction. +This way, the PIO state machines and the main process works simultaneously +without being much dependant on the other. + +Eaxh FIFO has four words (each of 32 bits) which can be linked to the DMA toin assemby +transmit larger amounts of data to the PIO state machine and allows it to +carry on execution without the main program keeping a track of it at each +instant of time. + +Each state machine has a set of instructions- which allow for a wide range of +behaviourial or location changes to the data. They are written in assembly +language which is later used in a MicroPython program to perform specific +tasks. These instructions are - + +jmp(cond, lebel=None) + condition : 0-7 + : 0-31 + target : instruction offset of label within the program + see sec 3.4.2 of RPi docs for details + +wait(polarity, src, index) + polarity: 0-1 + src: gpio, pin, irq + index: 0-31 + wait for high/low on pin 0-31 or irq 0-31 + see sec 3.4.3 of RPi docs for details + +in(src, data) + src : pin, X, Y, ISR, OSR(all 0-31) + data : bit count(0-31) + see sec 3.4.4 of RPi docs for details + +out(dist,data) + dist : pin, X, Y, PINDIRS, AC, ISR, OSR(all 0-31) + data : bit count(0-31) + see sec 3.4.5 of RPi docs for details + +push(value = 0, value = 2) + block = 0 : no block + block = 1 : block + see sec 3.4.6 of RPi docs for details + +pull(value = 0, value = 2) + pull(if empty) : 1 (default = 0) + block : 1 (default = 1) + no-block = 0 + see sec 3.4.7 of RPi docs for details + +mov(dist, src) + dist : pin, X, Y, ISR, OSR, PC (all 0-31) + src : pin, X, Y, ISR, OSR (all 0-31) + see sec 3.4.8 of RPi docs for details + +irq(mod, index = None) + index : IRQ (0-7) + see sec 3.4.9 of RPi docs for details + +self(dest, data) + dest : X, Y, PINS, PINDIRS + data : value (0-31) + see sec 3.4.10 of RPi docs for details + + + From d0a38b64d95e4c9d8a66703ee0cb67943e761800 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:14:35 +0530 Subject: [PATCH 02/31] changed self to set instruction --- docs/rp2/pio.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index c4af19f8dd117..415387137ffea 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -70,7 +70,7 @@ irq(mod, index = None) index : IRQ (0-7) see sec 3.4.9 of RPi docs for details -self(dest, data) +set(dest, data) dest : X, Y, PINS, PINDIRS data : value (0-31) see sec 3.4.10 of RPi docs for details From e49eafe9f4d9fb883efb2374e2d5c45f9f23a3bd Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:23:40 +0530 Subject: [PATCH 03/31] IRQ instruction updated as per review --- docs/rp2/pio.rst | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index 415387137ffea..5c3670c3634cf 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -66,14 +66,33 @@ mov(dist, src) src : pin, X, Y, ISR, OSR (all 0-31) see sec 3.4.8 of RPi docs for details -irq(mod, index = None) - index : IRQ (0-7) - see sec 3.4.9 of RPi docs for details - set(dest, data) dest : X, Y, PINS, PINDIRS data : value (0-31) see sec 3.4.10 of RPi docs for details +irq(mod, index = None) + These are the following forms of this instruction(index is an integer value + from 0-7) + * irq(index) + * irq(rel(index)) + * irq(block, index) + * irq(block, rel(index)) + * irq(clear, rel(index)) + * irq(block | clear, index) + * irq(block | clear, rel(index)) + + These can be summarised as two forms: + * form 1: irq(index) + * form 2: irq(mode,index) + where + * index can be an integer or rel(integer) + * mode can be: block or clear or block | clear + + Allowed IRQ numbers are 0-7 (0-3 are visible from to the processor, 4-7 are + internal to the state machines). + see sec 3.4.9 of RPi docs for details + + From 45b666a21bb2d61a2c46af3d71543205077636a0 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:26:16 +0530 Subject: [PATCH 04/31] all asm PIo instructions moved to new location(docs/library/rp2.rst ) (1) --- docs/rp2/pio.rst | 71 ------------------------------------------------ 1 file changed, 71 deletions(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index 5c3670c3634cf..70d1d972160e3 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -22,77 +22,6 @@ transmit larger amounts of data to the PIO state machine and allows it to carry on execution without the main program keeping a track of it at each instant of time. -Each state machine has a set of instructions- which allow for a wide range of -behaviourial or location changes to the data. They are written in assembly -language which is later used in a MicroPython program to perform specific -tasks. These instructions are - - -jmp(cond, lebel=None) - condition : 0-7 - : 0-31 - target : instruction offset of label within the program - see sec 3.4.2 of RPi docs for details - -wait(polarity, src, index) - polarity: 0-1 - src: gpio, pin, irq - index: 0-31 - wait for high/low on pin 0-31 or irq 0-31 - see sec 3.4.3 of RPi docs for details - -in(src, data) - src : pin, X, Y, ISR, OSR(all 0-31) - data : bit count(0-31) - see sec 3.4.4 of RPi docs for details - -out(dist,data) - dist : pin, X, Y, PINDIRS, AC, ISR, OSR(all 0-31) - data : bit count(0-31) - see sec 3.4.5 of RPi docs for details - -push(value = 0, value = 2) - block = 0 : no block - block = 1 : block - see sec 3.4.6 of RPi docs for details - -pull(value = 0, value = 2) - pull(if empty) : 1 (default = 0) - block : 1 (default = 1) - no-block = 0 - see sec 3.4.7 of RPi docs for details - -mov(dist, src) - dist : pin, X, Y, ISR, OSR, PC (all 0-31) - src : pin, X, Y, ISR, OSR (all 0-31) - see sec 3.4.8 of RPi docs for details - -set(dest, data) - dest : X, Y, PINS, PINDIRS - data : value (0-31) - see sec 3.4.10 of RPi docs for details - -irq(mod, index = None) - These are the following forms of this instruction(index is an integer value - from 0-7) - * irq(index) - * irq(rel(index)) - * irq(block, index) - * irq(block, rel(index)) - * irq(clear, rel(index)) - * irq(block | clear, index) - * irq(block | clear, rel(index)) - - These can be summarised as two forms: - * form 1: irq(index) - * form 2: irq(mode,index) - where - * index can be an integer or rel(integer) - * mode can be: block or clear or block | clear - - Allowed IRQ numbers are 0-7 (0-3 are visible from to the processor, 4-7 are - internal to the state machines). - see sec 3.4.9 of RPi docs for details - From 8b0e238668bf3f043938754f4cfbd5b7cdf410aa Mon Sep 17 00:00:00 2001 From: NitiKaur Date: Wed, 14 Jul 2021 01:30:15 +0530 Subject: [PATCH 05/31] asm PIO instructions moved to new location (2) --- docs/library/rp2.rst | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 5d168bce20262..e192f8b775a36 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -71,6 +71,79 @@ For running PIO programs, see :class:`rp2.StateMachine`. This exception is raised from `asm_pio()` or `asm_pio_encode()` if there is an error assembling a PIO program. +Each state machine has a set of instructions- which allow for a wide range of +behaviourial or location changes to the data. They are written in assembly +language which is later used in a MicroPython program to perform specific +tasks. These instructions are - + +jmp(cond, lebel=None) + condition : 0-7 + : 0-31 + target : instruction offset of label within the program + see sec 3.4.2 of RPi docs for details + +wait(polarity, src, index) + polarity: 0-1 + src: gpio, pin, irq + index: 0-31 + wait for high/low on pin 0-31 or irq 0-31 + see sec 3.4.3 of RPi docs for details + +in(src, data) + src : pin, X, Y, ISR, OSR(all 0-31) + data : bit count(0-31) + see sec 3.4.4 of RPi docs for details + +out(dist,data) + dist : pin, X, Y, PINDIRS, AC, ISR, OSR(all 0-31) + data : bit count(0-31) + see sec 3.4.5 of RPi docs for details + +push(value = 0, value = 2) + block = 0 : no block + block = 1 : block + see sec 3.4.6 of RPi docs for details + +pull(value = 0, value = 2) + pull(if empty) : 1 (default = 0) + block : 1 (default = 1) + no-block = 0 + see sec 3.4.7 of RPi docs for details + +mov(dist, src) + dist : pin, X, Y, ISR, OSR, PC (all 0-31) + src : pin, X, Y, ISR, OSR (all 0-31) + see sec 3.4.8 of RPi docs for details + +set(dest, data) + dest : X, Y, PINS, PINDIRS + data : value (0-31) + see sec 3.4.10 of RPi docs for details + +irq(mod, index = None) + These are the following forms of this instruction(index is an integer value + from 0-7) + * irq(index) + * irq(rel(index)) + * irq(block, index) + * irq(block, rel(index)) + * irq(clear, rel(index)) + * irq(block | clear, index) + * irq(block | clear, rel(index)) + + These can be summarised as two forms: + * form 1: irq(index) + * form 2: irq(mode,index) + where + * index can be an integer or rel(integer) + * mode can be: block or clear or block | clear + + Allowed IRQ numbers are 0-7 (0-3 are visible from to the processor, 4-7 are + internal to the state machines). + see sec 3.4.9 of RPi docs for details + + + Classes ------- From b25ea04a4c5ee0cc1a0b46901344b14deb7bcaf4 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 14 Jul 2021 12:15:16 +0530 Subject: [PATCH 06/31] typos corrected --- docs/rp2/pio.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index 70d1d972160e3..f30daf40f2757 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -4,20 +4,20 @@ RP2040 has standard hardware support like I2C, SPI and UART for communication protocols with standard devices. For devices where we do not have hardware support for such protocols or where there is a requirement of more I/O channels, PIO(Programmable Input Ouput) comes intp play. Also, typical -micropython devices make use of a technique called bit banging which is pins +micropython devices make use of a technique called bit banging in which pins are rapidly turned on and off to transmit data. This makes the entire process very slow as the processor concentrates on bit banging rather than exceuting -any other process. However, PIO sllows it to carry on with the bit banging +any other process. However, PIO allows it to carry on with the bit banging process while the processor resources are used for executing some other work. Along with the two main cotex - MO+ processing cores, RP2040 has two PIO blocks each of which has four state machines. These state machines take -process data in FIFO (FIrst-In-First-Out) format. When these state machines +process data in FIFO (First-In-First-Out) format. When these state machines are free, they will put in data from the queue and execute the instruction. This way, the PIO state machines and the main process works simultaneously without being much dependant on the other. -Eaxh FIFO has four words (each of 32 bits) which can be linked to the DMA toin assemby +Each FIFO has four words (each of 32 bits) which can be linked to the DMA to transmit larger amounts of data to the PIO state machine and allows it to carry on execution without the main program keeping a track of it at each instant of time. From 218d0d8fa0c2fe32004f3c789965a912327c7ba2 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 14 Jul 2021 12:27:40 +0530 Subject: [PATCH 07/31] brief description of all instructions added --- docs/rp2/pio.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index f30daf40f2757..fa81bb6ba7555 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -22,6 +22,26 @@ transmit larger amounts of data to the PIO state machine and allows it to carry on execution without the main program keeping a track of it at each instant of time. +The state machines have 9 instructions which can perform the following tasks:- + +* IN : shifts the bits from a source (scratch register or set of pins) to the +* input shift register. + +* OUT : shifts the bits from the output shift register to a destination + +* PUSH : sends data to RX FIFO + +* PULL : recieves data from TX FIFO + +* MOV : moves data from a souce to a destination + +* IRQ : sets or clears the input flag + +* WAIT : pauses until a particular action happens + +* JMP : moves to some target locations in differnt parts of code. + + From 1d761a638f10c8f54dcf51cb387a2efe1879be70 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Thu, 15 Jul 2021 09:52:50 +0530 Subject: [PATCH 08/31] blink_1hz example added --- docs/rp2/pio.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index fa81bb6ba7555..fcc6749278e10 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -35,6 +35,8 @@ The state machines have 9 instructions which can perform the following tasks:- * MOV : moves data from a souce to a destination + + * IRQ : sets or clears the input flag * WAIT : pauses until a particular action happens @@ -42,6 +44,16 @@ The state machines have 9 instructions which can perform the following tasks:- * JMP : moves to some target locations in differnt parts of code. +We can take the pio_1hz example for a sinple understanding. We are creating an +object of class StateMachine which will display the output on pin 25. The +'blink_1hz' program uses the PIO to blink an LED and raise the IRQ at 1 HZ. +Turn the LED on with the help of the set instruction. Set value 31 on register +X. Then wait for 30 cycles with the help of nop() instruction. Then with the +help of jmp, go to the code part which has label as 'delay high' for the +instruction offset. The next part of the code teaches us to turn the LED off +by turning the LED off with the help of set instruction. Here the label is +'delay_low' for the instruction offset part of the jmp instruction. +We then print the millisecond timestamp by setting the IRQ handler. From 541ab4ada8a5751376e5305f628b9bb825211a5f Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 01:32:30 +0530 Subject: [PATCH 09/31] heading added for PIO assembly language instructions --- docs/library/rp2.rst | 69 +++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index e192f8b775a36..fe393d315b818 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -71,15 +71,18 @@ For running PIO programs, see :class:`rp2.StateMachine`. This exception is raised from `asm_pio()` or `asm_pio_encode()` if there is an error assembling a PIO program. +PIO Assembly Language instructions +----------------------------------- + Each state machine has a set of instructions- which allow for a wide range of behaviourial or location changes to the data. They are written in assembly language which is later used in a MicroPython program to perform specific tasks. These instructions are - jmp(cond, lebel=None) - condition : 0-7 - : 0-31 - target : instruction offset of label within the program + condition : 0-7 + : 0-31 + target : instruction offset of label within the program see sec 3.4.2 of RPi docs for details wait(polarity, src, index) @@ -90,56 +93,56 @@ wait(polarity, src, index) see sec 3.4.3 of RPi docs for details in(src, data) - src : pin, X, Y, ISR, OSR(all 0-31) - data : bit count(0-31) + src : pin, X, Y, ISR, OSR(all 0-31) + data : bit count(0-31) see sec 3.4.4 of RPi docs for details out(dist,data) - dist : pin, X, Y, PINDIRS, AC, ISR, OSR(all 0-31) - data : bit count(0-31) + dist : pin, X, Y, PINDIRS, AC, ISR, OSR(all 0-31) + data : bit count(0-31) see sec 3.4.5 of RPi docs for details push(value = 0, value = 2) - block = 0 : no block + block = 0 : no block block = 1 : block see sec 3.4.6 of RPi docs for details pull(value = 0, value = 2) - pull(if empty) : 1 (default = 0) - block : 1 (default = 1) - no-block = 0 + pull(if empty) : 1 (default = 0) + block : 1 (default = 1) + no-block = 0 see sec 3.4.7 of RPi docs for details mov(dist, src) - dist : pin, X, Y, ISR, OSR, PC (all 0-31) - src : pin, X, Y, ISR, OSR (all 0-31) + dist : pin, X, Y, ISR, OSR, PC (all 0-31) + src : pin, X, Y, ISR, OSR (all 0-31) see sec 3.4.8 of RPi docs for details set(dest, data) - dest : X, Y, PINS, PINDIRS - data : value (0-31) + dest : X, Y, PINS, PINDIRS + data : value (0-31) see sec 3.4.10 of RPi docs for details irq(mod, index = None) - These are the following forms of this instruction(index is an integer value - from 0-7) + These are the following forms of this instruction(index is an integer value + from 0-7) * irq(index) - * irq(rel(index)) - * irq(block, index) - * irq(block, rel(index)) - * irq(clear, rel(index)) - * irq(block | clear, index) - * irq(block | clear, rel(index)) - - These can be summarised as two forms: - * form 1: irq(index) - * form 2: irq(mode,index) - where - * index can be an integer or rel(integer) - * mode can be: block or clear or block | clear - - Allowed IRQ numbers are 0-7 (0-3 are visible from to the processor, 4-7 are - internal to the state machines). + * irq(rel(index)) + * irq(block, index) + * irq(block, rel(index)) + * irq(clear, rel(index)) + * irq(block | clear, index) + * irq(block | clear, rel(index)) + + These can be summarised as two forms: + * form 1: irq(index) + * form 2: irq(mode,index) + where + * index can be an integer or rel(integer) + * mode can be: block or clear or block | clear + + Allowed IRQ numbers are 0-7 (0-3 are visible from to the processor, 4-7 are + internal to the state machines). see sec 3.4.9 of RPi docs for details From b182b084bc58bb676b64a4fb4accf8f52af1460f Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 01:38:26 +0530 Subject: [PATCH 10/31] uppercase to lowercase changes made where necessary --- docs/library/rp2.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index fe393d315b818..b75aef2a38237 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -93,12 +93,12 @@ wait(polarity, src, index) see sec 3.4.3 of RPi docs for details in(src, data) - src : pin, X, Y, ISR, OSR(all 0-31) + src : pin, x, y, isr, osr(all 0-31) data : bit count(0-31) see sec 3.4.4 of RPi docs for details out(dist,data) - dist : pin, X, Y, PINDIRS, AC, ISR, OSR(all 0-31) + dist : pin, x, y, pindirs, ac, isr, osr(all 0-31) data : bit count(0-31) see sec 3.4.5 of RPi docs for details @@ -114,12 +114,12 @@ pull(value = 0, value = 2) see sec 3.4.7 of RPi docs for details mov(dist, src) - dist : pin, X, Y, ISR, OSR, PC (all 0-31) - src : pin, X, Y, ISR, OSR (all 0-31) + dist : pin, x, y, isr, osr, pc (all 0-31) + src : pin, x, y, isr, osr (all 0-31) see sec 3.4.8 of RPi docs for details set(dest, data) - dest : X, Y, PINS, PINDIRS + dest : x, y, pins, pindirs data : value (0-31) see sec 3.4.10 of RPi docs for details From 5ba4a964ccb773f11b9e0448c7e50abc03f66b03 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 01:39:27 +0530 Subject: [PATCH 11/31] typos corrected --- docs/library/rp2.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index b75aef2a38237..2c3163145804c 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -113,8 +113,8 @@ pull(value = 0, value = 2) no-block = 0 see sec 3.4.7 of RPi docs for details -mov(dist, src) - dist : pin, x, y, isr, osr, pc (all 0-31) +mov(dest, src) + dest : pin, x, y, isr, osr, pc (all 0-31) src : pin, x, y, isr, osr (all 0-31) see sec 3.4.8 of RPi docs for details From 8dce4375616fe295e5288b8321338bf8d7611405 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 01:40:10 +0530 Subject: [PATCH 12/31] Update rp2.rst --- docs/library/rp2.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 2c3163145804c..461c13a998c5d 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -97,8 +97,8 @@ in(src, data) data : bit count(0-31) see sec 3.4.4 of RPi docs for details -out(dist,data) - dist : pin, x, y, pindirs, ac, isr, osr(all 0-31) +out(dest,data) + dest : pin, x, y, pindirs, ac, isr, osr(all 0-31) data : bit count(0-31) see sec 3.4.5 of RPi docs for details From 7abf0e7cc84580499d2d175ac97573f5a8f36f25 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 01:48:26 +0530 Subject: [PATCH 13/31] pio_1hz blink example added --- docs/rp2/pio.rst | 58 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index fcc6749278e10..91faa0ea0d852 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -44,15 +44,55 @@ The state machines have 9 instructions which can perform the following tasks:- * JMP : moves to some target locations in differnt parts of code. -We can take the pio_1hz example for a sinple understanding. We are creating an -object of class StateMachine which will display the output on pin 25. The -'blink_1hz' program uses the PIO to blink an LED and raise the IRQ at 1 HZ. -Turn the LED on with the help of the set instruction. Set value 31 on register -X. Then wait for 30 cycles with the help of nop() instruction. Then with the -help of jmp, go to the code part which has label as 'delay high' for the -instruction offset. The next part of the code teaches us to turn the LED off -by turning the LED off with the help of set instruction. Here the label is -'delay_low' for the instruction offset part of the jmp instruction. +We can take the pio_1hz example for a sinple understanding. Below is the code +of pio_1hz.py for reference. + +.. code-block:: python3 + + # Example using PIO to blink an LED and raise an IRQ at 1Hz. + + import time + from machine import Pin + import rp2 + + + @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW) + def blink_1hz(): + # fmt: off + # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000 + irq(rel(0)) + set(pins, 1) + set(x, 31) [5] + label("delay_high") + nop() [29] + jmp(x_dec, "delay_high") + + # Cycles: 1 + 7 + 32 * (30 + 1) = 1000 + set(pins, 0) + set(x, 31) [6] + label("delay_low") + nop() [29] + jmp(x_dec, "delay_low") + # fmt: on + + + # Create the StateMachine with the blink_1hz program, outputting on Pin(25). + sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25)) + + # Set the IRQ handler to print the millisecond timestamp. + sm.irq(lambda p: print(time.ticks_ms())) + + # Start the StateMachine. + sm.active(1) + +We are creating an object of class StateMachine which will display the output +on pin 25. The 'blink_1hz' program uses the PIO to blink an LED and raise the +IRQ at 1 HZ. Turn the LED on with the help of the set instruction. Set value +31 on register X. Then wait for 30 cycles with the help of nop() instruction. +Then with the help of jmp, go to the code part which has label as 'delay high' +for the instruction offset. The next part of the code teaches us to turn the +LED off by turning the LED off with the help of set instruction. Here the +label is 'delay_low' for the instruction offset part of the jmp instruction. We then print the millisecond timestamp by setting the IRQ handler. From fc8084dd4c3562b7dc9338f4e9fc7bce80c55dcb Mon Sep 17 00:00:00 2001 From: NitiKaur Date: Sun, 18 Jul 2021 01:59:42 +0530 Subject: [PATCH 14/31] file location changed --- docs/rp2/tutorial/pio.rst | 100 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 docs/rp2/tutorial/pio.rst diff --git a/docs/rp2/tutorial/pio.rst b/docs/rp2/tutorial/pio.rst new file mode 100644 index 0000000000000..ea5e1fea4e031 --- /dev/null +++ b/docs/rp2/tutorial/pio.rst @@ -0,0 +1,100 @@ +.. _rp2_pio: + +RP2040 has standard hardware support like I2C, SPI and UART for communication +protocols with standard devices. For devices where we do not have hardware +support for such protocols or where there is a requirement of more I/O +channels, PIO(Programmable Input Ouput) comes intp play. Also, typical +micropython devices make use of a technique called bit banging in which pins +are rapidly turned on and off to transmit data. This makes the entire process +very slow as the processor concentrates on bit banging rather than exceuting +any other process. However, PIO allows it to carry on with the bit banging +process while the processor resources are used for executing some other work. + +Along with the two main cotex - MO+ processing cores, RP2040 has two PIO +blocks each of which has four state machines. These state machines take +process data in FIFO (First-In-First-Out) format. When these state machines +are free, they will put in data from the queue and execute the instruction. +This way, the PIO state machines and the main process works simultaneously +without being much dependant on the other. + +Each FIFO has four words (each of 32 bits) which can be linked to the DMA to +transmit larger amounts of data to the PIO state machine and allows it to +carry on execution without the main program keeping a track of it at each +instant of time. + +The state machines have 9 instructions which can perform the following tasks:- + +* IN : shifts the bits from a source (scratch register or set of pins) to the +* input shift register. + +* OUT : shifts the bits from the output shift register to a destination + +* PUSH : sends data to RX FIFO + +* PULL : recieves data from TX FIFO + +* MOV : moves data from a souce to a destination + + + +* IRQ : sets or clears the input flag + +* WAIT : pauses until a particular action happens + +* JMP : moves to some target locations in differnt parts of code. + + +We can take the pio_1hz example for a sinple understanding. Below is the code +of pio_1hz.py for reference. + +.. code-block:: python3 + + # Example using PIO to blink an LED and raise an IRQ at 1Hz. + + import time + from machine import Pin + import rp2 + + + @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW) + def blink_1hz(): + # fmt: off + # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000 + irq(rel(0)) + set(pins, 1) + set(x, 31) [5] + label("delay_high") + nop() [29] + jmp(x_dec, "delay_high") + + # Cycles: 1 + 7 + 32 * (30 + 1) = 1000 + set(pins, 0) + set(x, 31) [6] + label("delay_low") + nop() [29] + jmp(x_dec, "delay_low") + # fmt: on + + + # Create the StateMachine with the blink_1hz program, outputting on Pin(25). + sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25)) + + # Set the IRQ handler to print the millisecond timestamp. + sm.irq(lambda p: print(time.ticks_ms())) + + # Start the StateMachine. + sm.active(1) + +We are creating an object of class StateMachine which will display the output +on pin 25. The 'blink_1hz' program uses the PIO to blink an LED and raise the +IRQ at 1 HZ. Turn the LED on with the help of the set instruction. Set value +31 on register X. Then wait for 30 cycles with the help of nop() instruction. +Then with the help of jmp, go to the code part which has label as 'delay high' +for the instruction offset. The next part of the code teaches us to turn the +LED off by turning the LED off with the help of set instruction. Here the +label is 'delay_low' for the instruction offset part of the jmp instruction. + +We then print the millisecond timestamp by setting the IRQ handler. + + + From 2a78748237de82fcc259c95221d9f20b8198e5a7 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 02:23:50 +0530 Subject: [PATCH 15/31] nop instruction added --- docs/rp2/pio.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index 91faa0ea0d852..cc4ac7cf1e432 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -35,16 +35,17 @@ The state machines have 9 instructions which can perform the following tasks:- * MOV : moves data from a souce to a destination - - * IRQ : sets or clears the input flag * WAIT : pauses until a particular action happens * JMP : moves to some target locations in differnt parts of code. +We also have the feature of a pseudo-instruction provided by pioasm:- + +* NOP : assembles to mov y and y; used for providing extra-delay -We can take the pio_1hz example for a sinple understanding. Below is the code +To understand the use of these instrcutions we can take the pio_1hz example for a sinple understanding. Below is the code of pio_1hz.py for reference. .. code-block:: python3 From cd85f4a50d0f5ebb593450421ff384e7fdc6bad6 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 02:24:50 +0530 Subject: [PATCH 16/31] lines wrapped --- docs/rp2/pio.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index cc4ac7cf1e432..8f7a8e072ffd0 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -45,8 +45,8 @@ We also have the feature of a pseudo-instruction provided by pioasm:- * NOP : assembles to mov y and y; used for providing extra-delay -To understand the use of these instrcutions we can take the pio_1hz example for a sinple understanding. Below is the code -of pio_1hz.py for reference. +To understand the use of these instrcutions we can take the pio_1hz example for +a sinple understanding. Below is the code of pio_1hz.py for reference. .. code-block:: python3 From 08fb1eac2492e8f69d313ddf2b0574d1cfdffd07 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 16:14:07 +0530 Subject: [PATCH 17/31] nop syntax added --- docs/library/rp2.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 461c13a998c5d..110e64fca0b94 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -145,7 +145,8 @@ irq(mod, index = None) internal to the state machines). see sec 3.4.9 of RPi docs for details - +nop(self) + see sec 3.3.7 of RPi docs for details Classes From 286eab1eb9bd15f7444903a0e611d27344b0c3bb Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 16:27:24 +0530 Subject: [PATCH 18/31] instructions shifted to lowercase --- docs/rp2/pio.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index 8f7a8e072ffd0..24028cbe17c23 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -24,26 +24,26 @@ instant of time. The state machines have 9 instructions which can perform the following tasks:- -* IN : shifts the bits from a source (scratch register or set of pins) to the +* in : shifts the bits from a source (scratch register or set of pins) to the * input shift register. -* OUT : shifts the bits from the output shift register to a destination +* out : shifts the bits from the output shift register to a destination -* PUSH : sends data to RX FIFO +* push : sends data to RX FIFO -* PULL : recieves data from TX FIFO +* pull : recieves data from TX FIFO -* MOV : moves data from a souce to a destination +* mov : moves data from a souce to a destination -* IRQ : sets or clears the input flag +* irq : sets or clears the input flag -* WAIT : pauses until a particular action happens +* wait : pauses until a particular action happens -* JMP : moves to some target locations in differnt parts of code. +* jmp : moves to some target locations in differnt parts of code. We also have the feature of a pseudo-instruction provided by pioasm:- -* NOP : assembles to mov y and y; used for providing extra-delay +* nop : assembles to mov y and y; used for providing extra-delay To understand the use of these instrcutions we can take the pio_1hz example for a sinple understanding. Below is the code of pio_1hz.py for reference. From c72b9334cfe9f82d3385f768abe6eef545b85aed Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 16:56:39 +0530 Subject: [PATCH 19/31] meta-instructions added description only --- docs/rp2/pio.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst index 24028cbe17c23..10c3dc8b20210 100644 --- a/docs/rp2/pio.rst +++ b/docs/rp2/pio.rst @@ -45,6 +45,33 @@ We also have the feature of a pseudo-instruction provided by pioasm:- * nop : assembles to mov y and y; used for providing extra-delay +In addition to the 9 instructions and 1 pseudo-instruction, we also have some +meta-instructions which are as follows: + +* wrap : allows us to loop automatically without a jmp instrcution; used to + jmp straight to .wrap_target + +* wrap_target : target label used with .wrap instruction to jump to a + particular point of code + +* word : used to store a 16-bit raw value instruction + +* label : instruction offset of label used with jmp instruction + +The pioasm functions have a common pattern: + + (side)([delay_value>]) + +where: + + : is 1 of the 9 assembly instructions + + : value applied to side_set pins where we can set one or more + pins at the time another instruction runs + + : value in clock-cycles to be delayed after the completion of + an instruction + To understand the use of these instrcutions we can take the pio_1hz example for a sinple understanding. Below is the code of pio_1hz.py for reference. From ab3f11e2e9d77d5b615326b9bc95a80b6af5d42c Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 17:04:27 +0530 Subject: [PATCH 20/31] IRQ instruction form corrected --- docs/library/rp2.rst | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 110e64fca0b94..7d10d2fb2f0c7 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -74,7 +74,7 @@ For running PIO programs, see :class:`rp2.StateMachine`. PIO Assembly Language instructions ----------------------------------- -Each state machine has a set of instructions- which allow for a wide range of +Each state machine has a set of instructions, which allow for a wide range of behaviourial or location changes to the data. They are written in assembly language which is later used in a MicroPython program to perform specific tasks. These instructions are - @@ -126,13 +126,6 @@ set(dest, data) irq(mod, index = None) These are the following forms of this instruction(index is an integer value from 0-7) - * irq(index) - * irq(rel(index)) - * irq(block, index) - * irq(block, rel(index)) - * irq(clear, rel(index)) - * irq(block | clear, index) - * irq(block | clear, rel(index)) These can be summarised as two forms: * form 1: irq(index) From b25d26d6ccc69db6827e06ced4c2f805af422ab0 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 17:08:13 +0530 Subject: [PATCH 21/31] jump instruction syntax corrected --- docs/library/rp2.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 7d10d2fb2f0c7..e9096485b4e98 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -79,10 +79,15 @@ behaviourial or location changes to the data. They are written in assembly language which is later used in a MicroPython program to perform specific tasks. These instructions are - -jmp(cond, lebel=None) - condition : 0-7 - : 0-31 - target : instruction offset of label within the program +jmp(cond, label=None) + This can take two forms: + jmp(label) + label : label to jump to unconditionlly + + jmp(cond,label) + cond: not_x, x_dec, not_y, y_dec, x_not_y, pin, not_osre + label: label to jump to if condition is true + see sec 3.4.2 of RPi docs for details wait(polarity, src, index) From 8a05b8331291eada78424e3ab873187b9871d875 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 17:20:18 +0530 Subject: [PATCH 22/31] push instruction forms corrected --- docs/library/rp2.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index e9096485b4e98..98cefcdacde31 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -107,9 +107,14 @@ out(dest,data) data : bit count(0-31) see sec 3.4.5 of RPi docs for details -push(value = 0, value = 2) - block = 0 : no block - block = 1 : block +push() + These instruction takes the following forms: + push() + push(block) + push(noblock) + push(iffull) + push(iffull, block) + push(iffull, noblock) see sec 3.4.6 of RPi docs for details pull(value = 0, value = 2) From 5dcfbd01abcb3657a11727a22a865dcbec7760f4 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 18 Jul 2021 17:24:24 +0530 Subject: [PATCH 23/31] pull instruction syntax corrected --- docs/library/rp2.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 98cefcdacde31..c6f92a7d44b7d 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -108,7 +108,7 @@ out(dest,data) see sec 3.4.5 of RPi docs for details push() - These instruction takes the following forms: + This instruction takes the following forms: push() push(block) push(noblock) @@ -117,10 +117,14 @@ push() push(iffull, noblock) see sec 3.4.6 of RPi docs for details -pull(value = 0, value = 2) - pull(if empty) : 1 (default = 0) - block : 1 (default = 1) - no-block = 0 +pull() + This instruction can take the following forms: + pull() + pull(block) + pull(noblock) + pull(ifempty) + pull(ifempty, block) + pull(ifempty, noblock) see sec 3.4.7 of RPi docs for details mov(dest, src) From 65c1f7d00383124c4f8757a2d9008a654a54833c Mon Sep 17 00:00:00 2001 From: NitiKaur Date: Tue, 20 Jul 2021 01:31:03 +0530 Subject: [PATCH 24/31] files corrected --- docs/rp2/pio.rst | 127 -------------------------------------- docs/rp2/tutorial/pio.rst | 1 + 2 files changed, 1 insertion(+), 127 deletions(-) delete mode 100644 docs/rp2/pio.rst diff --git a/docs/rp2/pio.rst b/docs/rp2/pio.rst deleted file mode 100644 index 10c3dc8b20210..0000000000000 --- a/docs/rp2/pio.rst +++ /dev/null @@ -1,127 +0,0 @@ -.. _rp2_pio: - -RP2040 has standard hardware support like I2C, SPI and UART for communication -protocols with standard devices. For devices where we do not have hardware -support for such protocols or where there is a requirement of more I/O -channels, PIO(Programmable Input Ouput) comes intp play. Also, typical -micropython devices make use of a technique called bit banging in which pins -are rapidly turned on and off to transmit data. This makes the entire process -very slow as the processor concentrates on bit banging rather than exceuting -any other process. However, PIO allows it to carry on with the bit banging -process while the processor resources are used for executing some other work. - -Along with the two main cotex - MO+ processing cores, RP2040 has two PIO -blocks each of which has four state machines. These state machines take -process data in FIFO (First-In-First-Out) format. When these state machines -are free, they will put in data from the queue and execute the instruction. -This way, the PIO state machines and the main process works simultaneously -without being much dependant on the other. - -Each FIFO has four words (each of 32 bits) which can be linked to the DMA to -transmit larger amounts of data to the PIO state machine and allows it to -carry on execution without the main program keeping a track of it at each -instant of time. - -The state machines have 9 instructions which can perform the following tasks:- - -* in : shifts the bits from a source (scratch register or set of pins) to the -* input shift register. - -* out : shifts the bits from the output shift register to a destination - -* push : sends data to RX FIFO - -* pull : recieves data from TX FIFO - -* mov : moves data from a souce to a destination - -* irq : sets or clears the input flag - -* wait : pauses until a particular action happens - -* jmp : moves to some target locations in differnt parts of code. - -We also have the feature of a pseudo-instruction provided by pioasm:- - -* nop : assembles to mov y and y; used for providing extra-delay - -In addition to the 9 instructions and 1 pseudo-instruction, we also have some -meta-instructions which are as follows: - -* wrap : allows us to loop automatically without a jmp instrcution; used to - jmp straight to .wrap_target - -* wrap_target : target label used with .wrap instruction to jump to a - particular point of code - -* word : used to store a 16-bit raw value instruction - -* label : instruction offset of label used with jmp instruction - -The pioasm functions have a common pattern: - - (side)([delay_value>]) - -where: - - : is 1 of the 9 assembly instructions - - : value applied to side_set pins where we can set one or more - pins at the time another instruction runs - - : value in clock-cycles to be delayed after the completion of - an instruction - -To understand the use of these instrcutions we can take the pio_1hz example for -a sinple understanding. Below is the code of pio_1hz.py for reference. - -.. code-block:: python3 - - # Example using PIO to blink an LED and raise an IRQ at 1Hz. - - import time - from machine import Pin - import rp2 - - - @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW) - def blink_1hz(): - # fmt: off - # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000 - irq(rel(0)) - set(pins, 1) - set(x, 31) [5] - label("delay_high") - nop() [29] - jmp(x_dec, "delay_high") - - # Cycles: 1 + 7 + 32 * (30 + 1) = 1000 - set(pins, 0) - set(x, 31) [6] - label("delay_low") - nop() [29] - jmp(x_dec, "delay_low") - # fmt: on - - - # Create the StateMachine with the blink_1hz program, outputting on Pin(25). - sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25)) - - # Set the IRQ handler to print the millisecond timestamp. - sm.irq(lambda p: print(time.ticks_ms())) - - # Start the StateMachine. - sm.active(1) - -We are creating an object of class StateMachine which will display the output -on pin 25. The 'blink_1hz' program uses the PIO to blink an LED and raise the -IRQ at 1 HZ. Turn the LED on with the help of the set instruction. Set value -31 on register X. Then wait for 30 cycles with the help of nop() instruction. -Then with the help of jmp, go to the code part which has label as 'delay high' -for the instruction offset. The next part of the code teaches us to turn the -LED off by turning the LED off with the help of set instruction. Here the -label is 'delay_low' for the instruction offset part of the jmp instruction. - -We then print the millisecond timestamp by setting the IRQ handler. - - diff --git a/docs/rp2/tutorial/pio.rst b/docs/rp2/tutorial/pio.rst index ea5e1fea4e031..c4ace0db01968 100644 --- a/docs/rp2/tutorial/pio.rst +++ b/docs/rp2/tutorial/pio.rst @@ -98,3 +98,4 @@ We then print the millisecond timestamp by setting the IRQ handler. + From 52b9371f721c2815cb707a5a681d6efd8c9bd5fb Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Tue, 20 Jul 2021 01:35:51 +0530 Subject: [PATCH 25/31] typos corrected --- docs/rp2/tutorial/pio.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/rp2/tutorial/pio.rst b/docs/rp2/tutorial/pio.rst index c4ace0db01968..45ace8781c570 100644 --- a/docs/rp2/tutorial/pio.rst +++ b/docs/rp2/tutorial/pio.rst @@ -3,19 +3,19 @@ RP2040 has standard hardware support like I2C, SPI and UART for communication protocols with standard devices. For devices where we do not have hardware support for such protocols or where there is a requirement of more I/O -channels, PIO(Programmable Input Ouput) comes intp play. Also, typical +channels, PIO(Programmable Input Ouput) comes into play. Also, typical micropython devices make use of a technique called bit banging in which pins are rapidly turned on and off to transmit data. This makes the entire process very slow as the processor concentrates on bit banging rather than exceuting any other process. However, PIO allows it to carry on with the bit banging process while the processor resources are used for executing some other work. -Along with the two main cotex - MO+ processing cores, RP2040 has two PIO +Along with the two main cortex - MO+ processing cores, RP2040 has two PIO blocks each of which has four state machines. These state machines take process data in FIFO (First-In-First-Out) format. When these state machines are free, they will put in data from the queue and execute the instruction. This way, the PIO state machines and the main process works simultaneously -without being much dependant on the other. +without being much dependent on the other. Each FIFO has four words (each of 32 bits) which can be linked to the DMA to transmit larger amounts of data to the PIO state machine and allows it to @@ -35,8 +35,6 @@ The state machines have 9 instructions which can perform the following tasks:- * MOV : moves data from a souce to a destination - - * IRQ : sets or clears the input flag * WAIT : pauses until a particular action happens @@ -98,4 +96,3 @@ We then print the millisecond timestamp by setting the IRQ handler. - From b76453a8d0ed468760128649975be3eefc199b8a Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 25 Jul 2021 20:25:29 +0530 Subject: [PATCH 26/31] directives,label, delay, side-set added --- docs/rp2/tutorial/pio.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/rp2/tutorial/pio.rst b/docs/rp2/tutorial/pio.rst index 45ace8781c570..94437844fa18a 100644 --- a/docs/rp2/tutorial/pio.rst +++ b/docs/rp2/tutorial/pio.rst @@ -22,6 +22,9 @@ transmit larger amounts of data to the PIO state machine and allows it to carry on execution without the main program keeping a track of it at each instant of time. +All pioasm instructions follow a common pattern: + (side ) ([]) + The state machines have 9 instructions which can perform the following tasks:- * IN : shifts the bits from a source (scratch register or set of pins) to the @@ -41,6 +44,26 @@ The state machines have 9 instructions which can perform the following tasks:- * JMP : moves to some target locations in differnt parts of code. +Apart from the PIO assembly instructions we have the following :- + + : value applied to the side set pins at the start of the + instruction which helps configure the side pin of the + program. + + : the number of clock cycles to delay after execution of + any instruction. + +We also have directives which are listed as :- + +* .wrap_target : specifies where the program execution will get continued from + +* .wrap : specifies the instruction where the control flow of the program will + get wrapped from. + +* .word : stores a raw 16-bit value which acts as an instruction to the + program. + +* label : instruction offset of label used with jmp instruction. We can take the pio_1hz example for a sinple understanding. Below is the code of pio_1hz.py for reference. From f830f4cc701d510ffaa6ba96b82350840b88d9d9 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Sun, 25 Jul 2021 20:26:53 +0530 Subject: [PATCH 27/31] set instruction added --- docs/rp2/tutorial/pio.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/rp2/tutorial/pio.rst b/docs/rp2/tutorial/pio.rst index 94437844fa18a..c53a9e08200e8 100644 --- a/docs/rp2/tutorial/pio.rst +++ b/docs/rp2/tutorial/pio.rst @@ -42,7 +42,9 @@ The state machines have 9 instructions which can perform the following tasks:- * WAIT : pauses until a particular action happens -* JMP : moves to some target locations in differnt parts of code. +* JMP : moves to some target locations in differnt parts of code + +* SET : writes data at destination Apart from the PIO assembly instructions we have the following :- From 753cb43d5fa39979ce2f80b12779ad30d7e66094 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 1 Sep 2021 09:47:33 +0530 Subject: [PATCH 28/31] typos corrected --- docs/rp2/tutorial/pio.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/rp2/tutorial/pio.rst b/docs/rp2/tutorial/pio.rst index c53a9e08200e8..5ef9e4bb610e5 100644 --- a/docs/rp2/tutorial/pio.rst +++ b/docs/rp2/tutorial/pio.rst @@ -6,7 +6,7 @@ support for such protocols or where there is a requirement of more I/O channels, PIO(Programmable Input Ouput) comes into play. Also, typical micropython devices make use of a technique called bit banging in which pins are rapidly turned on and off to transmit data. This makes the entire process -very slow as the processor concentrates on bit banging rather than exceuting +very slow as the processor concentrates on bit banging rather than excecuting any other process. However, PIO allows it to carry on with the bit banging process while the processor resources are used for executing some other work. @@ -25,7 +25,7 @@ instant of time. All pioasm instructions follow a common pattern: (side ) ([]) -The state machines have 9 instructions which can perform the following tasks:- +The state machines have 9 instructions which can perform the following tasks: * IN : shifts the bits from a source (scratch register or set of pins) to the * input shift register. @@ -46,7 +46,7 @@ The state machines have 9 instructions which can perform the following tasks:- * SET : writes data at destination -Apart from the PIO assembly instructions we have the following :- +Apart from the PIO assembly instructions we have the following: : value applied to the side set pins at the start of the instruction which helps configure the side pin of the @@ -55,7 +55,7 @@ Apart from the PIO assembly instructions we have the following :- : the number of clock cycles to delay after execution of any instruction. -We also have directives which are listed as :- +We also have directives which are listed as: * .wrap_target : specifies where the program execution will get continued from @@ -67,7 +67,7 @@ We also have directives which are listed as :- * label : instruction offset of label used with jmp instruction. -We can take the pio_1hz example for a sinple understanding. Below is the code +We can take the pio_1hz example for a simple understanding. Below is the code of pio_1hz.py for reference. .. code-block:: python3 From 708da6b3f08ab2b22f91a31b9645da69f6636b49 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 1 Sep 2021 09:49:39 +0530 Subject: [PATCH 29/31] typos corrected(2) --- docs/rp2/tutorial/pio.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/rp2/tutorial/pio.rst b/docs/rp2/tutorial/pio.rst index 5ef9e4bb610e5..adaea16a0af40 100644 --- a/docs/rp2/tutorial/pio.rst +++ b/docs/rp2/tutorial/pio.rst @@ -3,7 +3,7 @@ RP2040 has standard hardware support like I2C, SPI and UART for communication protocols with standard devices. For devices where we do not have hardware support for such protocols or where there is a requirement of more I/O -channels, PIO(Programmable Input Ouput) comes into play. Also, typical +channels, PIO(Programmable Input Output) comes into play. Also, typical micropython devices make use of a technique called bit banging in which pins are rapidly turned on and off to transmit data. This makes the entire process very slow as the processor concentrates on bit banging rather than excecuting @@ -34,15 +34,15 @@ The state machines have 9 instructions which can perform the following tasks: * PUSH : sends data to RX FIFO -* PULL : recieves data from TX FIFO +* PULL : receives data from TX FIFO -* MOV : moves data from a souce to a destination +* MOV : moves data from a source to a destination * IRQ : sets or clears the input flag * WAIT : pauses until a particular action happens -* JMP : moves to some target locations in differnt parts of code +* JMP : moves to some target locations in different parts of code * SET : writes data at destination From 565f65ff22ac820ee7eb0f47f6dd25cc25aa2401 Mon Sep 17 00:00:00 2001 From: Niti Kaur <46062965+NitiKaur@users.noreply.github.com> Date: Wed, 1 Sep 2021 10:13:29 +0530 Subject: [PATCH 30/31] typos (3) --- docs/library/rp2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index c6f92a7d44b7d..0a404936268d4 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -82,7 +82,7 @@ tasks. These instructions are - jmp(cond, label=None) This can take two forms: jmp(label) - label : label to jump to unconditionlly + label : label to jump to unconditionally jmp(cond,label) cond: not_x, x_dec, not_y, y_dec, x_not_y, pin, not_osre From 469f318be23f8a860b5d348346a53193278e451e Mon Sep 17 00:00:00 2001 From: NitiKaur Date: Wed, 1 Sep 2021 17:14:40 +0530 Subject: [PATCH 31/31] docs build corrected --- docs/library/index.rst | 1 + docs/library/rp2.rst | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/library/index.rst b/docs/library/index.rst index 2536e8dc96d04..bd0ec3a2eaa15 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -176,3 +176,4 @@ The following libraries are specific to the RP2040, as used in the Raspberry Pi :maxdepth: 2 rp2.rst + diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 0a404936268d4..19b8760532334 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -81,6 +81,7 @@ tasks. These instructions are - jmp(cond, label=None) This can take two forms: + jmp(label) label : label to jump to unconditionally @@ -144,13 +145,12 @@ irq(mod, index = None) These can be summarised as two forms: * form 1: irq(index) * form 2: irq(mode,index) + where * index can be an integer or rel(integer) * mode can be: block or clear or block | clear - Allowed IRQ numbers are 0-7 (0-3 are visible from to the processor, 4-7 are - internal to the state machines). - see sec 3.4.9 of RPi docs for details + Allowed IRQ numbers are 0-7 (0-3 are visible from to the processor, 4-7 are internal to the state machines). See sec 3.4.9 of RPi docs for details nop(self) see sec 3.3.7 of RPi docs for details