Got bare bones graphics working

General programming chat and advice for beginners

58 posts   Page 1 of 3   1, 2, 3
by DexOS » Wed May 30, 2012 6:49 pm
Good news, we (as in Dex and Dave_G_2) have got a bare-bone OS (start of DexOS port) to boot and run our GPIO code and setup the screen res, get buffer address and display a image on the Raspberry PI board.
All using FasmArm (a arm assembler based on fasm).
Its not 100% right yet and a lot more work to do, and so far only S-Video works.
I will post code once i find out why it needs so many tries to mailbox before it works

Here some screenshots
Image
Image
Image
Image
Image

Sorry about the quality, but i will work on that and theres just know info about how to do this, i must of done 1000 sd writes to get this far.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by dom » Wed May 30, 2012 7:43 pm
Good work!
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4042
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by nick.mccloud » Thu May 31, 2012 9:31 pm
Impressive, looking forward to a squint at the code to see how it's done!
User avatar
Posts: 795
Joined: Sat Feb 04, 2012 4:18 pm
by DexOS » Thu Jun 07, 2012 7:08 pm
I have finally got the print function to work with a full array of fonts , plus i have started porting some of the FBasic functions, its so cool running the same code on the R-PI as the x86, other than a different include.
May post a video, as it boots in less than a second 8).

Note: This is all bare metal, no OS, FBasic is a basic like language, that uses fasm macros to hide the asm code and lets you write app in basic that can run on other processors, just by changing a include file and reassembling.

Our biggest hold back on this project is the keyboard, we need to adapt a ps/2 keyboard which Dave_G_2 is working on.
Other option is to code a USB stack, which will take time.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by johnbeetem » Thu Jun 07, 2012 7:18 pm
Great job!

DexOS wrote:Our biggest hold back on this project is the keyboard, we need to adapt a ps/2 keyboard which Dave_G_2 is working on.
Other option is to code a USB stack, which will take time.


It's pretty sad that hacking a PS/2 keyboard is probably easier than getting USB to work.
User avatar
Posts: 942
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Coast
by DexOS » Thu Jun 07, 2012 7:46 pm
johnbeetem wrote:Great job!

DexOS wrote:Our biggest hold back on this project is the keyboard, we need to adapt a ps/2 keyboard which Dave_G_2 is working on.
Other option is to code a USB stack, which will take time.

It's pretty sad that hacking a PS/2 keyboard is probably easier than getting USB to work.

Thanks johnbeetem.
I have been looking into the possibility of using one of those cheap Bluetooth Module sold on ebay.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by DexOS » Sun Jun 10, 2012 9:45 pm
Here are some screen shots of FBasic running on the raspberry pi bare metal, the start of the DexOS port.
Image
Image

Its set at a low res because i am using a old TV to test it, with composite video.
Once i am happy with progress i will move to high res and HDMI .
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by IdleDeveloper » Wed Jun 13, 2012 2:00 pm
EDIT: Apologies Just re-read the entire post and I see you will provide source soon. I will wait patiently until then :)

Wow I'm super impressed.

I have been messing about on my Pi for a few days and I got a tool chain and some code booting bare metal (was about a million times easier than I thought). Big thanks to dewlch67 and his examples from here https://github.com/dwelch67/raspberrypi/.

I'm wondering if you are willing to share how you got video output? There is no documentation (I can find) and from everything I have read so far we aren't getting any (I'm ok with that people have to protect their IP). My ultimate hope is there is some way to just link in a blob and call some functions to get an OpenGL ES context.

I tried messing about with whats in https://github.com/raspberrypi/firmware/tree/master/opt/vc but it looks like those are for people running a Linux distro on their Pi.

I'm about to start breaking apart the Linux kernel until I find what I need but this is going to be slow going as I have no experience with the code base. And may not even yield any valid results.

Any info on how you went about discovering what you needed to do would also provide valuable insight for bare metal noobies like myself.

TL;DR... Can I get an exampe source for making a frame buffer? How did you figure this out?
Posts: 1
Joined: Wed Jun 13, 2012 7:54 am
by DexOS » Wed Jun 13, 2012 3:01 pm
Thanks for your kind words, i am using FasmArm so no tool chain 8-) .

