It is currently Fri May 24, 2013 11:35 am

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Examples of code for using the flash
PostPosted: Sun Jan 22, 2012 2:16 am 
Offline

Joined: Sun Jan 22, 2012 2:08 am
Posts: 11
Location: Felton, CA
I'm working on a project to store some data on an at45 flash, and then read it back multiple times.

I've found discussions about several of the various steps in the process, but I'm having a rough time find a "soup to nuts" example.

It would be very helpful to have some sample code where someone writes the contents of one array to flash, then writes the contents of another array to flash, then reads each of them back.


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Sun Jan 22, 2012 2:34 am 
Offline

Joined: Sun Jan 22, 2012 2:08 am
Posts: 11
Location: Felton, CA
Blast, I messed up, the at45 was the device atmel recommends, but the at25 is the one on the board.


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Sun Jan 22, 2012 1:06 pm 
Offline
User avatar

Joined: Wed May 26, 2010 9:46 pm
Posts: 73
Could you tell us the full device mark code? I am not sure BeRTOS has a driver for it.

_________________
Francesco Sacchi - Develer S.r.l.
BeRTOS Developer
http://www.develer.com/ - http://www.bertos.org/


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Mon Jan 23, 2012 9:38 pm 
Offline

Joined: Sun Jan 22, 2012 2:08 am
Posts: 11
Location: Felton, CA
It's the Atmel AT25FS010
Which is another SPI Flash memory.

Datasheet is: http://www.atmel.com/dyn/resources/prod ... oc5167.pdf


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Tue Jan 24, 2012 10:28 am 
Offline
User avatar

Joined: Thu May 27, 2010 8:17 am
Posts: 8
Actually we don't support your flash memory, but I see the code is quietly simple to add it to the driver. If you would like to add this memory, you should modify this file "bertos/drv/flash25.h", adding the definition for you memory, and test it.

Generally most bertos driver had the kfile interface that simplify their use. To use it you should init the spi module, and then init the flash25 driver with it, in code come:

#include <drv/ser.h>
#include <drv/flash25.h>
#include <io/kfile.h>

static Sertia spi_fd;
static Flash25 flash;

void main()
{
/* all init needed */
init();

/* Init and open the spi channel 0 */
spimaster_init(&spi_fd, SER_SPI0);
LOG_INFO("SPI0 init..ok\n");

/* set spi baudrate */
ser_setbaudrate(&spi_fd, 5000000UL);
LOG_INFO("SPI0 set baudrate..ok\n");

/* Init the flash driver over the spi channel */
flash25_init(&flash.fd, &spi_fd.fd);

/* Now we can access to memory using kfile interface */
kfile_write(&flash.fd, "Test", sizeof("Test")); // We write "Test" sting in memory starting from 0 address
kfile_seek(&flash.fd, 1000, KSM_SEEK_SET); // move pointer to address 1000 of memory, now we can read or write from this address
kfile_read(&flash.fd, buf, 10); // read 10 byte from current flash address, and put it into buf.

}

For more info you can consult the bertos sites:
http://www.bertos.org/use/tutorial-fron ... -interface

_________________
| [D]-o Ing. Daniele Basile - asterix@develer.com
| ||}-o Develer S.r.l., R&D dept.
| [B]-o http://www.develer.com - http://www.bertos.org


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Mon Jan 30, 2012 9:14 pm 
Offline

Joined: Sun Jan 22, 2012 2:08 am
Posts: 11
Location: Felton, CA
I've been looking over, and working on implementing the code. In hw_spi.h there are all sorts of macros left as stubs, some of which seem to be required by the initialization macros. Unfortunately, there doesn't seem to be any description at all of what they are supposed to do.

Some of them, like SCK_HIGH() are fairly obvious. I'm guessing that MISO_IN(), turns the MISO line into an input (Master In and so forth), but it isn't actually listed anyplace. Some of them are just used, with the assumption that whoever implements them will be able to correctly guess what they are supposed to do. But if MOSI_OUT() turns MOSI to an output, why is it called after MOSI_LOW() in the initialization routine?


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Tue Jan 31, 2012 11:18 am 
Offline
User avatar

