
Low Level Programming of the Raspberry Pi in C (2013) - mountainplus
http://www.pieter-jan.com/node/15
======
edoo
If you need a little bit more determinism the beaglebone has a PRU
(programmable realtime unit), a separate processor that can pass data back and
forth to the main RAM.

[http://beagleboard.org/pru](http://beagleboard.org/pru)

I was able to use one to read in an 8 bit parallel bus at around 8MHz without
having to build a separate board with appropriate MCU.

~~~
mikepurvis
Had a quick scroll through the docs there, thanks for the link! One thing
that's not clear to me is the degree to which the PRU has register-controller
peripheral modules like an MCU, or are you essentially bit-banging everything
(which definitely has its appeal after the hours you can spend wrangling with
the stupid timers and DMAs on a CM3).

How is the community? Are there ready to go modules for common tasks like
actively rectified H-bridge control, CANbus control, etc? (I know the
processor itself can do CAN too, but say I have a hard realtime requirement on
my CAN network...)

~~~
edoo
It is basically a raw MCU without any peripherals. I think the main purpose is
so you can implement just about any basic peripheral and novel ideas in code,
so it is essentially a bit bang but like most MCUs you can read/set an entire
IO bank in one go. Since it is separate and basically deterministic except for
some ram latency jitter whatever you implement that works should be as solid
as any purpose built peripheral. It takes some assembly though. It is
absolutely great for basic IO stuff that an arduino class MCU could do where
the bandwidth is too high for dealing with the GPIOs with standard linux
scheduler latency.

I played with it a couple years ago and the community appeared small, but it
is straight forward enough that the examples and docs are likely all you need.
I bet the community is stronger but it isn't going to be on stack exchange.

~~~
rcxdude
Yeah, they are excellent for bit-banging protocols, which is really handy if
you come across some weird digital interface. I've used it for interfacing
with a scanner head, which is a fairly quirky parallel interface.

------
jsd1982
Sure it's low level in that you're poking at physical memory registers, but to
me, low level in this context (thinking microcontrollers) means replacing the
Linux kernel binary with your own application that does its own direct memory
poking.

~~~
jacquesm
Low level: directly accessing hardware. To immediately equate low level with
'you need to roll your own kernel' is a redefinition of terms that makes no
sense to me. After all, even a Linux device driver still makes use of all the
facilities the kernel provides and yet it is _definitely_ low level
programming.

------
sansnomme
There used to be one in Rust but it seems that this year it reverted back to
C.

[https://www.reddit.com/r/rust/comments/7pymd9/stanford_cs140...](https://www.reddit.com/r/rust/comments/7pymd9/stanford_cs140e_operating_systems_writing_a/)

------
codewritinfool
Check out ultibo.org It is Pascal, not C, but runs down on bare metal.

------
SomaticPirate
Is there a Raspberry PI emulator that exists that I could test my code on
before attempting to load it onto the device?

~~~
torstenvl
I use the pre-built image from Azeria Labs. It's a Linux VM with QEMU set up
for Pi/Raspian out of the box.

[https://azeria-labs.com/arm-lab-vm/](https://azeria-labs.com/arm-lab-vm/)

~~~
pm215
Those instructions are not using QEMU to emulate the Pi. They tell QEMU to
emulate an entirely different piece of hardware (the versatilepb board) and
run the raspbian userspace on it. You certainly won't be able to test any code
for the Pi that directly accesses the hardware like that. (QEMU does have some
limited real rpi emulation support, but those instructions don't use it.)

------
cpoile
Is this the kind of thing that might be good for a kid (9) to learn as a first
step into real CS?

------
jihadjihad
Very cool! Has anyone seen a Rust equivalent of something like this?

~~~
glenda
I came across this [1] a while ago. I haven't spent any time reading it yet so
I can't exactly recommend it, but it seems pretty good.

[1] [https://github.com/rust-embedded/rust-raspi3-OS-
tutorials](https://github.com/rust-embedded/rust-raspi3-OS-tutorials)

