How to use spi-flash-m25p40 driver?

Robert S. Grimes rsg at alum.mit.edu
Sat Mar 8 00:48:44 UTC 2008


Hi Thomas,

I've got most of the pieces together, in the form of stubs right now, 
for the low-level SPI driver.  I've also got stubs for a Fram driver.  
I'm building these as part of my application, and everything builds 
fine.  But I don't know how to "use" this all, from an application's 
viewpoint.

Here's what I have now, in my main application:

  printf("Starting SPI...\n");
  err = bsp_register_spi();      // This returns okay

This results in the tracking output I've instrumented the spi_init code 
with, so I can see the SPI driver (and of course, the i2c library) is 
being initialized.  But I don't know what's next. 

I've tried this:

  rtems_driver_name_t framInfo;
  rtems_status_code result = rtems_io_lookup_name(name, &framInfo);
  if (result) {
    printf("Can't find %s, error %d\n", name, result);
  } else {
    printf("Found %s device\n", name);
    printf("  name:  %s\n", framInfo.device_name);
    printf("  major: %u\n", framInfo.major);
    printf("  minor: %u\n\nOpening...\n", framInfo.minor);

    result = rtems_io_open(framInfo.major, framInfo.minor, 0);   /* Is 0 
correct here? */
    if (result) {
      printf("Can't open %s, error %d\n", name, result);
    }
  }


This all works, in the sense that no errors are returned, but I'm not 
sure it is correct.  The next step, for example writing, seems way to 
complex - the call to rtems_io_write requires an args pointer, which is 
cast to an rtems_libio_rw_args_t struct, which requires a rtems_libio_t 
struct.  Clearly I'm not going about this in the write way!

So, what do I do to, for example, write and read something simple to the 
Fram device?  Simple pseudo-code is all I need, though I would 
appreciate actual function names.  Obviously, my Fram device driver is 
different from the spi-flash-m25p40 driver, but I can extrapolate 
answers expressed in terms of the spi-flash-m25p40.

This is a long email for what I expect is actually a pretty simple 
answer - I'm sure I'm just missing something!

Thanks, and take care,
-Bob




More information about the users mailing list