DrPinball
Posts: 57
Joined: Fri May 04, 2012 6:44 pm

SPI

Mon Nov 12, 2012 7:16 pm

Hi

I'm trying to get SPI working under Bare Metal. I'm not able to get anything out of Clock or MOSI and wondered if anyone has had any success?

I've looked at the mailbox get/set for the power and clocks - it looks like the power is on for SPI but I'm not sure which clock I need to be looking at, there isn't an SPI one mentioned (there is an ISP, not sure if this is a typo??)

Any help gratefully received.

Cheers, David.

ggkinthia
Posts: 1
Joined: Tue Sep 04, 2012 6:24 am

Re: SPI

Thu Nov 15, 2012 8:06 am

Hey David,
You might need to have a look at http://microeletroniki.wordpress.com/20 ... interface/

DrPinball
Posts: 57
Joined: Fri May 04, 2012 6:44 pm

Re: SPI

Thu Nov 15, 2012 10:24 pm

Thanks, I got it working now.

However, I need to use DMA to push a lot of data down the SPI channel. I'm not having much luck with this.

Does anyone know if I have to fix up the addresses passed to the DMA controller e.g. for the SPI FIFO should I use 0x7E204004? Do I need to fix up the source memory address to be in the 0xC0000000 range. To do this do I simply add 0xC0000000 to my addresses?

Any help gratefully received.

David.

phil95
Posts: 141
Joined: Wed Sep 12, 2012 8:10 am
Location: Paris

Re: SPI

Fri Nov 16, 2012 8:23 am

In bare metal mode (no OS no LINUX) peripherals address are 0x2000... (cf BCM2835 P 5)
You must replace 0x7e...... by 0x20......
Thus try 0x20204004
Philippe

DrPinball
Posts: 57
Joined: Fri May 04, 2012 6:44 pm

Re: SPI

Fri Nov 16, 2012 9:04 am

I was reading the following from the BCM peripherals pdf - section 1.2.4 page 6...

The peripheral addresses specified in this document are bus addresses. Software directly
accessing peripherals must translate these addresses into physical or virtual addresses, as
described above. Software accessing peripherals using the DMA engines must use bus
addresses.

Software accessing RAM directly must use physical addresses (based at 0x00000000).
Software accessing RAM using the DMA engines must use bus addresses (based at
0xC0000000).


It's suggesting that the DMA engines need bus addresses (0x7Exxxxxx for peripherals, 0xCxxxxxx for memory).

phil95
Posts: 141
Joined: Wed Sep 12, 2012 8:10 am
Location: Paris

Re: SPI

Fri Nov 16, 2012 9:29 am

After re-reading the documentation, I think your parameters are good.
Sorry, I have never used the DMA...
Philippe

DrPinball
Posts: 57
Joined: Fri May 04, 2012 6:44 pm

Re: SPI

Fri Nov 16, 2012 9:33 am

So to convert to 0xCxxxxxxx addresses should I just add 0xC0000000 to my physical address which presumably start from offset 0x00000000?

DrPinball
Posts: 57
Joined: Fri May 04, 2012 6:44 pm

Re: SPI

Fri Nov 16, 2012 9:37 am

I used DexOS example before which doesn't convert the physical addresses for either the source memory address for the DMA, or the address of the DMA Control Block - I'm a bit confused :?

Link to DexOS example: http://www.raspberrypi.org/phpBB3/viewt ... 64#p190764

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: SPI

Fri Nov 16, 2012 5:38 pm

DrPinball wrote:So to convert to 0xCxxxxxxx addresses should I just add 0xC0000000 to my physical address which presumably start from offset 0x00000000?
As I see it, you can consider the top two bits as being the 'bank' of memory as far as the GPU's MMU sees it. The bank you need to be using for DMA is bank 3, so as long as you haven't been doing any funny business with the ARM MMU, you should be able to do

Code: Select all

target = src | 0xc0000000;
which will unconditionally set the top two bits. It's a lot cleaner than simply adding 0xc0000000, and will work with peripheral addresses as well.

That said, I've not buggered about with DMA, so YMMV.

Simon

User avatar
joan
Posts: 14196
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: SPI

Fri Nov 16, 2012 6:54 pm

For what it's worth I or in 0x40000000 to map from physical to bus addresses for DMA. That's from Linux though.

As an aside has anyone got channel 15 to work for DMA? It's the channel at a different address space to the others, but I can't get it to work.

Return to “Bare metal, Assembly language”