Nut/OS  5.0.5
API Reference
stm32_flash.h
Go to the documentation of this file.
00001 #ifndef _STM32_FLASH_H_
00002 #define _STM32_FLASH_H_
00003 /*
00004  * Copyright (C) 2006 by egnite Software GmbH. All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the copyright holders nor the names of
00016  *    contributors may be used to endorse or promote products derived
00017  *    from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00026  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00027  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00028  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00029  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  * For additional information see http://www.ethernut.de/
00033  *
00034  */
00035 
00043 // #define FLASHDEBUG
00044 
00045 /* Define the STM32F10x FLASH Page Size depending on the used STM32 device */
00046 #if defined (STM32F10X_HD) || defined (STM32F10X_CL) || defined (STM32F10X_XL)
00047   #define FLASH_PAGE_SIZE        ((uint16_t)0x800)
00048 #else
00049   #define FLASH_PAGE_SIZE        ((uint16_t)0x400)
00050 #endif
00051 
00052 /* FLASH BANK addresses */
00053 #define FLASH_BANK1_START_ADDR   ((void*)0x08000000)
00054 #define FLASH_BANK1_END_ADDR     ((void*)0x0807FFFF)
00055 
00056 #define FLASH_BANK2_START_ADDR   ((void*)0x08080000)
00057 #define FLASH_BANK2_END_ADDR     ((void*)0x080FFFFF)
00058 
00059 #define FLASH_TOTAL_SIZE         ((uint32_t)ESIG->FLASH_SIZE*1024UL)
00060 #define FLASH_START_ADDR         FLASH_BANK1_START_ADDR
00061 #define FLASH_END_ADDR           ((void*)FLASH_BANK1_START_ADDR+FLASH_TOTAL_SIZE-1)
00062 
00063 /* Mask to calculate with sectors */
00064 #define FLASH_PAGE_MASK          ((uint32_t)0x0FFFFFFF-(FLASH_PAGE_SIZE-1))
00065 #define FLASH_PAGE_OFFS          ((uint32_t)(FLASH_PAGE_SIZE-1))
00066 
00067 /* Nut/OS specific definition for config sector */
00068 /* Assume size of config area is one page */
00069 #ifndef FLASH_CONF_SIZE
00070 #define FLASH_CONF_SIZE FLASH_PAGE_SIZE
00071 #endif
00072 
00073 /* Assume address of config area is last flash sector */
00074 #ifndef FLASH_CONF_SECTOR
00075 #define FLASH_CONF_SECTOR       ((void*)FLASH_BANK1_START_ADDR+FLASH_TOTAL_SIZE-FLASH_PAGE_SIZE)
00076 #endif
00077 
00078 /* Macros for NUTASSERT */
00079 #define IS_FLASH_ADDRESS(a)  ((a>=FLASH_START_ADDR)&&(a<(FLASH_END_ADDR+1)))
00080 #define IS_PAGE_ADDRESS(a)   ((a&FLASH_PAGE_OFFS)==0x00000000)
00081 
00082 
00086 typedef enum
00087 {
00088     FLASH_BUSY          =  1,   
00089     FLASH_COMPLETE      =  0,   
00090     FLASH_ERROR_PG      = -1,   
00091     FLASH_ERROR_WRP     = -2,   
00092     FLASH_LOCKED        = -3,   
00093     FLASH_TIMEOUT       = -4,   
00094     FLASH_BOUNDARY      = -5,   
00095     FLASH_COMPARE       = -6,   
00096 } FLASH_Status;
00097 
00098 /* Internally used functions that should not be accessef by user
00099  * application without exact knowledge of the flash system.
00100  */
00101 extern FLASH_Status FLASH_Unlock( void *addr, size_t len);
00102 extern FLASH_Status Stm32FlashWaitReady(uint32_t Timeout);
00103 extern int Stm32FlashErasePage(void *page);
00104 extern int Stm32FlashWritePage( void *dst, void *src);
00105 
00106 /* FLASH API functions to read and write at any FLASH address and
00107  * in any count of data.
00108  */
00109 extern uint32_t GetTotalFlashSize( void);
00110 extern void* GetFlashEndAddress( void);
00111 extern int Stm32FlashRead( void* dst, void* src, size_t len);
00112 extern int Stm32FlashWrite( void* dst, void* src, size_t len);
00113 
00114 /* Nut/OS specific API functions to read and write configuration data.
00115  */
00116 extern int Stm32FlashParamRead(unsigned int pos, void *data, unsigned int len);
00117 extern int Stm32FlashParamWrite(unsigned int pos, const void *data, unsigned int len);
00118 
00119 #endif /* _STM32_FLASH_H_ */