Defines | Functions | Variables

# flash_lib.h File Reference

This file contains a set of routines to perform flash access. More...

`#include "config.h"`
Include dependency graph for flash_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Defines
#define | FLASH_BLANK_VALUE 0xFF
#define | Flash_read_id1() ( (*boot_flash_read_sig)(0x0000))
| This macro function allows to read device ID1 of the product.
#define | Flash_read_id2() ( (*boot_flash_read_sig)(0x0002))
| This macro function allows to read device ID2 of the product.
#define | Flash_read_id3() ( (*boot_flash_read_sig)(0x0004))
| This macro function allows to read device ID3 of the product.
#define | Flash_read_osccal() ( (*boot_flash_read_sig)(0x0001))
| This macro function allows to read the OSCAL byte of the product.
#define | Flash_read_fuse_low() ( (*boot_flash_read_fuse)(0x0000))
| This macro function allows to read the low fuse byte of the product.
#define | Flash_read_fuse_high() ( (*boot_flash_read_fuse)(0x0003))
| This macro function allows to read device high fuse byte of the product.
#define | Flash_read_fuse_extended() ( (*boot_flash_read_fuse)(0x0002))
| This macro function allows to read extended fuse byte of the product.
#define | Flash_read_lock() ( (*boot_flash_read_fuse)(0x0001))
| This macro function allows to read lock byte of the product.
#define | Flash_write_lb(b) ((*boot_lock_wr_bits)(b))
## Functions
void | flash_wr_byte (Uint32 addr_byte, Uchar value)
| This function allows to write a byte in the flash memory.
Uchar | flash_wr_block (Byte _MemType_ *src, Uint32 dst, U16 n)
| This function allows to write up to 65535 bytes in the flash memory.
void | flash_erase (void)
| This function erases the whole flash memory.
U8 | flash_rd_byte (Uchar farcode *addr)
| This function allows to read a byte in the flash memory.
U16 | flash_rd_word (U16 farcode *addr)
| This function allows to read a word in the flash memory.
## Variables
U8(* | boot_flash_read_sig )(unsigned long adr)
U8(* | boot_flash_read_fuse )(unsigned long adr)
void(* | boot_lock_wr_bits )(unsigned char val)

## Detailed Description

This file contains a set of routines to perform flash access.

- Compiler: IAR EWAVR and GNU GCC for AVR
- Supported devices: ATmega32U4

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file flash_lib.h.

## Define Documentation

#define FLASH_BLANK_VALUE 0xFF

Definition at line 56 of file flash_lib.h.

#define Flash_read_id1 | ( | ) | ( (*boot_flash_read_sig)(0x0000))

This macro function allows to read device ID1 of the product.

Returns:
  word Read value

Definition at line 78 of file flash_lib.h.

#define Flash_read_id2 | ( | ) | ( (*boot_flash_read_sig)(0x0002))

This macro function allows to read device ID2 of the product.

Returns:
  word Read value

Definition at line 86 of file flash_lib.h.

#define Flash_read_id3 | ( | ) | ( (*boot_flash_read_sig)(0x0004))

This macro function allows to read device ID3 of the product.

Returns:
  word Read value

Definition at line 94 of file flash_lib.h.

#define Flash_read_osccal | ( | ) | ( (*boot_flash_read_sig)(0x0001))

This macro function allows to read the OSCAL byte of the product.

Returns:
  word Read value

Definition at line 102 of file flash_lib.h.

#define Flash_read_fuse_low | ( | ) | ( (*boot_flash_read_fuse)(0x0000))

This macro function allows to read the low fuse byte of the product.

Returns:
  word Read value

Definition at line 110 of file flash_lib.h.

#define Flash_read_fuse_high | ( | ) | ( (*boot_flash_read_fuse)(0x0003))

This macro function allows to read device high fuse byte of the product.

Returns:
  word Read value

Definition at line 118 of file flash_lib.h.

#define Flash_read_fuse_extended | ( | ) | ( (*boot_flash_read_fuse)(0x0002))

This macro function allows to read extended fuse byte of the product.

Returns:
  word Read value

Definition at line 126 of file flash_lib.h.

#define Flash_read_lock | ( | ) | ( (*boot_flash_read_fuse)(0x0001))

This macro function allows to read lock byte of the product.

Returns:
  word Read value

Definition at line 134 of file flash_lib.h.

#define Flash_write_lb | ( |  | b ) | ((*boot_lock_wr_bits)(b))

Definition at line 137 of file flash_lib.h.

## Function Documentation

void flash_wr_byte | ( | Uint32 | addr_byte,
|  | Uchar | value
| ) |  |

This function allows to write a byte in the flash memory.

Parameters:

  addr_byte | Address in flash memory to write the byte.
  value | Value to write in the flash memory