Theres just no info and the linux kernel is a mind field as it links all over the place.
But there is info if you look very deep, i am going to write a full tut, but i myself still need to fully understand some of its secrets.
Example i setup the screen as below, but there may be a case where you do not need to do this, you may just need to get buffer address form a offset at 0x100 plus ?.
But i have not tested that theory, as i only just got my print function working, i will dump stuff to screen and test for this.
I am making some progress, but slowly.
dewlch67 is a good coder and has done some nice demos.
But the basic info to get stuff to screen is here:
* ************************************************************************ *
* **** BCM2835 Specific Stuff **** *
* ************************************************************************ *
* This is where things get interesting (and specific to the BCM2835).
* Most of this was worked out by reading the Linux source code (mostly
* drivers/video/bcm2708_fb.c and arch/arm/mach-bcm2708/) and experimentation.
*
*
* **** Basic procedure to get stuff on screen ****
* The basic procedure to get a frame buffer is:
* 1) Set up a structure with the frame buffer specification (resolution, etc)
* 2) Tell the GPU about this structure by writing to the mailbox
* 3) Wait by reading from the mailbox for the GPU to modify this structure
* 4) Write to the frame buffer at the pointer we got in stage 3
* Only step 4 is required for subsequent writes to the frame buffer. Currently,
* I do not know how to enable the HDMI output, so this will always operate the
* composite, and not the HDMI.
*
*
* **** Mailbox operations ****
* Read/write operatitons on the mailbox consist of transfering data via a
* 32 bit register. 28 bits of this 32 bit register are the data to be sent
* to the receiver, while the lower 4 bits specify the channel (channel 1 is
* the frame buffer, but there are others).
*
* To send data via the mailbox:
* 1) Wait for space in the mailbox
* 2) Write ((data << 4) || channel) to the write register TODO: Make implementation match
*
* To receive data via the mailbox:
* 1) Wait for the mailbox to be non-empty
* 2) Execute a memory barrier
* 3) Read from the read register
* 4) Check the lowest 4 bits of the read value for the correct channel
* 5) If the channel is not the one we wish to read from (i.e: 1), go to step 1
* 6) Return the read value >> 4 TODO: Make implementation match
* Note: This will not work if we're interested in reading from more than one
* channel as it does not handle the reception of other channels' data
*
*
* **** Memory mapped registers ****
* The bus address for the mailbox memory mapped registers is 0x7E00B880.
* This corresponds to an ARM physical address of 0x2000B880 (the address we
* use from the ARM processor, and hence here). We use three registers from
* the mail box:
* - The read register for mailbox 0 at offset 0x00
* - The status register for mailbox 0 at offset 0x1C
* - The write register for mailbox 0 at offset 0x20 (this is actually the read
* register for mailbox 1).
*
*
* **** Notes ****
* - The address of the frame buffer must be at least a multiple of 16 (in
* order to be accurately transmitted in the 28 bits available in the
* mailbox)
* - The 32 bit value we actually send over the mailbox (including the channel)
* is (ADDRESS | 1) where ADDRESS is the address of the structure. This is
* equivalent to sending as the data (ADDRESS >> 4) (remember we do data << 4)
* - This works if we set vwidth = width, vheight = height, x = 0, y = 0.
* - I haven't managaged to make anything but 24 bit depth work, however the
* Linux source seems to use 16 bit?!
* - Sometimes the procedure described to get stuff on the screen doesn't
* work first time. I've hacked around this by repeating until it does work.
* - The two conditions for successfully acquiring a frame buffer are:
* - The data read from the mailbox (with the 4 least significant bits set
* to zero) is 0 (or 1 including the channel)
* - The pointer in the structure is non-zero after the mailbox read
* - Once we have the frame buffer, we can just write to it. The pixels (in
* 24 bit mode) are RGB ordered by y then x coordinate. The address of a
* subpixel is given by: y * pitch + x * 3 + rgb_channel, where rgb_channel
* is 0 for red, 1 for green, and 2 for blue.
Good luck and any ? just ask.
PS: To get to this stage, i have done over 1000 read/writes to SD card, i do not know how much more my R-PI sd slot can take.
Also a big problem R-PI OSDev's have to over come, is keyboard input.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by DexOS » Wed Jun 13, 2012 6:29 pm
Good news for R-PI OSDev's, i have got the hdmi working, so much better graphics :D
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by dwelch67 » Wed Jun 13, 2012 7:50 pm
Once I got a serial bootloader working I didnt have to do too many more sd writes. The arm jtag helped as well. $20 plus or minus should get you a usb to serial and some wires. Jtag is $50 to $80 plus some soldering on the raspi. The address kernel.img loads to cost me several dozen more writes. Nowhere near where you guys are on sd card cycles, but maybe you can capitalize on my bootloader or make your own.

