13

I've been doing a lot with Arduino recently. It's very simple because you can directly execute C++ code on it without the need of operating systems or drivers.

I've done some research and AFAIK, you usually install Linux on the Raspberry PI and create python scripts or C++ binaries on it.

Question: Is it possible to run code on it without any operating system, but still being able to use HDMI and SD cards?

m.Alin
  • 10,638
  • 19
  • 62
  • 89
bytecode77
  • 291
  • 1
  • 5
  • 9
  • 3
    You may find it easier to do bare-metal projects on a smaller and less capable, but more completely documented ARM processor. Though watch out for badly implemented, proprietary debug adapters on cheap dev boards - sometimes these get reverse engineered open drivers, or you can buy a real jtag or use a serial bootloader. At least with the pi you should be able to expect good toolchain support. – Chris Stratton Jul 08 '12 at 03:23

5 Answers5

19

Run code on the RaPi without OS: No problem. David Welch has done the grunt work, check his gitub. Basically, you can take the standard startup files and replace the kernel.img with the file you want to run. To avoid the 'SD card dance' you can run a bootloader that receives the image-to-be-run over a serial line. I have added an auto-reboot, so you can run a new image 'hands-off'. If you want to go this route I have some more information.

Run your own bare-metal application and use the screen and SD card: That's a problem. All information is available deep in the Linux sources, and there are persons working on this (check DexOs?), so I assume in a half a year or so this info will be common knowledge. But for now I would say this is probably too much work.

Earlz
  • 3,346
  • 15
  • 46
  • 66
Wouter van Ooijen
  • 48,407
  • 1
  • 63
  • 136
  • I wonder how the CPU can load the kernel from the SD card without the appropriate drivers for the SD card and the file system? – bytecode77 Jul 07 '12 at 18:40
  • 1
    The basic files that you need (and can be downloaded from the RaPi site, alone or as part of a Linux distribution) include a startup file for the GPU. Presumably the GPU has some built-in bootROM that allows it to read the SD, load its code, load the kernel.img, and activate the ARM CPU. – Wouter van Ooijen Jul 07 '12 at 18:57
  • @DevilsChild - many CPU's have basic bootloaders built in, the TI Davinci part I'm working with has a "ROM bootloader" that can work over serial or from SD card. SD cards use a basic SPI interface. – John U Apr 09 '14 at 08:32
5

It's always possible, but you'll have to write your own drivers for the HDMI and the SD-interface, and possibly a file system for the latter too.

stevenvh
  • 145,145
  • 21
  • 455
  • 667
  • 1
    Actually it would be extremely complicated since it's GPU which starts first and then needs to load some Broadcom's binary blobs in order to start the CPU. Also, if I remember correctly, GPU drivers and firmware are closed source too. – AndrejaKo Jul 07 '12 at 17:04
  • Are there drivers available which could be included so it will work? Any idea? – bytecode77 Jul 07 '12 at 17:06
  • @Devils Child I'm not sure how easy it would be or how documented everything is. I think that you may be able to use the existing bootloader to load your own OS image and start the CPU, but then the problem Stevenvh wrote in the answer shows: You'll need to write drivers and most of the documentation for them isn't available. – AndrejaKo Jul 07 '12 at 17:09
  • @DevilsChild - the drivers that exist will most likely be written for a specific OS, and if you want to integrate them in your own software it will need some of its functionality. In the end you'll be writing a (limited) copy of the OS. Also, AndrejaKo indicates that it will be very difficult, and closed source firmware doesn't make things easier. Why don't you want an OS? – stevenvh Jul 07 '12 at 17:12
  • Well, if I just install Debian on it, why would I need a Raspberry at all? Couldn't I just use a VM and install it there? I mainly wanted to do my own proof of concept thing with it so I could say "this is what I've done!". – bytecode77 Jul 07 '12 at 17:19
  • @DevilsChild - Sorry, I don't follow you. What's with the VM? You do mean a Virtual Machine, right? Would you install a VM on the Raspberry? To emulate what? – stevenvh Jul 07 '12 at 17:24
  • I was actually comparing a virtual machine with Linux on it to a Raspberry with Linux on it. The only difference is that the Raspberry is 'cool' in some way. I would really like to create my own UI sort of thing, but with an existing OS as a base, there is no difference to just using a virtual machine. – bytecode77 Jul 07 '12 at 18:12
  • 1
    @DevilsChild the important difference between a single board computer and a VM is that you can place the board somewhere other than the physical location of the machine hosting the VM; also it tends to have better real-world I/O. But VMs, and more specialized emulators or simulators often have an important role, such as letting the software team start work before the hardware exists, or avoiding having them fight over the only prototype board that has been hand-reworked to be functional, or running regression tests without tying up the collection of physical devices... – Chris Stratton Jul 08 '12 at 03:21
4

What they all said, but, the EASIEST path is to run a Linux distro that does what you want and is as minimalist as possible, and then strip off anything that you don't want.

Fairly soon it will stop being Linux and become a bootloader with SD & HDMI support. That is essentially indistinguishable from what you are asking for in all respects except
- it has been extracted from a Linux distro (but is no longer Linux) and
- you didn't do it yourself.

Unless doing it yourself completely is of utter importance this seems like a very logical approach.

Russell McMahon
  • 147,325
  • 18
  • 210
  • 386
3

If you fancy learning some ARM assembly in order to run code directly on the Pi then this tutorial from Cambridge is a great resource:

http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/os/

Matt Lacey
  • 361
  • 2
  • 15
0

If you want to program "Raspberry Pi as Arduino", check out wiringPi. Check out my article at http://www.jating.in/efyarticle/EFYArticle.pdf.

1) I made it look and work like Arduino, by using single cable to do USB-to-serial conversion and provide power to the board as well. so only one usb cable is sufficient just like arduino.

2) I made small utility which when run, will load wiring Pi code over serial line (Actually any text file :-)), compile and execute it.,

If you want you can run it upon every boot by modifying .bashrc file, so every time it boots, it will be waiting for new file. I didn't provide any link of the utility code, but you can find it at http://www.jating.in/efyarticle/

Chetan Bhargava
  • 4,612
  • 5
  • 27
  • 40