News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Positron Arm Compiler

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

Previous topic - Next topic

top204

I'm still trying to get my head around it Jon. :-)

Thanks to your help, I now have the ARM toolchain loaded and working, and I have compiled my first example. So now to get a PCB, so I can see things working.

So... My reaction is........ WOW !!!!!!!!!!!!!

Best regards
Les

JonW

Sent you a PM.  Ordered some PICO2W wifi boards and a swd debugger to your house. Ill send the mwave ones next week when im in the lab. The debugger will be useful for a hardware emulator, the software one can do serial, spi,12c, gpio, usb, ethernet using pc sockets, hardware ethernet will use wiz chips.

The full toolchain is not needed and am going to see how we can strip it without breaching the Gnu licensing and redistribution.  We are not changing them so it should be ok as long as we acknowledge and abide by the license.

Ill send you the latest version in the morning with the software emulator.

Glad you like it

Frizie

Jon, consider the following:
HIGH PORTx.x, LOW PORTx.x, and TOGGLE PORTx.x versus PORTx.x = 1, PORTx.x = 0, and PORTx.x = ~PORTx.x

HIGH, LOW and TOGGLE do not just set the state of PORTx.x; they also configure the corresponding port as an output (if it is not already set as such).
The examples using PORTx.x do not do this; they only set the state of PORTx.x.
Therefore, HIGH, LOW and TOGGLE are inefficient commands if you have already defined the ports using TRISx.x.

I am not sure if your compiler behaves this way (though it really should).
Ohm sweet Ohm | www.picbasic.nl

JonW

#23
Hi Frizie

PBC does the same as Positron: High, Low and Toggle also make the pin an output. On the RP2350 it costs almost nothing, and the "state only" version isn't faster. Here are both ways, with the code PBC actually produces.
You need to understand that the ARM GPIO differs from a PIC, so some instructions and commands will not port over directly.
1. High / Low / Toggle

Device = RP2354A
Symbol LED = 21

Output LED                      ' make it an output once

Do
    High LED                    ' set it, and make sure it is an output
    Low LED
    Toggle LED
Loop

PBC output (ARM Thumb-2):

    ldr  r1, =0x00200000        ; pin mask, 1 << 21   } loaded once,
    ldr  r2, =0xD0000000        ; SIO base address     } before the loop
    str  r1, [r2, #0x38]        ; GPIO_OE_SET  (Output LED)
.L1:
    str  r1, [r2, #0x18]        ; GPIO_OUT_SET  - High
    str  r1, [r2, #0x38]        ; GPIO_OE_SET   - ...and output
    str  r1, [r2, #0x20]        ; GPIO_OUT_CLR  - Low
    str  r1, [r2, #0x38]        ; GPIO_OE_SET
    str  r1, [r2, #0x28]        ; GPIO_OUT_XOR  - Toggle
    str  r1, [r2, #0x38]        ; GPIO_OE_SET
    b    .L1

2. "State only": the equivalent of PORTB.0 = 1

Do
    SIO_GPIO_OUT_SET = 1 << LED
    SIO_GPIO_OUT_CLR = 1 << LED
    SIO_GPIO_OUT_XOR = 1 << LED
Loop

PBC output:

.L1:
    ldr  r0, =0x00200000        ; pin mask
    ldr  r3, =0xD0000018        ; address of GPIO_OUT_SET
    str  r0, [r3]
    ldr  r3, =0xD0000020        ; address of GPIO_OUT_CLR
    str  r0, [r3]
    ldr  r3, =0xD0000028        ; address of GPIO_OUT_XOR
    str  r0, [r3]
    b    .L1

Why High / Low / Toggle win on this chip

No read-modify-write. On a PIC, setting TRIS for one pin is a bcf on the whole TRIS register, often with a bank select. The RP2350 has separate write-only registers for set, clear and toggle, for both the pin state (OUT) and the direction (OE). Writing a 1 changes only that pin, in one store. That's atomic, so an interrupt can't catch it half-done.
Each of those stores is about one clock, roughly 7 ns at 150 MHz. That's because the SIO block sits on the core's own single-cycle bus, not out on the peripheral bus. So the "make it an output" part of High is one extra 7 ns store.
The compiler puts the pin mask and the SIO base address in registers once, before the loop, so every High, Low or Toggle inside it is just two stores. All the stores share one base address and differ only in offset (#0x18, #0x20, #0x28, #0x38).
The "state only" version has to load each register's address before writing to it. That's 8 instructions per loop against 7, and the four loads each take longer than a store. So on this chip, PORTx.x = 1 style is the slower of the two.

So the advice for Positron on a PIC (set TRIS once and write to the port or latch directly) doesn't carry over to PBC on the RP2350. Use High, Low and Toggle.

The instruction counts (SEVEN against EIGHT) are exact. The one-clock store and the timing claims are from the Cortex-M33 and RP2350 documentation; I haven't measured them on the board.

top204

Many thanks Jon.

Sorry for the sparse feedbacks, but I still cannot get my head around the fact that someone is actually helping me so much, and not doing it for a secondary reason.

Throughout my working life, I have been used more often than helped.

If it all works out, I will be using the PBC as the backend of the Positron_Arm compiler, so that backward compatibility is as close to 100% as possible, and I can also integrate the preprocessor and loader and IDE etc...

It also means the Positron_Arm compiler can pick up syntax errors and relay them to the excellent 3rd party IDEs that have been written for them.

Best regards
Les

JonW

Sounds perfect, Les. Glad to help out and it makes me feel good. Plus, you know I have been pushing for an ARM compiler like Positron and some other C-style commands (Structs, unions, string functions, USB, ETH, etc.).

I've sent you the latest version, which includes all the Ethernet and USB test and measurement classes and 60 demos. The IDE is built in C89 and colours the Procs too.  There is a demo or a USBTMC-SCPI-ETHERNET bridge in there.  I did this in C, and it was 90k, and PBC is 23k.  60 lines of BASIC for a full USBTMC SCPI BRIDGE, pretty impressive

Simulator is working too!


trastikata

Les, Jon,

I don't know if it is possible or it would make sense, but the advanced AI that Jon has access to could run the actual Positron8/16 source (or test part of it) and could advise on possible anomalies.

The high end paid AI got so advanced in coding and analysis that I think if there's any potential anomaly it will catch it. It doesn't mean you have to trust it blindly and the pointed possible anomaly should be verified, but in my experience - it is rarely wrong with code analysis - sometimes inefficient but almost never wrong.

This could make the excellent Positron8/16 better even better, just a thought.

Best regards,
D

JonW

Hi Dyanko

This is exactly what I said to Les in a PM: if he can generate enough from this initial version, it could raise the funds to pay for it; I can also share the tools and know-how to get the most out of it, so the cost is as low as possible. Then, as you say, the sky is the limit.  I am 100 per cent convinced that AI can write and test the current compiler with ease.  On the PBC, it runs hundreds of thousands of regressive steps and precompiles, emulating the cores down to the ASM and register level.

J

▲