News:

Let's find out together what makes a PIC Tick!

Main Menu

Positron Arm Compiler

Started by JonW, Nov 27, 2026, 01:04 AM

Previous topic - Next topic

JonW

Guys  I have been working on this for months. Pure basic to ARM compiler.  Does basic direct to UF2 on RP2354A, Inline asm, PIO, dual-processor interrupt, USB, timers, adc, overclocking, ring-buffered serial and a lot, lot more. Take a look at the help file.
download html, open


Just messing about with it at the moment and don't want to step on Les toes, so when it's a bit more polished I plan to give the source to Les so he can possibly look at adding it. But if you have used the Pico SDK, it's not that easy and should have been made so much simpler like this.  Literally a dozen lines of code direct to UF2 and you have a running program.

JonW

Not sure it shared so i posted the help on the bootloader site HERE

TimB

Very impressive Jon


DaveS

Hats off, brilliant.
DaveS

JonW

Cheers, added WIFI to it now, dev board can run the RMC20452T so built a full wifi stack

Mapo

WOW
same syntax as Positron—wonderful.
Great project, Jon.

Frizie

This is truly incredible.
Huge respect for making this possible.

Quote from: Mapo on Nov 27, 2026, 10:38 PMWOW
same syntax as Positron—wonderful

Maintaining the same syntax as Les' Positron is the biggest plus.
This also makes Wifi easier to access.

And the help file is also very neat and comprehensive, just the way Les does it.

Very, very good job Jon  ;D

Ohm sweet Ohm | www.picbasic.nl

top204

#7
Many thanks Jon.

With your knowledge, and AI for help with the coding, it will be excellently implemented by you.

I look forward to seeing and using it

Best Regards
Les

Dompie

WOW! It's hard to believe you could create something like this for a completely different processor!! Incredible—and the documentation you've already put together is amazing!!!

Question: I found a Raspberry Pi Pico 2 W dev board that appears to have the right components (RP2350 + memory = RP2354A, and a CYW43439 = RMC20452T). Will it work with your compiler? Or is an RP2354A + RMC20452T combination specifically required?
Official Rasberry Pi Pico 2 W link:Rasberry Datasheet

Johan

JonW

#9
Les, no worries, I am adding some other string functions, ifndef, watchdog, second serial port, encryption etc etc.  The wifi stack  can already  run parallel on separate core or on a single with interrupts and fifos for tcp, dchp, udp, web page creation, manual IP and loads of examples of controlling WiFi, plus 50 plus other examples.I am benchmarking to GCC and its already way faster than any other basic compiler for RPI and this produces pure asm.  I still need to work on the optimiser though.

Having read many Ardubloto libraries, the power and simplicity of basic and the PIO really is impressive.  Dma is built and with PIO you can stream custom protocols over WiFi into the tens  of Mbit without hardly touching the dual cores. 

Hope you dont mind me copying the positron syntax, in return, Ill share all the C source files for the compiler, parser, optimiser and IDE with you, plus all examples and C89 gui C for the wifi on PC. I had my Ai go over all the Positron files and its well impresed and has based much on your work.

It already does RP2354A and Pico2/2W, ive not started looking at RP2040 and would rather get it as good as I can before bloating it.  It should port to other vendors Arm cores, the RP2354A is such an underestimated MCU for Less than $1.  It also has embedded flash and is one of the most secure devices on the market now. 

Was a bit of fun, but its turned out to extraordinarily powerful and very capable, ive been feeding other Ai the help files, its seemingly fills a  huge void the Pi guys have missed with the current SDK.  With 30 lines of basic, 1 IDE, direct to UF2, infact if you enable the usb declare, it programs the RP2354A without pushing boot button, you can have a web server.  Copilot was shocked at the efficiency and readability of the basic to true form, that's a credit to you Les!

The power of AI is incredible if used to its potential and carefully guided.  I planned it over a few months, spec sheets and outline architecture but its only taken  4 days to go from spec to 90 percent complete. I also painted 2 bedrooms while the Agents were crunching.... Ridiculous really.

