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.

▲