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

RP2 - PIO module #7496

wants to merge 32 commits into from

Conversation

NitiKaur
Copy link
Contributor
@NitiKaur NitiKaur commented Jul 6, 2021

1st draft for PIO module- brief overview with explanation of each command

@NitiKaur NitiKaur changed the title brief overview with explanation of each command RP2 - PIO module Jul 6, 2021
@dpgeorge
Copy link
Member
dpgeorge commented Jul 8, 2021

This is a good start, and the general overview here is well suited to a tutorial or general introduction section.

The specific commands and the details of their arguments are more of a reference and I think would be better placed in a new section at the end of docs/library/rp2.rst.

docs/rp2/pio.rst Outdated

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)
  • for 10000 m 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).

docs/rp2/pio.rst Outdated
index : IRQ (0-7)
see sec 3.4.9 of RPi docs for details

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"

@mattytrentini
Copy link
Contributor

This is already of use and close to what we asked of you @NitiKaur. But the more I dig into the PIO programming (I'm quite new to it), the more I think we need more, of which, this reference will form a component.

In particular:

  • A description of rp2.StateMachine
    • How many, how to start, what methods etc
  • How nop() works
  • How rel() affects indices
  • An explanation for wrap_target()/wrap()
  • How labels are implemented
  • Methods on some of the instructions (.side() for example)
  • How IRQ can map to interrupts

In short, enough documentation so that all of the techniques used in the PIO examples are covered.

We'll discuss this further at the next meeting.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

This section could do with a heading, for example "PIO assembly language"

see sec 3.4.3 of RPi docs for details

in(src, data)
src : pin, X, Y, ISR, OSR(all 0-31)
Copy link
Member

Choose a reason for hiding this comment

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

these all need to be lower case: x, y, isr, osr. also it's in_ to not clash with the in keyword

see sec 3.4.4 of RPi docs for details

out(dist,data)
dist : pin, X, Y, PINDIRS, AC, ISR, OSR(all 0-31)
Copy link
Member

Choose a reason for hiding this comment

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

dist should be dest, and lowercase for x, y, pindirs, isr, osr (AC is not supported I don't think)

see sec 3.4.7 of RPi docs for details

mov(dist, src)
dist : pin, X, Y, ISR, OSR, PC (all 0-31)
Copy link
Member

Choose a reason for hiding this comment

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

dist should be dest (for destination), and lowercase for the options

see sec 3.4.8 of RPi docs for details

set(dest, data)
dest : X, Y, PINS, PINDIRS
Copy link
Member

Choose a reason for hiding this comment

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

lowercase

* irq(block, rel(index))
* irq(clear, rel(index))
* irq(block | clear, index)
* irq(block | clear, rel(index))
Copy link
Member

Choose a reason for hiding this comment

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

either keep this set of possible ways of writing it, or the below set of 2 forms, but not both

docs/rp2/pio.rst Outdated
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.
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to put the code for blink_1hz here in the docs so readers can easily see what is going on

docs/rp2/pio.rst Outdated
@@ -0,0 +1,59 @@
.. _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

data : value (0-31)
see sec 3.4.10 of RPi docs for details

irq(mod, index = None)
Copy link
Member

Choose a reason for hiding this comment

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

instead of this line, I'd suggest breaking this instruction into 2 parts:

irq(index)
     index: <integer> or rel(<integer>)

irq(mode, index)
    mode: block, clear, block|clear
    index: <integer> or rel(<integer>)

Copy link
Member

Choose a reason for hiding this comment

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

or it might be clearer to just write out all 7 possible options explicitly, as done below

language which is later used in a MicroPython program to perform specific
tasks. These instructions are -

jmp(cond, lebel=None)
Copy link
Member

Choose a reason for hiding this comment

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

jmp(label)
    label: label to jump to unconditionally

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

data : bit count(0-31)
see sec 3.4.5 of RPi docs for details

push(value = 0, value = 2)
Copy link
Member

Choose a reason for hiding this comment

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

push()
push(block)
push(noblock)
push(iffull)
push(iffull, block)
push(iffull, noblock)

@dpgeorge
Copy link
Member
dpgeorge commented Jul 15, 2021

Also include nop in the list of normal instructions.

There are also "meta instructions":

  • wrap_target
  • wrap
  • label
  • word

Then also side() and [x] (delay). They can be applied to all (?) instructions by writing them after the instruction, eg:

<instruction>  .side(<integer>)  [<integer_delay>]

You can apply side or delay or both or neither.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

sp: cortex

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

sp: dependent

@dpgeorge
Copy link
Member

The 4 directives that MicroPython supports are: wrap, wrap_target, word and label

@kevindawson
Copy link
kevindawson commented Aug 20, 2021

@NitiKaur

Check commit message formatting / build (pull_request) Failing after 6s — build

Our old friend:

  • Subject line should match '^[^!]+: [A-Z]+.+ .+\.$':

rears it's head again

see commit-conventions

Copy link
Contributor
@alphaFred alphaFred left a comment

Choose a reason for hiding this comment

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

Found some typos

@NitiKaur
Copy link
Contributor Author
NitiKaur commented Sep 7, 2021

@dpgeorge
I am getting the following error while building docs.

/home/runner/work/micropython/micropython/docs/rp2/tutorial/pio.rst: WARNING: document isn't included in any toctree

I tried copying the ESP8266 file structure as suggested for the ESP32 but it didn't work out as desired. It will be great if you can tell me how I should include this index file.

@alphaFred
Copy link
Contributor
alphaFred commented Sep 7, 2021

For now you have tutorial/intro.rst which is referenced in quickref.rst but you have not referenced your pio.rstanywhere as far as I could see.
When you check out the pyboard documentation there is a separated document called micropython/docs/pyboard/tutorial/index.rst referencing all tutorial documents. This would be a good option, especially when adding more tutorials in the future I guess.

So I would suggest you create tutorial/index.rst and reference intro.rst and pio.rst there. Then exchange the reference to intro.rst in quickref.rst with an reference to tutorial/index.rst. Similarly to pyboard.

That should fix your warning and also include pio.rstin the documentation.

@dpgeorge
Copy link
Member

This was merged in baa5a76, with some improvements.

@dpgeorge dpgeorge closed this Oct 13, 2021
Wind-stormger pushed a commit to BPI-STEAM/micropython that referenced this pull request Jan 30, 2023
…n-main

Translations update from Hosted Weblate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0