RE: https://oldbytes.space/@thelastpsion/116345290344668595
And the results are in!
So, what am I going to do? Well, I'm leaning towards porting the existing Arduino C code to the Pico C SDK. I'm currently using one class for encapsulation and abstraction, but I could replace that with structs and static functions. I'm not a great C programmer, but I'm pretty comfortable with it, so it makes sense
However, before I do that, I see a bigger challenge of getting a good setup without using VS Code. I've been using #NeoVim for a while now, and I'd like to get a comfortable setup using that on #Linux.
So, I'm going to try to build Blinky projects for at least Pico C, Rust and Free Pascal, using Linux and NeoVim. Hopefully this will give me a better feel for how well these languages actually suit me. I've never done any Rust before, either, so that's going to be quite the learning curve!
If I have time, I'm going to give Yarg a go, too, because I think the premise is really cool. If I'm on a roll, I'll try #MicroZig too.
And if I really feel like I have the capacity, I'll port the code to one of these other languages.
I'm acutely aware of all the other projects I've given myself to do, such as the SIBO SDK and other small Psion-related projects, not to mention $dayjob and $reallife. So we'll see how things go!
#Pascal #FreePascal #ObjectPascal #RustLang #YargLang #RaspberryPiPico #PiPico #PiPico2 #RP2040 #RP2350
RE: https://oldbytes.space/@thelastpsion/116345290344668595
Only a couple of hours left for this poll.
C is clearly out in front for my embedded project, but Rust and Pascal aren't far behind!
PIO on the Raspberry Pi Pico – Part 2
Having got all the theory out of the way in PIO on the Raspberry Pi Pico now is the time to actually start programming. Whilst I have the option of using the C/C++ SDK or one of the Python variants, I’m particularly interested in getting it going from within the Arduino environment, just because that is where I do pretty much all of my other microcontroller messing about.
I’m not using the official Arduino for Pico support though, I’m using Earl Philhower’s version from here: https://github.com/earlephilhower/arduino-pico
Pico Arduino Getting Started
Before getting too far into PIO land, there are a few things to note about using the unofficial Arduino Pico core with the Raspberry Pi Pico.
On first boot, hold down the BOOT switch and the Pico will be detected as a “UF2 Board”. This will allow the first upload to take place (more here). I’ve selected “Raspberry Pi Pico” or “Raspberry Pi Pico 2” as appropriate for the board.
Prior to the first download, the configuration should set the Debug Port to Serial. Then once the first sketch is downloaded the board can be redetected via a serial link which will allow both Serial.print() and automatic reset on download of new sketches.
Aside: there are three serial ports (more here):
Here is a simple starter program to make sure everything is working:
void setup() {Assuming everything is working, every second the LED will flash on or off and the counter value will be printed to the serial monitor.
Some PIO API Principles
Pin groups are an important idea when dealing with PIO state machines.
There are four different sets of pins that can be enacted upon via the PIO system: OUT, IN, SET and Sidestep. Each has its own group of API functions. For example, to set the start and number of pins in a specific group there are the following functions (from here):
pio_sm_set_out_pins (PIO pio, uint sm, uint out_base, uint out_count)Oh, and there is a special “jmp” pin too which is kind of a 5th group all on its own, independent of the other four.
This pattern is mirrored for other PIO functions too, for example, the sm_config_ range of functions to update a state machine configuration:
sm_config_set_xxx_pin_base (pio_sm_config *c, uint xxx_base)So each of the pin groups has a set of APIs functions that act directly on the state machine (pio_sm_set_xxx as described first) and a set that acts on a state machine’s configuration (sm_config_set_xxx as described above).
There is also a third set that encodes actual PIO instructions related to the pin groups, although this isn’t a direct one-for-one with the previous two, as it relates to the actual PIO instruction set itself.
Some examples:
pio_encode_in (enum pio_src_dest src, uint count) // in src,cntNote it is worth adding at this point that although there are API functions for all of the above, it is also possible to directly set state machine parameters and operational configuration using direct access to state machine registers. For more, see section “11.7 List of Registers” in the RP2350 datasheet.
Hello PIO
I’m starting off with a simple pulse on a GPIO pin and will be using the online PIO assembler from https://wokwi.com/tools/pioasm to build it.
My PIO Source:
.program pulseThe online assembler turns the above into the following, which is pasted into a pulse_pio.h file within an Arduino sketch.
// -------------------------------------------------- //Adding the appropriate additional PIO initialisation code to my previous test sketch now gives me the following complete code:
#include <PIOProgram.h>Notes:
The PIO and state machine used are allocated dynamically by the system using pio_claim_free_sm_and_add_program(). The first version had hard-coded PIO 0, state machine 0:
PIO pio = pio0;The final result can be seen on the oscilloscope trace below.
Other Interesting PIO API Groups
The PIO hardware documentation describes two modules for PIO APIs:
But there are also the direct state machine APIs which have the form pio_(sm|get|gpio|other)_. These appear to have several functional groups as follows:
Unfortunately there isn’t a particularly consistent API naming convention that I’ve spotted for the pio_ functions apart from an awful lot of them start pio_sm_. Apart from the state machines functions that don’t…
Conclusion
I’ve now been through the theory and a real, albeit simple, application and am feeling like I understand a lot more what is going on now. I still am somewhat bewildered by the huge array of API calls and do feel like they could be grouped together somehow to make them more accessible to people who haven’t swallowed the entire chip datasheet and SDK guidebooks…
But yes, I’m slowly starting to feel like I’m getting to grips with PIO a bit more now. I want to do something that now grabs some input from the GPIO and sticks it into memory, ideally using the DMA system, so that is probably where I’ll go next.
Kevin
#pio #raspberryPiPico #rp2040 #rp2350Simulating the AVR8 for a browser-based Arduino emulator
It has come to my attention that this exists.
https://github.com/tabemann/zeptoforth
I can't update my poll without resetting the results. But, uh, I guess it's an option now?