Definition at line 75 of file flash_lib.c.

References flash_wr_block().

    {
      Enable_flash();
      flash_wr_block(&value, addr_byte, 1);
      Disable_flash();
    }

Here is the call graph for this function:

Uchar flash_wr_block | ( | Byte _MemType_ * | src,
|  | Uint32 | dst,
|  | U16 | n
| ) |  |

This function allows to write up to 65535 bytes in the flash memory.

This function manages alignement issue.

Parameters:

  *src | Address of data to write.
  dst | Start address in flash memory where write data
  n | number of byte to write

Definition at line 92 of file flash_lib.c.

References FALSE, flash_rd_byte(), flash_rd_word(), LOW, LSB, MSB, and TRUE.

    {
       U16 nb_word, temp16;
       U32 address;
       U32 save_page_adr;
       U8 page_is_blank;

       while(n)  // While there is data to load from src buffer
       {
          page_is_blank=TRUE;
          address=dst-(LOW(dst)%FLASH_PAGE_SIZE); // Compute the start of the page to be modified
          save_page_adr=address; //memorize page addr

          // For each word in this page
          for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
          {
             if(n) //Still some data to load from src
             {
                if(address>=dst) //current address is inside the target range adr
                {
                   MSB(temp16)=(*(U8*)src); //load MSB of word from buffer src
                   src++; n--;
                   if(n) //Still some data to load ?
                   {
                      LSB(temp16)=(*(U8*)src); //load LSB of word from buffer src
                      src++; n--;
                   }
                   else  //only the MSB of the working belong to src buffer
                   {     //load LSB form exisying flash
                      LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
                   }
                }
                else  //current word addr out of dst target
                {     //load MSB from existing flash
                   MSB(temp16)=flash_rd_byte((U8 farcode*)address);
                   if(address+1==dst) // Is LSB word addr in dst range ?
                   {
                      LSB(temp16)=(*(U8*)src);
                      src++; n--;
                   }
                   else // LSB read from existing flash
                   {
                      LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
                   }
                }
             }
             else  //complete page with words from existing flash
             {
                temp16=flash_rd_word((U16 farcode*)address);
             }
             //Load temp buffer
             (*boot_flash_fill_temp_buffer)(temp16,address);
             address+=2;
          }
          address=save_page_adr;
          for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
          {
             if(flash_rd_word((U16 farcode*)address)!=0xFFFF) //Check for Blank page
             {
                page_is_blank=FALSE;
                break;
             }
             address+=2;
          }
          // Now launch prog sequence (with or without page erase)
          address=save_page_adr;
          if(page_is_blank)  { (*boot_flash_prg_page)(save_page_adr); }
          else{(*boot_flash_page_erase_and_write)(save_page_adr);}
          //- First Flash address update for the next page
          address = save_page_adr + FLASH_PAGE_SIZE;
       }
       return TRUE;
    }

Here is the call graph for this function:

void flash_erase | ( | void | ) |

This function erases the whole flash memory.

Definition at line 142 of file flash_boot_lib.c.

References Flash_page_erase.

    {
    #if FLASH_SIZE > 0
      U16 nb_page;

      Enable_flash();
      nb_page=0;
      do {
        Flash_page_erase(nb_page);
        nb_page += FLASH_PAGE_SIZE;
      } while (nb_page<(FLASH_SIZE));
      Disable_flash();
    #endif

    }

U8 flash_rd_byte | ( | Uchar farcode * | addr ) |

This function allows to read a byte in the flash memory.

Parameters:

  *add | Address of flash memory to read.

Returns:
  byte Read value

Definition at line 158 of file flash_boot_lib.c.

Referenced by flash_rd_word(), and flash_wr_block().

    {
      unsigned char temp;

      Enable_flash();
      temp = *addr;
      Disable_flash();
      return temp;
    }

Here is the caller graph for this function:

U16 flash_rd_word | ( | U16 farcode * | addr ) |

This function allows to read a word in the flash memory.

Parameters:

  *add | Address of flash memory to read.

Returns:
  word Read value

Definition at line 190 of file flash_lib.c.

References Union16::b, flash_rd_byte(), and Union16::w.

    {
      Union16 temp;
      Enable_flash();
      temp.b[1] = flash_rd_byte ((Uchar farcode*) addr);
      temp.b[0] = flash_rd_byte ((Uchar farcode*)addr+1);
      Disable_flash();
      return temp.w;
    }

Here is the call graph for this function:

## Variable Documentation

U8(* boot_flash_read_sig)(unsigned long adr)

Definition at line 52 of file flash_lib.c.

U8(* boot_flash_read_fuse)(unsigned long adr)

Definition at line 53 of file flash_lib.c.

void(* boot_lock_wr_bits)(unsigned char val)

Definition at line 57 of file flash_lib.c.