Les, I wont publish it without you seeing it and approving it, I really think it can be sold rather than free and you can have all the proceeds if it goes that way as Positron is your baby.   Ill send you a couple of the dev boards with WiFi fitted soon.

FRIZIE,  the help file was designed in a "similar fashion"  to Les', and to be feed into any simple Ai.  This way a novice can get high end, almost developer standard compiled code in 5 minutes and read it, understand it and alter it.  There is also auto complete in the IDE and I have  similar PPI and def files for the processor datashert registers, instead of meaningless register $0x000000, I detest make files, fragments of C files everywhere, repeated headers, just confusing to the novice and unnecessary imho.


top204

#10
I cannot write the feeling of friendship I have, Jon. :-)

I really look forward to seeing and using it.

Very best regards
Les


JonW

#11
Les,

No worries.

Jx

CPR

What awesome work JonW. 8) This is the proper use of AI and demonstrates how it can be so beneficial when used correctly in this way. Fantastic project! Les, have you tried posting any code snippets to Claude or Gemini just out of curiosity?

JonW

Updated the help and added the register help file.  Extensive string support added and Gui (work in progress) along with Pico2W support HERE

JonW

Fixed the missing help file

Frizie

Jon, at the top of your help page, you have "Current pcb help file" instead of "pbc".
Ohm sweet Ohm | www.picbasic.nl

JonW

#16
HAHA pcb on the brain, cheers

Worked on this a lot today: Unions was a big one, Watchdog, Positron bit manipulation, stress-tested with 5000 lines of code; we are close to GCC on benchmarking, beating it on variables but need another level of optimiser for the FPU.  Overclocking worked on, and some changes to the GUI for auto reload on code change, etc

Example of the bit and byte manipulation


' bits.bas - Positron-style bits and parts of a variable, self-checking
'
'   x.0 .. x.31               one bit, read (0 / 1) or written
'   High x.n / Low x.n        set / clear a bit
'   Toggle x.n                flip a bit
'   x.LowByte  x.HighByte     bytes 0 and 1
'   x.Byte0 .. x.Byte3        any byte (Byte0 = the lowest)
'   x.LowWord  x.HighWord     the two halves of a Dword (also Word0, Word1)
'
' Byte and word parts are read and written straight from memory, as fast
' as a plain variable. On a hardware register High / Low / Toggle and
' "= 0 / = 1" use the RP2350's atomic set / clear / xor addresses.
' Output on the CP2102 COM port (115200), repeated every 5 s.
Device = RP2354A                                            ' the chip on the board
Declare Hserial_Baud = 115200                               ' CP2102 COM port
Declare USB_Driver = On                                     ' F5 reprograms the board without BOOTSEL

Dim Flags As Byte                                           ' 8 flags in one byte
Dim w As Word                                               ' a Word for byte parts
Dim d As Dword                                              ' a Dword for bits and parts
Dim arr[4] As Word                                          ' an array: parts of its elements
Dim n As Byte, bit As Byte                                  ' n = counter, bit = a bit number in a variable
Dim Fails As Byte, Checks As Byte                           ' Fails = failures, Checks = tests run

Structure Rec                                               ' parts work on Structure fields too
    id As Byte                                              ' byte 0
    value As Dword                                          ' bytes 4..7
EndStructure                                                ' end of the record type
Dim r As Rec                                                ' one record

' print one result and compare it with the right answer
Proc Check(what As String, got As Dword, want As Dword)     ' compare, print PASS or FAIL
    Inc Checks                                              ' count tests
    HRSOut what, " ", Hex8 got, " "                         ' show the test and its result
    If got = want Then                                      ' right?
        HRSOut "PASS", 13, 10                               ' pass
    Else                                                    ' wrong
        HRSOut "FAIL - want ", Hex8 want, 13, 10            ' show what it should have been
        Inc Fails                                           ' count it
    EndIf                                                   ' end If
EndProc                                                     ' end of Check

