Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 05:29 20 Sep 2021 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite - thinking about PIO - and a request

     Page 1 of 3    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5237
Posted: 07:59am 27 Jun 2021
Copy link to clipboard 
Print this post

One of the strengths of the RP2040 is the two PIO channels which can run small programs independent of the main processor. I've been thinking about how to give access to these from Basic and the developing concept is as follows:

PIO INIT - loads a program to a PIO, sets the clock etc.
PIO START/STOP - starts and stops an instance of a PIO program
PIO READ/WRITE - sends and receives data from a PIO

The bit that I'm missing is an assembler to construct the PIO binary code from text.

My thought in the first instance is that this could be written in Basic
There are only 9 instructions and a program is a maximum of 32 instructions long.
The PIO program could easily be stored in Basic DATA statements e.g.

DATA "set x, 23"
DATA "bitloop: set pins,1"
DATA "out y, 1 [5]"
DATA .....
DATA NOP


Then a basic subroutine could convert this into a 8 element integer array (32 instructions at 16bits each). This array would then be used by PIO INIT to program the PIO.

Anyone want to volunteer to write this basic subroutine? All the info needed is in the RP2040 datasheet or the RP2040 C SDK?

Adopting this approach means that I can get on with the PIO Basic instruction knowing that the input to it will always be an array of 8 integers

Thoughts? Volunteers?
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 1760
Posted: 08:14am 27 Jun 2021
Copy link to clipboard 
Print this post

I will (try) to do it if you want Peter, but I can't promise to do it quickly, so if there are other volunteers you may want to consider one of them.

Edit: if anyone does start work on this then please post, I don't want to be duplicating effort - thanks.

Best wishes,

Tom
Edited 2021-06-27 18:43 by thwill
CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 789
Posted: 08:50am 27 Jun 2021
Copy link to clipboard 
Print this post

I'm just reading the info (it's clever stuff, innit?) - tbh I don't think I have the skills for assembler writing.

This site has a nice chart showing the makeup of the instructions:
https://www.cnx-software.com/2021/01/27/a-closer-look-at-raspberry-pi-rp2040-programmable-ios-pio/

I'm going to have a little play based on that anyway. You never know, something may come of it eventually. lol There may only be 9 instructions, but the arguments for each seem pretty complex.
Edited 2021-06-27 19:30 by Mixtel90
-- Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 1760
Posted: 12:31pm 27 Jun 2021
Copy link to clipboard 
Print this post

I've taken a very brief look at the datasheet and this looks non-trivial but decidedly doable. However does the C SDK not include an assembler implementation that can be incorporated into the Picomite firmware ? Possibly licensing requirements might make that unpaletable even if it does exist ?

Best wishes,

Tom
CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 789
Posted: 02:56pm 27 Jun 2021
Copy link to clipboard 
Print this post

I have a bit of something. You can change jump conditions and values and see the binary result. It doesn't calculate jumps - that's up to the programmer. I think Set is working too now. It's not trivial, but quite a bit of slog. :)

It's all a bit crude. :)

What does DATA "out y, 1 [5]" do? I thought out y, 1 put 1 into y, but what's the [5] bit?

Took me a while to get a working parser to split up the arguments, but that seems to be ok now. Also added an extra optional argument to the end of each to set the delay time for the instruction.

At the moment the output is a simple single-dimension array.


'PIO assembler - 003

Dim inst$(9)=("jmp","wait","in","out","push","pull","mov","irq","set","end")
Dim op(31) 'this is the output array. bytes 0-31
Dim a$(6) 'arguments for the command

Data "set pins,31,3"
Data "jmp x,1,3"
Data "bitloop: set pins,1"
Data "out y,1 [5]"
Data "end"