My biggest worry is the raspi sd card slot looks a bit fragile, afraid I am going to break it (yes I have dozens, not thousands but dozens of cycles).

Is there a way to wire up a reset so that I/we dont have to yank the usb to power cycle. I could come up with a switch on a power strip with a usb wall wart thing, but would rather have something on or near the board...

Keep up the good work, I am also interested in the tutorial for general framebuffer info.
Posts: 421
Joined: Sat May 26, 2012 5:32 pm
by DexOS » Wed Jun 13, 2012 9:53 pm
Thanks dwelch67, i have ordered the parts that you suggested (FTDI Basic Breakout - 3.3v) to use Uart, than i can try you "serial bootloader" once its working.
I have the same worries as you with the SD card slot.
I am thinking about making a board with a sd slot at one end and the other end to match a sd card, so that will stay in the R-PI and the slot i added, will take the wear.

I am also working on something so i can use a keyboard, if it works it will be very cool for R-PI OSDev's, as its as a twists to the design .
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by Valandir » Thu Jun 14, 2012 9:09 am
Great work on the graphics. Any clues on getting the HDMI working?

I'm going to attempt the JTAG "mod" tomorrow and see if this JTAG device will work http://www.olimex.com/dev/arm-usb-ocd.html.
Posts: 4
Joined: Fri May 25, 2012 8:53 pm
Location: Cambridgeshire
by rurwin » Thu Jun 14, 2012 9:26 am
DexOS wrote:I am thinking about making a board with a sd slot at one end and the other end to match a sd card, so that will stay in the R-PI and the slot i added, will take the wear.


It's called a micro SD adapter... if those work yet; there was a problem with them but there have been firmware updates since then. If not you could always try a mini SD adapter...
User avatar
Forum Moderator
Forum Moderator
Posts: 2932
Joined: Mon Jan 09, 2012 3:16 pm
by DexOS » Thu Jun 14, 2012 6:02 pm
rurwin wrote:
DexOS wrote:I am thinking about making a board with a sd slot at one end and the other end to match a sd card, so that will stay in the R-PI and the slot i added, will take the wear.


It's called a micro SD adapter... if those work yet; there was a problem with them but there have been firmware updates since then. If not you could always try a mini SD adapter...

Mini SD adapter are know good, even if they work on R-PI, its not easy getting the micro SD out, without taking the adapter out.
I will custom make small PCB with the SD foot print and have a ribbon to a SD card holder.
This will be easier to put a normal SD card in and out.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by rurwin » Thu Jun 14, 2012 9:19 pm
Just a suggestion, but rather than taking the SD connector off, howabout butchering a Micro SD adapter and fixing the extender to that?
User avatar
Forum Moderator
Forum Moderator
Posts: 2932
Joined: Mon Jan 09, 2012 3:16 pm
by gillespie » Fri Jun 15, 2012 1:13 am
@Dex

Excellent work on the framebuffer access! Looking forward to the hdmi secrets. I have a question however: isn't the register at offset 0x20 the write register for mailbox 1 (from owner 0), and nothing to do with mailbox 0 (the definition of ARM_0_MAIL1_WRT in arch/arm/mach-bcm2708/include/mach/arm_control.h would suggest this, nothing else has value ARM_BASE+0x880+0x20)? So we're just reading from box 0 and writing to box 1?

It's not a huge problem, and it makes no difference to your code, but it confused me when trying to understand it, so hopefully this will clear it up for others.

Of course, I may be completely wrong, in which case feel free to shoot me down :D

Thanks,
Tom
Posts: 4
Joined: Fri Jun 15, 2012 12:58 am
by DexOS » Fri Jun 15, 2012 3:57 pm
gillespie wrote:@Dex