DelayMs 2000                                                ' time for the terminal to reconnect after F5
Main:                                                       ' run the tests every 5 s
    Fails = 0 : Checks = 0                                  ' start the counts
    HRSOut 13, 10, "--- bits and parts ---", 13, 10         ' heading

    ' ---- bits ----
    Flags = 0                                               ' all bits clear
    Flags.3 = 1                                             ' set bit 3
    High Flags.0                                            ' set bit 0
    Check("Flags.3 = 1, High .0", Flags, %00001001)         ' bits 0 and 3 set
    Toggle Flags.7                                          ' flip bit 7 on
    Low Flags.3                                             ' clear bit 3
    Check("Toggle .7, Low .3   ", Flags, %10000001)         ' bit 7 set, bit 3 cleared
    Check("read Flags.7        ", Flags.7, 1)               ' read one bit: 0 or 1
    Check("read Flags.6        ", Flags.6, 0)               ' a clear bit
    bit = 5                                                 ' a bit number in a variable
    Flags.1 = bit                                           ' odd value sets the bit
    Flags.7 = bit - 5                                       ' even value clears it
    Check("Flags.n = variable  ", Flags, %00000011)         ' check it
    If Flags.1 = 1 And Flags.2 = 0 Then                     ' bits as conditions
        Check("If Flags.1 / .2     ", 1, 1)                 ' right
    Else                                                    ' wrong
        Check("If Flags.1 / .2     ", 0, 1)                 ' right
    EndIf                                                   ' end If
    n = 0                                                   ' count the set bits of d
    d = $F0F0000F                                           ' a Dword
    If d.0 = 1 Then Inc n                                   ' bit 0 is 1
    If d.31 = 1 Then Inc n                                  ' bit 31 is 1
    If d.16 = 1 Then Inc n                                  ' bit 16 is 0
    Check("d.0 + d.31 + d.16   ", n, 2)                     ' two of the three
    d.31 = 0                                                ' clear the top bit
    Check("d.31 = 0            ", d, $70F0000F)             ' check it

    ' ---- bytes and words ----
    w = $1234                                               ' a Word
    Check("w.LowByte           ", w.LowByte, $34)           ' low byte
    Check("w.HighByte          ", w.HighByte, $12)          ' high byte
    w.HighByte = $AB                                        ' write one byte of w
    Check("w after .HighByte   ", w, $AB34)                 ' low byte untouched

    d = $12345678                                           ' a Dword
    Check("d.Byte0             ", d.Byte0, $78)             ' byte 0
    Check("d.Byte3             ", d.Byte3, $12)             ' byte 3
    Check("d.HighWord          ", d.HighWord, $1234)        ' high Word
    d.Byte2 = $FF                                           ' write byte 2
    d.LowWord = $BEEF                                       ' and the low Word
    Check("d after Byte2, Low  ", d, $12FFBEEF)             ' check it

    arr[2] = $5566                                          ' parts and bits of array elements
    Check("arr[2].HighByte     ", arr[2].HighByte, $55)     ' part of an array element
    arr[2].LowByte = 1                                      ' write its low byte
    arr[2].15 = 1                                           ' and its top bit
    Check("arr[2] after        ", arr[2], $D501)            ' check it

    r.value = $CAFE0000                                     ' and of Structure fields
    r.value.LowWord = $1234                                 ' write the low Word of a record field
    Check("r.value             ", r.value, $CAFE1234)       ' check it
    Check("r.value.Byte3       ", r.value.Byte3, $CA)       ' a byte of a field
    Check("r.value.3           ", r.value.3, 0)             ' a bit of a field
    Check("r.value.4           ", r.value.4, 1)             ' another bit

    ' ---- a hardware register ----
    ' WATCHDOG_SCRATCH0 is a spare read/write register (bootrom leaves 0-3 alone).
    ' High / Low / Toggle use the atomic set / clear / xor addresses; parts are
    ' read as the whole 32-bit register (registers can only be written whole).
    WATCHDOG_SCRATCH0 = 0                                   ' a hardware register (free scratch: safe to write)
    High WATCHDOG_SCRATCH0.2                                ' atomic set
    High WATCHDOG_SCRATCH0.9                                ' register bit writes use the atomic set alias
    WATCHDOG_SCRATCH0.31 = 1                                ' "= 1" is an atomic set too
    Low WATCHDOG_SCRATCH0.2                                 ' atomic clear
    Toggle WATCHDOG_SCRATCH0.0                              ' atomic xor
    ' check the register
    Check("register bits       ", WATCHDOG_SCRATCH0, $80000201)
    ' a byte of a register: read only
    Check("register .Byte1     ", WATCHDOG_SCRATCH0.Byte1, $02)
    Check("register .9         ", WATCHDOG_SCRATCH0.9, 1)   ' a bit of a register

    If Fails = 0 Then                                       ' the result
        ' every test passed
        HRSOut "ALL PASS (", Dec Checks, " checks)", 13, 10
    Else                                                    ' some failed
        HRSOut Dec Fails, " FAILED", 13, 10                 ' how many
    EndIf                                                   ' end If
    DelayMs 5000                                            ' wait 5 s
    GoTo Main                                               ' and again