ac=0
Do
For i=0 To 6:a$(i)="":Next  'clean the args array
 Read d$                   'get statement
 If d$="end" Then Exit
 p=0                       'point to the first argument array position
 For i=1 To Len(d$)        'parse the statement, putting the arguments into a$()
   t$=Mid$(d$,i,1)
   If (t$<>",") And (t$<>" ") Then a$(p)=a$(p)+t$ Else p=p+1
 Next
 Select Case a$(0)         'process the command
   Case "jmp"
     av=&b0000000000000000
     f1=0
     Select Case a$(1)
       Case "ix":av=av+&b00100000+Val(a$(2))+(Val(a$(3))<<8)
       Case "x":av=av+&b01000000+Val(a$(2))+(Val(a$(3))<<8)
       Case "iy":av=av+&b01100000+Val(a$(2))+(Val(a$(3))<<8)
       Case "y":av=av+&b10000000+Val(a$(2))+(Val(a$(3))<<8)
       Case "x!=y":av=av+&b10100000+Val(a$(2))+(Val(a$(3))<<8)
       Case "pin":av=av+&b11000000+Val(a$(2))+(Val(a$(3))<<8)
       Case "!osre":av=av+&b11100000+Val(a$(2))+(Val(a$(3))<<8)
       Case Else :av=av+&b00000000+Val(a$(1))+(Val(a$(2))<<8)
     End Select
     op(ac)=av
   Case "wai"
     av=&b0010000000000000
   Case "in "
     av=&b0100000000000000
   Case "out"
     av=&b0110000000000000
   Case "pus"
     av=&b1000000000000000
   Case "pul"
     av=&b1000000000000000
   Case "mov"
     av=&b1010000000000000
   Case "irq"
     av=&b1100000000000000
   Case "set"
     av=&b1110000000000000+Val(a$(2))+(Val(a$(3))<<8)
       Select Case a$(1)
         Case "x"
           av=av+&b00100000
         Case "y"
           av=av+&b01000000
         Case "pindirs"
           av=av+&b10000000
         Case "pins"
           av=av+&b00000000
       End Select
       op(ac)=av
 End Select
ac=ac+1
Loop


Print
Restore
p=0
Do
 Read d$
 If d$="end" Then Exit
 Print p,Left$(d$+"           ",20),
 Print Bin$(op(p),16)
 p=p+1
Loop

Edited 2021-06-28 02:17 by Mixtel90
-- Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 833
Posted: 04:55pm 27 Jun 2021
Copy link to clipboard 
Print this post

I thought the [5] meas set bit 5 as a side action.
If nothing goes right ... turn left
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 789
Posted: 05:10pm 27 Jun 2021
Copy link to clipboard 
Print this post

It might do, but the RP2040 datasheet doesn't seem to mention it in the part about the PIO instructions. I might just be bog-eyed. I must admit I haven't read everything and it might be C, which is all foreign to me. :)

I've carried on and I'm down to Push and Pull now. Mov and Irq to go...
-- Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5237
Posted: 05:30pm 27 Jun 2021
Copy link to clipboard 
Print this post

Suggest you watch this  - excellent introduction to PIO and explains side vs delay
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 789
Posted: 06:06pm 27 Jun 2021
Copy link to clipboard 
Print this post

That's very good indeed! And it solved my immediate problem. :)
The [n] bit is working properly now.
No labels yet, of course. That's a "design challenge" for the future. lol

Latest version: PIO assembler wip007.zip
Edited 2021-06-28 04:48 by Mixtel90
-- Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5237
Posted: 06:44pm 27 Jun 2021
Copy link to clipboard 
Print this post

I think we should set some assumed defaults. These can be relaxed as the assembler and the firmware get more sophisticated. I've probably missed some

To start I propose:
1 program per PIO,
program entry address is always 0
no. of statements is always 32 - pad with mov y,y (i.e.NOP)
1 bit for side and 4 bits for delay.
Side will always be allocated to data rather than direction
FIFOs are always 4 in and 4 out
autopull, autopush both off
Pull threshold is 32-bits
optional side-set is off
outshift and in shift directions both default
no H/W interrupts


The PIO init command will need the following:
various pin base no.s and counts
Push threshold (# of bits to satisfy a push)
wrap bottom, wrap top
clock speed
JMP pin
Edited 2021-06-28 04:46 by matherp
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 1760
Posted: 07:41pm 27 Jun 2021
Copy link to clipboard 
Print this post

  Mixtel90 said  ...


   

  Quote  No labels yet, of course. That's a "design challenge" for the future. lol


And directives, and what looks like arbitrary expression evaluation (section 3.3.3, you might be able to lean on MMBasics EVAL function to help with that), traditionally you'd also need some manner of 2nd pass to handle forward jumps to labels. I wasn't trying to be deliberately obtuse when I described this exercise as "non-trivial" and that is why I enquired if the source of the SDK might already contain an implementation, including all the bells and whistles, in C which Peter could just lift.

Best wishes,

Tom
Edited 2021-06-28 05:43 by thwill
CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 789
Posted: 08:01pm 27 Jun 2021
Copy link to clipboard 
Print this post

Like I said, Tom, I'm playing. :)  I've never even considered writing any sort of assembler before. If this thing is of any use whatsoever it'll be a miracle. And I refuse to worry about sorting out jumps and labels - the whole prog will fit on 32 lines of text on your screen or on a single side of A4 paper if you insist on bells & whistles. You can count the jumps. :)

Eh... when I were a lad we programmed Z80 machine code without an assembler at all ...  ;)
-- Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 1760
Posted: 08:23pm 27 Jun 2021
Copy link to clipboard 
Print this post

  Mixtel90 said  Eh... when I were a lad we programmed Z80 machine code without an assembler at all ...  ;)