Excellent work on the framebuffer access! Looking forward to the hdmi secrets. I have a question however: isn't the register at offset 0x20 the write register for mailbox 1 (from owner 0), and nothing to do with mailbox 0 (the definition of ARM_0_MAIL1_WRT in arch/arm/mach-bcm2708/include/mach/arm_control.h would suggest this, nothing else has value ARM_BASE+0x880+0x20)? So we're just reading from box 0 and writing to box 1?

It's not a huge problem, and it makes no difference to your code, but it confused me when trying to understand it, so hopefully this will clear it up for others.

Of course, I may be completely wrong, in which case feel free to shoot me down :D

Thanks,
Tom

Like i said its very confusing, as from that source its it is, but its also the read address for mailbox 1
The write register for mailbox 0 at offset 0x20 (this is actually the read
register for mailbox 1).

But for now the important thing is it works ;).

And it not a secret, but i want people to want to use my OS because its useful for real time OS, not because the code is useful.
People download linux for the distro not the code.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by jamesh » Fri Jun 15, 2012 4:05 pm
DexOS wrote:
rurwin wrote:
DexOS wrote:I am thinking about making a board with a sd slot at one end and the other end to match a sd card, so that will stay in the R-PI and the slot i added, will take the wear.


It's called a micro SD adapter... if those work yet; there was a problem with them but there have been firmware updates since then. If not you could always try a mini SD adapter...

Mini SD adapter are know good, even if they work on R-PI, its not easy getting the micro SD out, without taking the adapter out.
I will custom make small PCB with the SD foot print and have a ribbon to a SD card holder.
This will be easier to put a normal SD card in and out.


With the uSD cadpater (Kingston) I have here, its pretty easy to get teh uSD in and out without disconnecting the SD adapter.
Soon to be employed engineer - Hurrah! Volunteer at the Raspberry Pi Foundation, helper at PiAcademy September 2014.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11930
Joined: Sat Jul 30, 2011 7:41 pm
by DexOS » Fri Jun 15, 2012 4:12 pm
dwelch67 wrote:Is there a way to wire up a reset so that I/we dont have to yank the usb to power cycle. I could come up with a switch on a power strip with a usb wall wart thing, but would rather have something on or near the board...


I found a great way to power the PI on/off without yanking the plug out (i am using phone charger)
Use a "Remote Controlled Socket" ( i got mine from maplins).
It works great, no more yanking the plug out 8-).
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by DexOS » Fri Jun 15, 2012 4:16 pm
jamesh wrote:With the uSD cadpater (Kingston) I have here, its pretty easy to get teh uSD in and out without disconnecting the SD adapter.

Thanks jamesh, i will try one of those, it would be much easier and neater.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by DexOS » Fri Jun 15, 2012 5:20 pm
DexOS wrote:
jamesh wrote:With the uSD cadpater (Kingston) I have here, its pretty easy to get teh uSD in and out without disconnecting the SD adapter.

Thanks jamesh, i will try one of those, it would be much easier and neater.

Yes i can confirm it works great, just got a 2GB KINGSTON (Class 2), i can get the micro sd in and out without taking adapter out, and it boots my OS fine.

One thing to note: you will need another adapter or a min sd card read/writer, as you need to leave the adapter in the PI as take it out to write to it is pointless.
Lucky i had a usb one.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by aaa801 » Fri Jun 15, 2012 11:32 pm
on the sd rewrites, couldnt you change the / partition pointer to a usb drive?
Posts: 427
Joined: Mon Jun 04, 2012 9:06 pm
Location: Berkshire
by toxibunny » Sat Jun 16, 2012 12:01 am
Image

google 'sd slot extender' :)
note: I may or may not know what I'm talking about...
Posts: 1143
Joined: Thu Aug 18, 2011 9:21 pm
by nick.mccloud » Sat Jun 16, 2012 10:14 am
aaa801 wrote:on the sd rewrites, couldnt you change the / partition pointer to a usb drive?


There is no / partition to point to - the kernel is not Linux but hand coded assembler.

On the Pi, the kernel HAS to be on the SD card - once it's got started it can then look for the rest of the files where ever you tell it to, if it has the code and drivers to do so.
User avatar
Posts: 795
Joined: Sat Feb 04, 2012 4:18 pm