charliecoutas

"Impressive" isn't a big enough word for your work Jon. Very good indeed.

Charlie

Craig

Fantastic Work Jon, Absolutely Brilliant!
Craig

JonW

#19
Building an Emulator for it, I had the AI create an ASM emulator to cross-reference the GCC-produced ASM against PBC. For benchmarking, I can reuse it to create a software emulator with breakpoints and a pulseview-type IO tracer with decoders.

EMU.png


' bitbang.bas - serial, I2C and SPI done in software, with other pins toggling
'
' Made for the simulator's Pins page and its decoders (F6, then Pins ->
' Decoders...):  UART  PIN=14 BAUD=9600
'                I2C   SCL=4 SDA=5
'                SPI   SCK=18 MOSI=19 MISO=27 CS=17 MODE=0
' Each pass: LED1 toggles, MARK (GP13) is high round the I2C part, an I2C
' write of register 3 and a read back (repeated start) to the device at $60,
' three SPI bytes with CS low, then "P" and a digit on the soft serial pin.
' The simulator has an I2C device at $60 on GP4 / GP5 (like the board's
' Si5351), so the read must give back what was written: "I2C ok".
'
' On the board: GP4 / GP5 really are the Si5351 (register 3 = output enables,
' so the clock outputs switch on and off), GP16-19 the OLED (not set up, so
' it ignores the bytes), GP13 the FPGA's MODE1 line, GP14 its MCU_IRQ line.
Device = RP2354A
Declare Hserial_Baud = 115200
Declare USB_Driver = On                             ' F5 reprograms the board without BOOTSEL

Symbol LED = GP21                                   ' LED1: toggles every pass
Symbol MARK = GP13                                  ' high round the I2C transfers
Symbol STX = GP14                                   ' soft serial out, 9600 baud
Symbol SCL = GP4                                    ' I2C clock  (pulled up on the board)
Symbol SDA = GP5                                    ' I2C data   (pulled up on the board)
Symbol SCK = GP18                                   ' SPI clock, mode 0: idles low
Symbol MOSI = GP19                                  ' SPI data out
Symbol MISO = GP27                                  ' SPI data in
Symbol CS = GP17                                    ' SPI chip select, active low
Symbol BIT_US = 104                                 ' 1 / 9600 baud = 104 us a bit

Dim i As Byte, v As Byte, ack As Byte
Dim pass As Word, fails As Word

' ---- soft serial: 8 data bits, no parity, 1 stop bit, LSB first
Proc SoftTx(c As Byte)
    Dim k As Byte
    Low STX : DelayUs BIT_US                        ' start bit
    For k = 0 To 7
        If (c & 1) = 1 Then High STX Else Low STX   ' the lowest bit first
        c = c >> 1
        DelayUs BIT_US
    Next
    High STX : DelayUs BIT_US                       ' stop bit (and the line idles high)
EndProc

' ---- I2C, open drain: a line is pulled low (Low = output 0) or let go
' (Input: the pull-up takes it high). About 100 kHz.
Proc I2cStart()                                     ' START, or repeated START
    Input SDA : DelayUs 2                           ' both lines released: high
    Input SCL : DelayUs 5
    Low SDA : DelayUs 5                             ' SDA falls while SCL is high = START
    Low SCL : DelayUs 3
EndProc

Proc I2cStop()
    Low SDA : DelayUs 2
    Input SCL : DelayUs 5
    Input SDA : DelayUs 5                           ' SDA rises while SCL is high = STOP
EndProc

Proc I2cWrite(b As Byte), Byte                      ' send a byte; result 0 = ACK, 1 = NAK
    Dim k As Byte
    For k = 0 To 7
        If (b & $80) <> 0 Then Input SDA Else Low SDA   ' MSB first; SDA changes while SCL is low
        b = b << 1
        DelayUs 2
        Input SCL : DelayUs 5                       ' SCL high: the device reads the bit
        Low SCL : DelayUs 3
    Next
    Input SDA : DelayUs 2                           ' let go of SDA: the device answers
    Input SCL : DelayUs 3
    Result = GetPin(SDA)                            ' low = ACK
    DelayUs 2
    Low SCL : DelayUs 3
EndProc

Proc I2cRead(last As Byte), Byte                    ' read a byte; last = 1: NAK it (the end)
    Dim k As Byte, b As Byte
    Input SDA                                       ' the device drives SDA
    For k = 0 To 7
        DelayUs 2
        Input SCL : DelayUs 3
        b = b << 1
        If GetPin(SDA) = 1 Then b = b | 1           ' read while SCL is high
        DelayUs 2
        Low SCL : DelayUs 3
    Next
    If last = 1 Then Input SDA Else Low SDA         ' NAK the last byte, ACK the others
    DelayUs 2
    Input SCL : DelayUs 5
    Low SCL : DelayUs 3
    Input SDA
    Result = b
EndProc

' ---- SPI mode 0, MSB first: data set while SCK is low, read on the rising edge
Proc SpiXfer(b As Byte), Byte
    Dim k As Byte, r As Byte
    For k = 0 To 7
        If (b & $80) <> 0 Then High MOSI Else Low MOSI
        b = b << 1
        DelayUs 1
        High SCK                                    ' both ends take the bit
        r = r << 1
        If GetPin(MISO) = 1 Then r = r | 1
        DelayUs 1
        Low SCK
    Next
    Result = r
EndProc

' ---- start
High STX                                            ' serial line idles high
Low SCK : High CS : Low MOSI : Input MISO           ' SPI idle
Input SCL : Input SDA                               ' I2C released
Low LED : Low MARK
HRSOut "bitbang.bas - soft serial GP14, I2C GP4/GP5 ($60), SPI GP17-19", 13, 10

Do
    Inc pass
    Toggle LED

    ' I2C: register 3 = the pass number, then read it back
    High MARK
    I2cStart()
    ack = I2cWrite($C0)                             ' address $60, write
    ack = ack + I2cWrite(3)                         ' register pointer = 3
    ack = ack + I2cWrite(pass.LowByte)              ' register 3 = pass
    I2cStop()
    DelayUs 20
    I2cStart()
    ack = ack + I2cWrite($C0)                       ' address $60, write
    ack = ack + I2cWrite(3)                         ' register pointer = 3
    I2cStart()                                      ' repeated START
    ack = ack + I2cWrite($C1)                       ' address $60, read
    v = I2cRead(1)                                  ' one byte, NAK = that's all
    I2cStop()
    Low MARK

    HRSOut "pass ", Dec pass, "  I2C ", Dec ack, " NAKs, read $", Hex2 v
    If ack = 0 And v = pass.LowByte Then
        HRSOut "  I2C ok"
    Else
        Inc fails
        HRSOut "  I2C FAIL"
    EndIf

    ' SPI: three bytes in one CS low
    Low CS
    v = SpiXfer($A5)
    v = SpiXfer($3C)
    v = SpiXfer(pass.LowByte)
    High CS
    HRSOut "  SPI sent A5 3C ", Hex2 pass.LowByte, 13, 10

    ' soft serial: "P" and the last digit of the pass number
    SoftTx("P")
    SoftTx("0" + pass // 10)
    SoftTx(13)
    SoftTx(10)

    DelayMs 5
Loop





The "Master" aka LES now has a copy; this will be interesting to see his reaction. 

▲