Z80, you were lucky, we had to make do with a 6502 and if we asked for H&L registers we were sent to bed without any supper.

Actually I missed out on that part of 8-bit computing, but that is a different story.

Best wishes,

Tom
Edited 2021-06-28 06:24 by thwill
CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5237
Posted: 09:30pm 27 Jun 2021
Copy link to clipboard 
Print this post

  Quote  that is why I enquired if the source of the SDK might already contain an implementation


Gosh I would never have thought of that. I just proposed an approach without any research or reading the SDK docs or the chip datasheet or going through the source of PIOASM or watching videos on PIO or googling and reading articles
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 1760
Posted: 10:29pm 27 Jun 2021
Copy link to clipboard 
Print this post

  matherp said  Gosh I would never have thought of that...


Alas Peter I don't know what you think on many issues (or necessarily agree with those thoughts I do know about.) I fear that when they were handing out omniscience I instead asked for a modicum of good manners and a soupscon of mutual respect for those who might offer to do hours of unpaid software development that would help me towards my goals.

I'm sorry,

Tom
Edited 2021-06-28 08:41 by thwill
CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 789
Posted: 06:00am 28 Jun 2021
Copy link to clipboard 
Print this post

I've had a reprieve from something. All jumps in PIO programming are absolute so I've no relative jump calculations to bother about if I get round to adding labels. :)

@matherp
I assume you would like the output array arranged with bit 0 of the first instruction at bit 0 of the first element of the array?
-- Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 833
Posted: 06:33am 28 Jun 2021
Copy link to clipboard 
Print this post

Hi mixtel90,

To make your life easier, you may think of "line numbers" as labels..The ancient Basic way we just left behind. Just start every new instruction with a line number, that is the actual address in the PIO sequencer. 0,1,2,3,4 etc...

Your "compiler" can simply ignore lines that doe not start with a line number.

Or is this a bad idea..?

In a later version you can start thinking about the match to evaluate labels.

Regards,

Volhout

P.S. I will try your pio compiler later today. I am many versions of picomite behind. I am still doing FFT.  

P.P.S. There are some examples of PIO sequencer use on the web. Like the WS2812 driver. That would be simple things to try.
Edited 2021-06-28 16:34 by Volhout
If nothing goes right ... turn left
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 789
Posted: 07:16am 28 Jun 2021
Copy link to clipboard 
Print this post

I'm not sure if it's a bad idea... I'll think about it. The source code is the data statements, of course, and I can simply use a statement like DATA ":alabelname" to get an easy to parse label position, which will relate to the following data statement. That would be easier than parsing a label on the same line as an instruction. A first set of data reads could pick those up and save the addresses in an array.
Hmmm... labels for later. :)

The prog isn't ready for doing anything with yet (not all the commands are there), but by all means have some fun with it. :)  I plan to make some pretty major changes to it today.
-- Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 5237
Posted: 07:29am 28 Jun 2021
Copy link to clipboard 
Print this post

Remember the field$ function - useful for parsing. Check the CMM2 manual for details
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 833
Posted: 07:57am 28 Jun 2021
Copy link to clipboard 
Print this post

Hi Mixtel90,

Nice work Mixtel !!

Tried some different examples from the web in your V07 compiler.
It works correct for the parts implemented.

- the "side" command is not implemented yet
- the [x] value in brackets looks like a timing (how many timer clock ticks) this sequence takes.

I added hex view in the print function, since all examples in the micropython pages is presented as a hex file. Easier to compare the output.

Volhout
If nothing goes right ... turn left
 
     Page 1 of 3    
Print this page
© JAQ Software 2021