adding pitopi (pi to pi) a way to use two raspberry pi boards,
one as the Linux based development plaform and the other to run the bare metal programs taking advantage of the uarts on the boards.
This commit is contained in:
9
README
9
README
@@ -203,3 +203,12 @@ follow the discovery of the chip into uart01, etc. You will need some
|
||||
sort of cross compiler (well maybe a native compiler on a raspberry pi
|
||||
or other arm system). See the build_gcc directory if you cant get
|
||||
the LITE version from codesourcery.com (now mentor graphics).
|
||||
|
||||
UPDATE: I added the baremetal directory, it has a tutorial on one
|
||||
aspect of the things you need to master to do bare metal programming.
|
||||
|
||||
UPDATE: I added the pitopi directory (pi to pi). If you have two
|
||||
Raspberry Pi boards, instead of buying one of the usb to serial or
|
||||
other solutions above you can use one Raspberry Pi as the development
|
||||
platform which already has a uart at the right line levels, and the
|
||||
other Raspberry Pi for running the bare metal programs.
|
||||
|
||||
294
pitopi/README
Normal file
294
pitopi/README
Normal file
@@ -0,0 +1,294 @@
|
||||
|
||||
What is a pit opi? It is actually pi to pi as in a Raspberry Pi running
|
||||
Linux used as a host and a second Raspberry Pi used as a bare metal
|
||||
platform. I will call one the Linux pi and the other the bare metal pi.
|
||||
|
||||
If you look at the top level README there is talk of buying a $15 or
|
||||
so usb to serial (usb to uart) and some wires for connecting your host
|
||||
pc to your bare metal pi for bare metal development, using the
|
||||
bootloader, etc. Well that puts you into a problem of where do I get
|
||||
the tools, I need a toolchain and I need a terminal program with xmodem
|
||||
(to use one of my bootloaders) as well as the usb to uart thing. Well
|
||||
for a little more you can get another Raspberry Pi if you dont already
|
||||
have a second one. You can get Linux up and running on that Linux pi
|
||||
and it has a working arm gnu toolchain compiler as part of the distro.
|
||||
With a little more work (mostly just downloading a few things) and
|
||||
three wires (still need the wires)(maybe two, depends on your comfort
|
||||
level) you gain a development environment where the tools are trivial
|
||||
to come by, and a dumb terminal program with xmodem.
|
||||
|
||||
I am doing this from memory, so hopefully I cover all the steps
|
||||
|
||||
I downloaded Raspian wheezy
|
||||
|
||||
http://www.raspberrypi.org/downloads
|
||||
|
||||
And put it on an sd card
|
||||
|
||||
http://elinux.org/RPi_Easy_SD_Card_Setup
|
||||
|
||||
Plugged in a monitor, keyboard, mouse, and network and the powered
|
||||
that Linux pi from a computer. You want to power both Raspberry Pis
|
||||
from the same power source for example a powered usb hub or the same
|
||||
computer. In theory this way you dont put a large delta between
|
||||
the ground planes on the two boards which could fry something. The
|
||||
odds of this are quite low, but if you happened to get lucky and
|
||||
cross phases, that is about like taking bare wires from wall power and
|
||||
touching those wires on metal parts around the board, some smoke will
|
||||
be released from something. So the Linux pi boots, I get this text
|
||||
menu thing that asks things like do you want ssh enabled do you want
|
||||
to push the filesystem to fill the sd card, stuff like that. After this
|
||||
first bring up I actually dont use the keyboard, mouse, and monitor on
|
||||
the Linux pi I used ssh and/or vnc, personal preference, not going to
|
||||
explain the steps, I assume you are using the Linux pi as a computer
|
||||
with keyboard, mouse and monitor.
|
||||
|
||||
The Linux pi reboots with these settings and I am in I have a Linux
|
||||
based computer.
|
||||
|
||||
Next I made sure I had a few tools:
|
||||
|
||||
apt-get install build-essential
|
||||
apt-get install minicom lrzsz
|
||||
|
||||
You have to be a programmer to be doing or learning bare metal
|
||||
programming so I dont need to tell you about text editors you have
|
||||
one or ones you like and know how to use it or them.
|
||||
|
||||
Now the uart on the Linux pi is by default enabled to be used as the
|
||||
console, it spits out messages on boot, and provides a login prompt.
|
||||
Well I want to use it as a generic uart/serial port and not have it
|
||||
used for that purpose so looking at this page
|
||||
|
||||
http://elinux.org/RPi_Serial_Connection
|
||||
|
||||
I backed up inittab
|
||||
|
||||
cd /etc
|
||||
sudo cp inittab inittab.orig
|
||||
Now edit inittab (using sudo if you are not logged in as root)
|
||||
comment out the T0:23... line they mention which has the ttyAMA0 thing
|
||||
in it, and save
|
||||
|
||||
backup cmdline.txt
|
||||
|
||||
cd /boot
|
||||
sudo cp cmdline.txt cmdline.orig
|
||||
Now edit cmdline.orig I think there were two places where ttyAMA0 were
|
||||
called out. DONT KILL THE WHOLE LINE, just remove the two chunks
|
||||
of non-whitespace that include AMA0.
|
||||
save.
|
||||
|
||||
Now reboot
|
||||
|
||||
sudo reboot
|
||||
|
||||
As mentioned
|
||||
|
||||
cat /proc/cmdline
|
||||
|
||||
and make sure there is no reference to AMA0
|
||||
|
||||
and then
|
||||
|
||||
ps aux | grep ttyAMA0
|
||||
|
||||
You should only see the ps command in the output and no other commands
|
||||
|
||||
Once you have reached this point. Glance at the top level README for
|
||||
this repo. The corner of the board with two rows of pins, about 26 or
|
||||
so pins total. The outer corner pin is pin 2 starting at that pin and
|
||||
counting toward the rca and audio plugs it goes by 2s, 2,4,6,8,10.
|
||||
|
||||
pin 6 is ground
|
||||
pin 8 is TX
|
||||
pin 10 is RX
|
||||
|
||||
For now take one of your wires and connect pin 8 to pin 10 on the Linux
|
||||
pi (we are doing a test, we will connect between the boards later this
|
||||
is connecting two pins on the same board).
|
||||
|
||||
Open a command line/terminal on the Linux pi
|
||||
|
||||
We need to setup minicom one time before we use it (must use sudo or
|
||||
run as root)
|
||||
|
||||
sudo minicom -s
|
||||
|
||||
Now the user interface to minicom is a bit dated and likely very strange
|
||||
in this point and click or touch screen world.
|
||||
|
||||
Using the arrow keys down arrow to Serial port setup and hit enter.
|
||||
|
||||
Along the left side is A B C D E F G, press the A key (does not have
|
||||
to be capital just press a one time) the cursor moves to the end
|
||||
of the A line, the Serial Device. Edit that line using backspace or
|
||||
delete and you want it to have
|
||||
|
||||
/dev/ttyAMA0
|
||||
|
||||
Then press enter one time
|
||||
|
||||
Now press F one time, Hardware Flow Control should change from Yes to NO
|
||||
|
||||
Now press enter one time, this takes you back to the top menu
|
||||
|
||||
Down arrow to Modem and Dialing and press enter one time
|
||||
|
||||
Press A one time
|
||||
|
||||
Press space and I think that will erase the line and put a space then
|
||||
backspace to have nothing on that line (faster than a bunch of backspaces
|
||||
or deletes to erase the line)
|
||||
|
||||
Press enter one time
|
||||
|
||||
Press K one time
|
||||
|
||||
same deal we want to delete that line, then press enter one time
|
||||
|
||||
Press enter one more time to go to the top level menu
|
||||
|
||||
(you can re-enter these submenus as needed to make these changes and can
|
||||
make these changes in any order)
|
||||
|
||||
Down arrow twice to Save setup as dfl (default).
|
||||
|
||||
And then down arrow and select Exit from Minicom. For whatever reason
|
||||
to disable hardware flow control you have to exit minicom then come
|
||||
back for it to actually work. At least on x86 based pcs that is the case.
|
||||
|
||||
So minicom is now ready to use, if all of the above went well you wont
|
||||
need to do that again. With a jumper wire connecting pin 8 to pin 10
|
||||
run minicom (without any options)
|
||||
|
||||
sudo minicom
|
||||
|
||||
Whatever you type you should be able to see on the terminal. If this
|
||||
doesnt work you cannot continue. What is going in is the character
|
||||
is going out the uart (TX) and through the wire then that is looped
|
||||
back into the input (RX) and we can see it. A return here is simply
|
||||
a carriage return without a line feed so when you hit enter it only
|
||||
goes to the beginning of the same line, it does not advance a line
|
||||
like you are used to. Unplug one end of the wire and the echoing of
|
||||
characters should no longer work. Replace the wire and it should work
|
||||
again. I repeat if this doesnt work for you you cannot continue...
|
||||
|
||||
Now very carefully not to short other parts of the boards together, you
|
||||
might want to power off the Linux pi safely and have both of them turned
|
||||
off. Depends on your comfort level. Connect pin 6 on one board to
|
||||
pin 6 on the other board. Connect pin 8 on one board to pin 10 on the
|
||||
other and vice versa so both boards have their pin 8 connected to pin 10
|
||||
on the other board.
|
||||
|
||||
Get my bootloader (bootloader05 for example) and follow the instructions
|
||||
there or in the top level README for putting the files you need including
|
||||
that kernel.img file on A SECOND SD CARD, NOT ON THE LINUX PI SD CARD,
|
||||
THIS GOES ON THE BARE METAL PI SD CARD. You need two sd cards to go
|
||||
with two Raspberry Pis.
|
||||
|
||||
Power on the Linux pi, let it come up completely, open a terminal
|
||||
then run minicom. A trick to save yourself time is to run minicom
|
||||
wherever you have the .bin files you want to load to the bare metal pi
|
||||
this way you dont have to navigate through the directory structure using
|
||||
a confusing and painful text based thing in minicom. The other
|
||||
alternative is to run minicom in some simple place like your home
|
||||
directory then when you build a .bin file to try, copy it to your home
|
||||
directory (putting the .bin file in the same place as minicom was launched)
|
||||
|
||||
sudo minicom
|
||||
|
||||
Now power on the bare metal pi. Sometimes I have to try more than once
|
||||
to get it to come up. DexOS has a config.txt solution for this I simply
|
||||
just try again.
|
||||
|
||||
Once you see some characters then see it every so many seconds send
|
||||
something that looks kind of like garbage, you are ready to download
|
||||
a program.
|
||||
|
||||
Grab blinker01 or something simple like that. Edit the makefile
|
||||
and replace $(ARMGNU)- with nothing
|
||||
|
||||
Such that lines like these:
|
||||
|
||||
blinker01.elf : memmap vectors.o blinker01.o
|
||||
$(ARMGNU)-ld vectors.o blinker01.o -T memmap -o blinker01.elf
|
||||
$(ARMGNU)-objdump -D blinker01.elf > blinker01.list
|
||||
|
||||
Change to this:
|
||||
|
||||
blinker01.elf : memmap vectors.o blinker01.o
|
||||
ld vectors.o blinker01.o -T memmap -o blinker01.elf
|
||||
objdump -D blinker01.elf > blinker01.list
|
||||
|
||||
Save the makefile and run make from a Linux pi command line.
|
||||
|
||||
If you are actually on an arm based Linux (which the linux pi is) it should
|
||||
build just fine. If you try this on your x86 it should fail the asm code
|
||||
in particular will fail to assemble, game over.
|
||||
|
||||
So now you have a .bin file to try, as mentioned above you want it
|
||||
wherever you launched minicom to save yourself some trouble. I am
|
||||
going to assume the filename in question is hello.bin
|
||||
|
||||
Back to the minicom window, it should be getting those weird characters
|
||||
once every so many seconds.
|
||||
|
||||
Press Ctrl-A then press S
|
||||
this should pop up one of those minicom menus with a few upload choices,
|
||||
|
||||
down arrow twice to xmodem and hit enter one time
|
||||
|
||||
Now you have the file selection window of pain. If you took my advice
|
||||
the just hit enter one time It should pop up another thing that says
|
||||
No file selected - enter filename:
|
||||
Now type in
|
||||
hello.bin
|
||||
and press enter one time
|
||||
|
||||
it should then do the download to the bare metal pi, and the
|
||||
program should load and run on the bare metal pi.
|
||||
|
||||
When you want to run another program, pull the usb cable for the
|
||||
bare metal pi (LEAVE THE LINUX PI POWERED). and plug it back in, I find
|
||||
the fat plug on the computer side is easier to pull and replug than
|
||||
the micro-b connector on the rasberry pi itself, YMMV.
|
||||
|
||||
Note that once you have typed in the filename one time in minicom,
|
||||
so long as you dont exit minicom it will be there the next time you
|
||||
run, if you use the same filename for a while the download key sequence
|
||||
becomes
|
||||
|
||||
ctrl-a
|
||||
s
|
||||
down arrow
|
||||
down arrow
|
||||
enter
|
||||
enter
|
||||
enter
|
||||
|
||||
Modify your program
|
||||
compile
|
||||
copy to whever
|
||||
mouse over to minicom
|
||||
power cycle the bare metal pi
|
||||
do the key sequence
|
||||
repeat
|
||||
|
||||
To exit minicom:
|
||||
|
||||
Ctrl-A then Q and press enter to select the default of exiting without
|
||||
reset.
|
||||
|
||||
If your bare metal pi program spits out stuff (the uart## examples)
|
||||
and the text goes off the right side of the minicom window then
|
||||
use Ctrl-a then w to swich to wrap mode, and the text will wrap so you
|
||||
can see all of it.
|
||||
|
||||
Minicom may be clunky but like vi it is available for so many Linux/unix
|
||||
platforms that you can rely on it as a tool in your toolbox, you may
|
||||
not like it but it is always there. Like hyperterm used to be for
|
||||
Windows, but geez, they screwed that up didnt they? Like minicom
|
||||
hyperterm was not the best tool, but for a good many years/versions it
|
||||
was always there.
|
||||
|
||||
Reference in New Issue
Block a user