nixiebunny
Posts: 5
Joined: Thu Apr 04, 2019 4:32 pm
Contact: Website

Run Raspbian on 3 cores, Arduino-ish on fourth core?

Wed Apr 24, 2019 11:52 pm

Like most of you, I want to do high performance real-time things with a Pi, but I also want access to the niceties of an OS.

Would it be possible to have the Raspbian system start running on only three of the four cores, and leave the fourth core for use with all the GPIO stuff? Furthermore, could the Arduino development environment be set up to use that core with all the GPIO things, and a shared memory structure to pass data between the realtime core and the Raspbian system?

This would make a Raspino or something like that, combining the best of both worlds in one low-cost board.

I can't have been the first person to ever think of this.

User avatar
Ultibo
Posts: 154
Joined: Wed Sep 30, 2015 10:29 am
Location: Australia
Contact: Website

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Thu Apr 25, 2019 12:30 am

What you want to do has been asked multiple times before.

Isolating a CPU from Linux is simple enough, search for the ISOLCPUS option and you should find a lot of discussion. Actually making use of that CPU for other things is much more complicated and I don't know if anyone has completely resolved all the issues especially when it comes to sharing hardware and communicating with the Linux kernel itself.

I suspect running the Arduino environment on an isolated CPU might be a big ask, for reference the Ultibo project has a dedicated CPU example that shows how to isolate a CPU from the Ultibo kernel and use it for real time purposes, it's all done in Pascal so probably not what you want but it might help.

EDIT: Actually the maxcpus command line option might be worth looking at as well, I think ISOLCPUS only isolates from the scheduler not from Linux itself.
Ultibo.org | Make something amazing
https://ultibo.org

Threads, multi-core, OpenGL, Camera, FAT, NTFS, TCP/IP, USB and more in 3MB with 2 second boot!

nixiebunny
Posts: 5
Joined: Thu Apr 04, 2019 4:32 pm
Contact: Website

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Thu Apr 25, 2019 3:58 pm

I know about ISOLCPUS and the other things needed to get one core sorta removed form the Linux process soup. It's not perfect, but it's close. There's an issue with not being able to prevent kernel interrupts form executing on the isolated core, which hopefully could be addressed by the very clever kernel programming folks.

The real need is for the Arduino part of the equation, to provide an easy-to-use, widely available development system and runtime framework for that real-time process that's running in the isolated core.

hippy
Posts: 5157
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Thu Apr 25, 2019 8:58 pm

Instead of isolating one core for your Pseudoduino you could feasibly run that in the GPU on the available scalar processor. I'm not entirely sure what access it has to GPIO etc with Linux running and how feasible would likely depend on what you want to do, how much VPU code you'd need to do it.

ghans
Posts: 7855
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Tue Apr 30, 2019 1:56 pm

The most advanced Raspberry/Pseudoduino project i remember is this one:

https://github.com/me-no-dev/RasPiArduino

BUT it does NOT run on bare metal - it runs on top of Linux !

I believe what you want is probably impossible without writing a "Raspberry Pseudoduino"
"standard library" from scratch. How you can integrate that into the Arduino toolchain seems like another can of worms.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Andyroo
Posts: 2916
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Tue Apr 30, 2019 2:04 pm

Why not use a Pi Zero for the Arduino development?

You are trying to restrict a multi-user, multi-process system in ways it really was not designed for (even VMware assigns cores to virtual machines rather than processes) - think about IO / Disk / GPIO - all have to be shared and managed across all cores even if it is just to stop a deadlock.

I would be tempted to use a 3B or 3B+ for the basic Raspbian and add a Zero (possibly via USB Boot) into your stack. At least then you can limit what runs on it to the bare minimum giving you a better stab at a RTOS than the default Raspbian.

One other option - way out there at the mo though is to use Bare Metal Python for any specific tasks. No idea how it will handle real time tasks yet as it seem reasonably new on the Pi.
Need Pi spray - these things are breeding in my house...

hippy
Posts: 5157
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Tue Apr 30, 2019 5:21 pm

I think there's possibly some confusion creeping into things with the OP having mentioned "Arduino".

Can code be run on a specific core of a Pi and can that be dedicated to running code controlling and interacting with I/O ? Ultibo seems to allow that and I am sure it could therefore be done under Raspbian though I have no idea how to do that.

Can the code running on that core interact with code running on other cores ? I would say very probably, though again I have no idea how one would achieve that.

Creating the code to run on that isolated core should be easy enough; it just has to be able to run on an isolated core when it runs, and one needs a means to get it on to that core. Again ... no idea.

Nothing actually "Arduino" there so far, but it's giving the Pi Arduino-like capabilities in the sense of the OP's post as I read it.

The second part of the OP's post seems to suggest using the actual Arduino IDE to create the code which runs on that isolated core and that's likely possible too. I am not convinced it would be necessary, but could see why it might be a nice option to have.

As ghans suggests; that would involve writing a library so when the source code in the Arduino IDE is compiled it produces an executable which can run in the isolated core and the downloader would need to get that executable into the core. RasPiArduino seems to have covered much of that but it would all need to be bashed into shape and probably needs stuff adding.

Another alternative is for the Arduino IDE to produce executables for some other micro or Virtual Micro, download that into the core, and have the isolated core emulate that.

It's all a lot of work but likely worthwhile to some. I'd start with getting a core isolated, running code in that, figuring out how to interact with that core when running. Then move on to how to create code for it, and finally supporting it in the Arduino IDE.