Joined: Wed May 26, 2010 9:46 pm
Posts: 73
It is not an error to set a pin low and then activate the output. This is done so that all pins will get the correct state at once, once switched to output.

This file needs to be reimplemented only if you use the bitbang implementation of the SPI driver. If you use a SPI peripheral of the microcontroller, these pins will be moved by the hardware automatically.

If you want to use the SPI bitbang driver, the macros needs to be reimplemented. The file is generic and some of them may be unused. The macros which end in _IN or _OUT, are meant to switch the corresponding pin to input or to output.

_________________
Francesco Sacchi - Develer S.r.l.
BeRTOS Developer
http://www.develer.com/ - http://www.bertos.org/


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Thu Feb 02, 2012 11:00 pm 
Offline

Joined: Sun Jan 22, 2012 2:08 am
Posts: 11
Location: Felton, CA
I'm getting a better feel for how this all works.
It would be very helpful if I could look at some sample code, preferably of using the spi.
I'm running into an issue with the channel field of the flash25 structure, and seeing an example of how everything works would really help me understand.
The kfile tutorial seems to pretty much explain the advantages of using object oriented code, without actually showing a "soup to nuts" example of it being used.
There are a lot of missing steps that are probably obvious once you've seen things used and have an intuitive understanding.

I think I may have found part of my problem, in that the channel pointer needs to point to the spi kfile structure.


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Fri Feb 03, 2012 3:15 am 
Offline

Joined: Sun Jan 22, 2012 2:08 am
Posts: 11
Location: Felton, CA
I found a discrepancy between flash25.h and the datasheet (doc5167), I haven't tested it yet, but wanted to point it out while it was conveniently in my editor, and this window was in my browser.

/**
* Serial flash opcode commands. Table 4-1 pg 8 doc 5167
*/
typedef enum {
FLASH25_WREN = 0x6, ///< Set write enable latch
FLASH25_WRDI = 0x4, ///< Reset enable write latch
FLASH25_RDSR = 0x5, ///< Read status register
FLASH25_WRSR = 0x1, ///< Write status register
FLASH25_READ = 0x3, ///< Read data from memory array
FLASH25_FAST_READ = 0x0B, // Read Data from Memory array (with dummy cycles)
FLASH25_PROGRAM = 0x2, ///< Program data into memory array
//!!! FLASH25_SECTOR_ERASE = 0x52, ///< Erase one sector in memory array
FLASH25_SECTOR_ERASE = 0x20, // or 0xD7 /< Erase one 4k sector in memory array
FLASH25_BLOCK_ERASE = 0x52, // OR 0xD8 /< Erase one 32k sector in memory array
//!!! FLASH25_CHIP_ERASE = 0x62, ///< Erase all sector in memory array
//!!! FLASH25_RDID = 0x15 ///< Read Manufacturer and product ID !!!
FLASH25_CHIP_ERASE = 0x60, // or 0xC7 /< Erase all sector in memory array
FLASH25_RDID = 0x9F // or 0xAB /< Read Manufacturer and product ID !!!
} Flash25Opcode;


Top
 Profile  
 
 Post subject: Re: Examples of code for using the flash
PostPosted: Fri Feb 03, 2012 10:33 am 
Offline
User avatar

Joined: Wed May 26, 2010 9:46 pm
Posts: 73
ellarsee wrote:
I'm getting a better feel for how this all works.
It would be very helpful if I could look at some sample code, preferably of using the spi.
I'm running into an issue with the channel field of the flash25 structure, and seeing an example of how everything works would really help me understand.
The kfile tutorial seems to pretty much explain the advantages of using object oriented code, without actually showing a "soup to nuts" example of it being used.
There are a lot of missing steps that are probably obvious once you've seen things used and have an intuitive understanding.


Maybe I am missing something but Asterix, a few posts ago, has already supplied a full working example on how to initialize the SPI and the flash memory and how to read/write from it. You do not have to modify the channel field of the flash25 structure, you can use it as an opaque handler which is passed to the generic kfile_* functions.

If you are more specific on what your issues are we can supply better help.

Cheers

_________________
Francesco Sacchi - Develer S.r.l.
BeRTOS Developer
http://www.develer.com/ - http://www.bertos.org/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group