13
\$\begingroup\$

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?

\$\endgroup\$
1
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ Jul 8, 2012 at 3:23

5 Answers 5

19
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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? \$\endgroup\$
    – bytecode77
    Jul 7, 2012 at 18:40
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Jul 7, 2012 at 18:57
  • \$\begingroup\$ @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. \$\endgroup\$
    – John U
    Apr 9, 2014 at 8:32
5
\$\begingroup\$

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.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – AndrejaKo
    Jul 7, 2012 at 17:04
  • \$\begingroup\$ Are there drivers available which could be included so it will work? Any idea? \$\endgroup\$
    – bytecode77
    Jul 7, 2012 at 17:06
  • \$\begingroup\$ @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. \$\endgroup\$
    – AndrejaKo
    Jul 7, 2012 at 17:09
  • \$\begingroup\$ @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? \$\endgroup\$
    – stevenvh
    Jul 7, 2012 at 17:12
  • 1
    \$\begingroup\$ @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... \$\endgroup\$ Jul 8, 2012 at 3:21
4
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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/

\$\endgroup\$
0
\$\begingroup\$

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/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.