valtonia
Posts: 26
Joined: Wed Jul 04, 2012 9:09 pm

Bare metal OS, DMA reset problem (solved)

Wed Jul 04, 2012 9:22 pm

Hi all,

Hopefully someone can help with this. I'm developing a bare-metal OS for the Raspberry PI. So far it's in the early stages although I have GPIO, Framebuffer (via the TV out), a basic C library (including printf) and some timer stuff, so I can do some useful stuff with it already. I'm working on getting the DMA going, initially to use a blitter for the framebuffer, and have it working of sorts.

Basically, I can DMA transfer from a buffer to the framebuffer, or I can 'funnel' a single (well, 128bits) word into the framebuffer - e.g. to clear the screen. The problem is if I try to reuse the DMA channel, say to set the screen to a different colour, it seems to retain some its previous settings.

Getting more technical now:

I've set up the DMA control block as per the BCM spec. sheet (256bit aligned), and then set the address of this into the DMA controller, set the enable bit and then set the start bit - the DMA then happens. I then try to:
1. Write the end bit to clear the 'ended' status
2. Write the reset bit
3. Disable and re-enable the channel
None of this seems to work. Weirdly, if I put the whole thing in a loop, it starts working the second time around. Its almost like I have to write the control block to the DMA channel multiple times, except after first boot when it works straight away.

Anyone got any ideas? I've tried everything I can think of. I did think it was maybe the compiler optimising something, but all my register accesses happen through volatile pointers. Oh, the L2 cache is disabled in config.txt too.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5182
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Bare metal OS, DMA reset problem

Wed Jul 04, 2012 10:10 pm

@valtonia

Remember any memory addresses the DMA sees should be bus addresses.
That means that start 0x4xxxxxxx when L2 is enabled, and 0xCxxxxxxx when L2 is disabled.
Using 0x0xxxxxxx addresses will give you cache coherency issues.

Also, there's generally no need to reset the DMA.
Just launch the DMA, wait until it tells you it has finished, clear the status bits, and then launch the next (by writing to CBA register).

valtonia
Posts: 26
Joined: Wed Jul 04, 2012 9:09 pm

Re: Bare metal OS, DMA reset problem

Thu Jul 05, 2012 9:55 pm

@Dom

D'Oh! That was it! Thanks.

I don't how many times I must've read this line in DMA section of the technical document without connecting the dots! :roll:

> Beware that the DMA controller is direcly connected to the peripherals. Thus the DMA
controller must be set-up to use the Physical (harware) addresses of the peripherals.

I'd like to think I would have realised in the end, but this was driving me insane.

Cheers!

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Bare metal OS, DMA reset problem (solved)

Thu Aug 02, 2012 10:31 pm

Hows it going valtonia?

valtonia
Posts: 26
Joined: Wed Jul 04, 2012 9:09 pm

Re: Bare metal OS, DMA reset problem (solved)

Fri Aug 03, 2012 8:27 pm

Hi PG,

Things are going well, but slowly - I'd forgotten how much fun coding at this level was. I used to work for a big STB maker and write driver code etc for them. These days I work on web apps but I always wanted to get back into low level stuff.

V.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Bare metal OS, DMA reset problem (solved)

Sun Aug 05, 2012 11:02 pm

I would be interested to give it a whirl when its finished - I'm looking at various bare metal solutions for my balancing robot as it needs a control system that operates as near to real time as possible to stop it falling over!

I am used to PHP / C(++) so hope it will be stupid proof as low level programming makes my head spin!

User avatar
Cycl0ne
Posts: 102
Joined: Mon Jun 25, 2012 8:03 am

Re: Bare metal OS, DMA reset problem (solved)

Mon Aug 06, 2012 8:52 pm

pygmy_giant wrote:I would be interested to give it a whirl when its finished - I'm looking at various bare metal solutions for my balancing robot as it needs a control system that operates as near to real time as possible to stop it falling over!

I am used to PHP / C(++) so hope it will be stupid proof as low level programming makes my head spin!
you can use my baremetal os for htis purpose, it has everything you need and is small enough and fast enough to fit into less than 32kb. it has a highlevel api for you to call, and you decide which modules you need. at the moment there are only 3:
- exec -> Multitask, Interrupts, Messages, Semaphores, Memory,... ~20kb
- timer -> a 100hz timer (sort of alarmclock) and someday also a 0.0001hz Alarmclock, with a function on getting the 1.000.000hz system timer for accurate timings.
- utility -> for some CStr Utils and some Tag Mechanism for implementing in your code.

all 3 take up about ~40kb at the moment. your code can be easily linked to the os and you decide when to startup: single task or multitask. if you need something implemented, just ask.

at the moment im doing the graphics, gui, filesystem, shell thing.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Bare metal OS, DMA reset problem (solved)

Mon Aug 06, 2012 8:56 pm

cool - thanks - I'm assembling hardware atm, but will give it closer look when I start to code...

GPIO / SPI / I2C are my top piorities - I think I should be able to do this in C without any OS modules, but dedicated ones would not hurt....

User avatar
Cycl0ne
Posts: 102
Joined: Mon Jun 25, 2012 8:03 am

Re: Bare metal OS, DMA reset problem (solved)

Mon Aug 06, 2012 9:34 pm

pygmy_giant wrote:cool - thanks - I'm assembling hardware atm, but will give it closer look when I start to code...

GPIO / SPI / I2C are my top piorities - I think I should be able to do this in C without any OS modules, but dedicated ones would not hurt....
yes, im not sure about what your program will look like, but if you have more than 2 programs runing simultanious, you need some program switching part. but we will see ;)

Return to “Bare metal, Assembly language”