8000 RP2 - PIO module by NitiKaur · Pull Request #7496 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

RP2 - PIO module #7496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3c0781b
brief overwiew with explaination of each command
NitiKaur Jul 6, 2021
d0a38b6
changed self to set instruction
NitiKaur Jul 13, 2021
e49eafe
IRQ instruction updated as per review
NitiKaur Jul 13, 2021
45b666a
all asm PIo instructions moved to new location(docs/library/rp2.rst )…
NitiKaur Jul 13, 2021
8b0e238
asm PIO instructions moved to new location (2)
NitiKaur Jul 13, 2021
b25ea04
typos corrected
NitiKaur Jul 14, 2021
218d0d8
brief description of all instructions added
NitiKaur Jul 14, 2021
1d761a6
blink_1hz example added
NitiKaur Jul 15, 2021
541ab4a
heading added
NitiKaur Jul 17, 2021
b182b08
uppercase to lowercase changes made where necessary
NitiKaur Jul 17, 2021
5ba4a96
typos corrected
NitiKaur Jul 17, 2021
8dce437
Update rp2.rst
NitiKaur Jul 17, 2021
7abf0e7
pio_1hz blink example added
NitiKaur Jul 17, 2021
fc8084d
file location changed
NitiKaur Jul 17, 2021
2a78748
nop instruction added
NitiKaur Jul 17, 2021
cd85f4a
lines wrapped
NitiKaur Jul 17, 2021
08fb1ea
nop syntax added
NitiKaur Jul 18, 2021
286eab1
instructions shifted to lowercase
NitiKaur Jul 18, 2021
c72b933
meta-instructions added
NitiKaur Jul 18, 2021
ab3f11e
IRQ instruction form corrected
NitiKaur Jul 18, 2021
b25d26d
jump instruction syntax corrected
NitiKaur Jul 18, 2021
8a05b83
push instruction forms corrected
NitiKaur Jul 18, 2021
5dcfbd0
pull instruction syntax corrected
NitiKaur Jul 18, 2021
65c1f7d
files corrected
NitiKaur Jul 19, 2021
52b9371
typos corrected
NitiKaur Jul 19, 2021
b76453a
directives,label, delay, side-set added
NitiKaur Jul 25, 2021
f830f4c
set instruction added
NitiKaur Jul 25, 2021
753cb43
typos corrected
NitiKaur Sep 1, 2021
708da6b
typos corrected(2)
NitiKaur Sep 1, 2021
565f65f
typos (3)
NitiKaur Sep 1, 2021
469f318
docs build corrected
NitiKaur Sep 1, 2021
641b949
Merge branch 'master' into rp2_pio
NitiKaur Sep 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions docs/rp2/pio.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
.. _rp2_pio:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this file to docs/rp2/tutorial/pio.rst


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
<delay_value> : 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the following forms of this instruction (index is an integer value):

  • irq(index)
  • irq(rel(index))
  • irq(block, index)
  • irq(block, rel(index))
  • irq(clear, index)
  • irq(clear, rel(index))
  • irq(block | clear, index)
  • irq(block | clear, rel(index))

That can be summarised as 2 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).


self(dest, data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "set"

dest : X, Y, PINS, PINDIRS
data : value (0-31)
see sec 3.4.10 of RPi docs for details



0