Well, I still don't know why the overlays aren't working, but I seem to 
have gotten the clocks toggled correctly to avoid a SIGBUS Bus Error.

This code turns on the clocks and waits for them to become stable.  Then it 
reads the SPI0 version register for confirmation.


#include <stdint.h>

#include <unistd.h>

#include <fcntl.h>

#include <sys/mman.h>

#include <stdio.h>
#include <assert.h>


// Hunt these addresses down from ls -al /sys/devices/platform/ocp | grep 
gpio
// You can also pull them from the TI manual (spruh73l.pdf)

#define CM_PER_BASE 0x44E00000
#define CM_PER_SIZE 0x4000

#define CM_PER_SPI0_CLKCTRL 0x4C
#define CM_PER_L4LS_CLKCTRL 0x60



#define MCSPI0_BASE 0x48030000
#define MCSPI0_SIZE 0x00001000


#define MCSPI_REVISION  (0x000)
#define MCSPI_SYSCONFIG (0x110)
#define MCSPI_SYSSTATUS (0x114)

#define MCSPI_SYST      (0x124)
#define MCSPI_MODULCTRL (0x128)


#define MCSPI_CH0CONF (0x12C)
#define MCSPI_CH0STAT (0x130)
#define MCSPI_CH0CTRL (0x134)



int main(int argc, char *argv[])
{
    
    uint8_t volatile * bbCM_PERMap = NULL;
    uint8_t volatile * bbMCSPI0Map = NULL;
    uint32_t ui32tmp = 0;
    uint32_t volatile * ppui32tmp = NULL;
    
    int fd = open("/dev/mem", O_RDWR);

    bbCM_PERMap = mmap(0, CM_PER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, 
fd, CM_PER_BASE);
    assert(bbCM_PERMap != MAP_FAILED);


    *(uint32_t volatile *)(bbCM_PERMap+CM_PER_L4LS_CLKCTRL) = 0x00000002; 
 // Enable L4LS_CLK
    do {
ui32tmp = *(uint32_t volatile *)(bbCM_PERMap+CM_PER_SPI0_CLKCTRL);
sleep(1);
    } while (((ui32tmp >> 16) & 0x00000003) != 0);  // Wait for L4LS_CLK to 
come up
    
    
    *(uint32_t volatile *)(bbCM_PERMap+CM_PER_SPI0_CLKCTRL) = 0x00000002; 
 // Enable SPI0 CLK
    do {
ui32tmp = *(uint32_t volatile *)(bbCM_PERMap+CM_PER_SPI0_CLKCTRL);
sleep(1);
    } while (((ui32tmp >> 16) & 0x00000003) != 0);  // Wait for module to 
come up

    

    bbMCSPI0Map = mmap(0, MCSPI0_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, 
fd, MCSPI0_BASE);
    assert(bbMCSPI0Map != MAP_FAILED);


    ppui32tmp = (uint32_t volatile *)bbMCSPI0Map;
    assert(bbMCSPI0Map == ppui32tmp);
    ui32tmp = *ppui32tmp;  // Read the revision register
    printf("SPI0 Revision: 0x%08x\n", ui32tmp);
    
    

    close(fd);


    return 0;
}


 

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to