#Commodore64 #C64 #RetroComputing #FRANKC64 #Frodo4 #RP2350 #RaspberryPiPico2 #Murmulator #FRANKM2
https://theoasisbbs.com/pico-2-c64-brings-frodo-based-emulation-to-frank-and-murmulator/?fsp_sid=5043
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 #rp2350Poll for a bit of fun. Feel free to boost!
I've got a #RaspberryPiPico project written in #Arduino C. It talks to a Psion SSD and dumps the contents over USB serial. It can (theoretically) act as a full controller to tag an SSD, too.
I feel like I should port it to the proper Pico SDK. But I also know there are other options. And I'm intrigued to know what Fedi would do.
What should I rewrite this firmware in?
PIO on the Raspberry Pi Pico
Every time I’ve started to approach the use of the programmable IO (PIO) subsystem on the RP2040 or RP2350 (as used on the Raspberry Pi Pico), I’ve found myself essentially starting from scratch again and the examples quite opaque to me.
So this time as I’ve worked through it yet again, I’ve decided to write it all down 🙂
Here are some existing tutorials and projects that talk about getting going with the PIO:
Assembling PIO Code
The PIO has its own bespoke micro-instruction set that is very similar to many types of assembly language and it requires its own pio assembler to process it. The basic sequence is as follows:
There are options for writing PIO in both Micropython and Circuitpython, which I have done in the past, but I’m sticking with the C route here. This requires the pioasm to take PIO code and produce a C header file that can then be included in a C project.
To use the RP2040/2350 Arduino environment, it is necessary to process PIO independently and then add the C file to the Arduino project. The Raspberry Pi C/C++ SDK can process PIO files directly as part of the main build.
There is also an option to use hardware SDK functions for dynamic creation of PIO code at runtime. The functions are a series of pio_encode_XX() functions representing the different PIO instructions as listed here: https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#group_pio_instructions
There are two other novel approaches I found so far too:
The first is an online editing environment that creates the required processed PIO related code for the C/C++ SDK or Python which can then be included in your build environment as required.
The second is an alternative run-time approach that uses a range of C macros to allow the “assembling” of PIO code as part of the run-time execution. It does this by directly creating the HEX equivalents of PIO instructions, thereby effectively assembling in the fly. This means that the PIO code can be customised to the specific run-time situation.
At this stage I’m not sure what it gives over using the pio_encode_ SDK functions directly. I do note however there is an equivalent PIO emulator which means this approach will run equally well on real hardware or in emulation. I’ve bookmarked this to come back to at some point.
Running PIO Code
Regardless of how the PIO instructions become code, to use them requires setting up and configuring the PIO state machines at run time as part of a project. A common approach is to include an initialisation function within the PIO code itself that is destined for passing straight through to the C/C++ SDK. This will have access to all definitions used within the PIO code and also allows the appropriate configuration information to remain encapsulated with the code.
But I have to admit I find there is an awful lot of assumed “magic” going on when configuring and getting running PIO programs and state machines. And whilst there are plenty of examples to study, I don’t find that they are written so as to teach. Consequently, I’ve noted the following as “reminders to self” on how to read some of the examples. It doesn’t help that the SDK function list is very long and there are several ways to achieve the same things.
Taking the PIO PWM code from the pico_examples as a starting point (https://github.com/raspberrypi/pico-examples/tree/master/pio/pwm), I’ve added in some comments containing the full function prototypes for some of the calls to make them a bit easier to walk through.
pwm.pio:
;And its associated C code pwm.c:
/**There are a few key things to remember to make sense of these examples:
There is one additional mix of techniques that is worth pulling out here. In the C code the function pio_pwm_set_period() is used to update the PWM period which it has to do by passing it into the SM via the FIFO. It is using some SM manipulation routines and then some inline, run-time PIO code, to achieve this.
void pio_pwm_set_period(PIO pio, uint sm, uint32_t period) {Again some pretty confusing API calls, especially giving this is meant to be an example, but essentially what is going on (I think) is:
Disable the statemachine by using pio_sm_set_enabled(... false).By default anything sent to the FIFO is written to the X register and used to set the duty cycle of the PWM. But this code creates some temporary PIO code to receive the contents of the FIFO and put it into ISR instead. Of course it has to temporarily suspend the execution of the stored PIO code in order to do this.
I really dislike the nomenclature of “set enabled (false)” as an API approach. I’d much prefer to see something like pio_sm_enable() and pio_sm_disable() myself. I suppose they haven’t done this due to the large increase in API functions it creates.
I guess this is personal preference, but I do find that it adds to the opaqueness of much of the example code when it doesn’t read naturally.
So To Recap…
Writing PIO code can be done at build time (from Python or C/C++ using pioasm or an online assembler) or run time (using pio_encode_ functions or maybe APIO).
pioasm bridges the gap between PIO code and C/C++ including creating two magic C/C++ constructs: pwm_program for the code and pwm_program_get_default_config() to return the created PIO configuration.
PIO and SMs can be allocated by the system using a range of “claim” functions. There are 2 PIOs on the RP2040 and 3 on the RP2350, each with its own 32 instruction program memory and each with four state machines.
It can be useful to include an initialisation routine, that configures and starts the PIO program, within the PIO code for use from the C/C++ code using % c-sdk { … %}.
The PIO program is added into the system and given an offset in instruction memory using pio_add_program.
PIO code is very dense and often the functionality cannot be seen from the PIO code itself as it is defined by the PIO configuration – e.g. pins to use, frequency of execution, direction of shifts and so on.
I’ve not touched on it here, but the use of PIO and DMA (direct memory access) often go hand in hand to create completely CPU-free means of getting data in and out of a RP2040/RP2350 system. A really good example of this is Piers Rocks’ OneROM (see this video for a brilliant summary of how this works: https://www.youtube.com/watch?v=Y8RODQZM2HY).
Finally I need to remember that ISR stands for Input Shift Register and not Interrupt Service Routine…
Kevin
#pio #raspberryPiPico #rp2040 #rp2350
A pure Embedded Rust blinky project that runs a WebAssembly Component Model runtime (wasmtime + Pulley interpreter) directly on the RP2350 bare-metal w/ HW capabilities exposed through WIT. - myte...
Lilbits: Samsung Galaxy Z Fold 8 Wide, Razer Blade 16, and more fallout from Chuwi’s processor mixup
Two recent laptops from Chinese PC maker Chuwi that were supposed to ship with AMD Ryzen 5 7430U processors actually had Ryzen 5 5500U chips inside. That means instead of getting a processor with a Zen 3 CPU, customers were getting notebooks with chips featuring AMD’s older Zen 2 architecture.
But the only way to prove this was to actually open up the computer and remove the CPU cooler to look […]
#chuwi #cpuZ #esp32 #foldables #galazyZFold8Wide #gamingLaptop #googleTv #lilbits #mediaStreamer #onn #onn4kPro #pantherLake #picoz89 #razer #razerBlade16 #rp2350 #samsungGalaxyZFold8Wide #z80 Read more: https://liliputing.com/lilbits-samsung-galaxy-z-fold-8-wide-razer-blade-16-and-more-fallout-from-chuwis-processor-mixup/