Want someone else to do it ? I'd suggest suggesting a RISC-V emulator running in the isolated core, and propose RISC-V as an Arduino IDE target. See what the 'RISC-V fanboys' can deliver :mrgreen:

User avatar
scruss
Posts: 2228
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Tue Apr 30, 2019 6:54 pm

This is kind of what the BeagleBone was meant to do with its ARM core for Linux and the PRUs for realtime. But you said "low-cost board", though.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

LdB
Posts: 1104
Joined: Wed Dec 07, 2016 2:29 pm

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Tue Apr 30, 2019 11:08 pm

There are commercial products that can do it, I don't know any opensource projects that actually work.
What the OP is asking is to coexist a GPOS + RTOS and searches on that sort of thing would be a start point.

AFAIK there are three ways to go at it
1.) Baremetal Virtualization .. search for which of these works on the Pi .. I think XEN and KVM do.
2.) Core and resource partition .. discussed above and is all about getting linux to play nice.
3.) AMP ... you need an RTOS and LINUX distribution that support the same standard probably OpenAMP

As the OP wants Audrino the connection to RTOS is many of them have audrino libraries such as FreeRTOS
https://www.arduinolibraries.info/libraries/free-rtos
They are also developed enough to be able to communicate with Linux unlike baremetal where you would have to develop it yourself.

There are running demos of 1 & 3 done on the Zynq board but the board is not cheap.

Xilinx has a number of running AMP examples with linux and FreeRTOS talking as AMP cluster .. there are opensource links at bottom as well as links throughout to the xilinx APP note code. It also has examples of baremetal co-existence if you want to go that path.
https://xilinx-wiki.atlassian.net/wiki/ ... Hypervisor

User avatar
Gavinmc42
Posts: 2895
Joined: Wed Aug 28, 2013 3:31 am

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Wed May 01, 2019 12:21 am

A Zero based Arduino?
Well Arduino uses C++.
But what to run it on, the Arm core or the VC4.

If video is not needed can the VC4 be used?

It is already running a ThreadX RTOS.
This is running on one of the Vector Processing Units?
What is the other one doing?

Ultibo is the easiest way I know to play with this, 1, 2, 3 cores doing other stuff?
Keeping it small, run a VM in the core cache?
A Tiny Basic interpreter?

I already use Zeros with code loading via OTP USB booting, this does not even need a SD card.
And I did get he PiCore Linux Kernel booting this way too..

How to do this with Linux? No idea, but I think it is very possible.
And it might be fun to try, or we can wait for Pi4 which will come with a M0 or M4 coprocessor, hint ;)
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Andyroo
Posts: 2916
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Wed May 01, 2019 12:58 am

Have you seen this viewtopic.php?f=29&t=228727

It may give you a clue / starting point.
Need Pi spray - these things are breeding in my house...

LdB
Posts: 1104
Joined: Wed Dec 07, 2016 2:29 pm

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Wed May 01, 2019 3:50 am

There is one glaring error in that post link in that you can disable irq and fiq on a per core basis. There are also a limited number of interrupts you can uniquely direct to each core and handle them individually (I have an example of that on my xRTOS code). The problem is there is a big block of IRQ's that can only be routed to 1 specific core, which AFAIK was the price for the removal of the GIC and putting the standard Pi QA7 crosspoint switch in.

I am guessing the linux handler only disables the interrupts on the one core handling the big block of IRQ's which is what confused the OP in the post.

hippy
Posts: 5157
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Wed May 01, 2019 9:53 pm

ghans wrote:
Tue Apr 30, 2019 1:56 pm
The most advanced Raspberry/Pseudoduino project i remember is this one:

https://github.com/me-no-dev/RasPiArduino

BUT it does NOT run on bare metal - it runs on top of Linux !

I believe what you want is probably impossible without writing a "Raspberry Pseudoduino"
"standard library" from scratch. How you can integrate that into the Arduino toolchain seems like another can of worms.
Thanks for reminding me of RasPiArduino. I had seen it in the past but had never investigated it. It is quite neat for creating 'Arduino Sketches' on Windows which compile down to a .bin file which can execute on a Pi under Raspbian. One of the easiest cross-compilation toolchains I have set-up for using a Pi, bar Python where that's just a case of dragging and dropping .py files.

It is a bit rough round the edges. The compilation throws up a number of warnings so it looks like the 'Arduino/PiDuino libraries' aren't quite compatible with the GCC versions being used, but my Fibo(24) program did run and reported the correct result when run on my Pi 3B.

To turn that into something which can be used to create code which can run on an isolated core I would expect the 'Arduino/PiDuino libraries' have to be modified to do nothing which can't be done within an isolated core.

Turning that into something which could be booted and run bare metal is probably not much more effort on top of that, if that were wanted, though not asked for here.

I am not sure how one would set-up the Arduino IDE on a Pi, but I imagine someone does. After that it should be easy enough to edit the one configuration line to point the IDE to the Pi hosted ARM compilers, and it should equally be able to generate the same .bin files.

So, turns out, the 'Arduino part' is pretty easy, excepting the mods required for isolated core use.

hippy
Posts: 5157
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Run Raspbian on 3 cores, Arduino-ish on fourth core?

Thu May 02, 2019 7:46 pm

As mentioned, I got the RasPiDuino stuff integrated into the Arduino IDE on Windows easily enough but am struggling to make it work with the Arduino IDE on an actual Pi.

There are alternatives. PiDuino is one, an Arduino-style library for the Pi which allows Arduino-style code to be compiled for the Pi at the command line of the Pi -

https://github.com/epsilonrt/piduino

Return to “Bare metal, Assembly language”