Skip to content Skip to navigation

Connexions

You are here: Home » Content » Lab 6: Writing a Flash Driver

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the authors

Recently Viewed

This feature requires Javascript to be enabled.

Lab 6: Writing a Flash Driver

Module by: adrian valenzuela, CJ Ganier

Summary: In this lab we will program a flash memory driver.

In this lab, you will write your first driver for the MSP430. In the previous lab, datasheets were introduced, but there was only a small amount of information needed from the datasheet. In this lab, you will focus on writing a library of functions to provide access to the Flash memory chip on the processor. This chip, Atmel’s AT45DB161B 2Mbit flash memory (www.atmel.com), interfaces with the MSP via the SPI module. In this lab, the serial interface modules will be covered again. The explanation of the flash memory chip is left largely up to the datasheet, but we will provide you with a list of the important information you will need to find. The lab will explain the programming organization behind writing the memory interface. The lab project itself culminates in a working memory interface with the Atmel chip.

In order to understand how to write a programming interface for the Atmel chip, some explanation of what a software library is might be helpful. Our particular library for the Atmel flash chip is going to be a type of driver. You may also find explanations of serial protocols and data sheet interpretation useful.

Exercise 1

The Atmel data sheet outlines the operating conditions and commands of the AT45DB161B. Based on the data sheet, answer the following questions.

  1. Why is the Status Register Read command important for implementing any other commands?
  2. Which USART transfer mode do both the MSPF169 and the AT45DB161B support? Can the MSP or the AT45 support the faster baud rate?
  3. How much faster is the Buffer to Main Memory Page Program without Built-in Erase command than the Buffer to Main Memory Page Program without Built-in Erase command?
  4. Under what kind of usage conditions is the Buffer Write command (without writing to the flash until later) useful? Why would the Main Memory Page to Buffer Compare be similarly useful?
  5. What is the least number of bytes that the flash can erase with a single command? What is the most?
Once you understand the flash chip as a memory and how it will respond to the commands in the data sheet, you have the building blocks needed to implement a useful interface for the chip. At a high level of abstraction, the interface will need to support reading and writing to the chip without requiring that.

Exercise 2

Write the template for your implementation of the following commands in a library for the AT45DB161B. The template should include the input parameters, return value, name of the function, and what the function specifically does to the inputs and outputs. These C functions should aim to be as close to simple executing the command as possible.

  1. Buffer 1 Write
  2. Buffer 2 Write
  3. Buffer 1 to Main Memory with Built in Erase
  4. Buffer 2 to Main Memory with Built in Erase
  5. Read Buffer 1
  6. Read Buffer 2
  7. Read Main Memory through Buffer 1
  8. Read Main Memory through Buffer 2
  9. Status Register Read

Exercise 3

Implement the commands from Exercise 2 in C for the ELEC 226 board, adhering to the templates provided from Exercise 2.

Exercise 4

Using the commands implemented in Exercise 3, implement the following commands. The templates are provided below. These commands are essentially "read" and "write" that hide the implementation details and behavior that this flash memory requires.

read_data

int read_data(char* read_array, int size, int page_address, int byte_address)

parameters:

  • read_array - an array of chars of length size. This array will be written to the flash memory by this function
  • size - the size of the array read_array
  • page_address - the page to be read
  • byte_address - the byte to be read

returns:

  • 0 if the array read_array has been successfully written to the flash memory
  • 1 if the flash memory is busy
  • 2 if any of the parameters are invalid.

write_data

int write_data(char* write_array, int size, int page_address, int byte_address)

parameters:

  • write_array - an array of chars of length size. This array will be written to the flash memory on page page_address and byte byte_address.
  • size - the size of the array write_array
  • page_address - the page to be written
  • byte_address - the byte to be written

returns:

  • 0 if data has been successfully read from the flash memory into the array
  • 1 if the flash memory is busy
  • 2 if any of the parameters are invalid

Comments, questions, feedback, criticisms?

Send feedback