STM32F439xx HAL User Manual
stm32f4xx_hal_nor.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_nor.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of NOR HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */ 
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32F4xx_HAL_NOR_H
00038 #define __STM32F4xx_HAL_NOR_H
00039 
00040 #ifdef __cplusplus
00041  extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F412Zx) ||\
00046     defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
00047   #include "stm32f4xx_ll_fsmc.h"
00048 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */
00049 
00050 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00051     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00052   #include "stm32f4xx_ll_fmc.h"
00053 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00054 
00055 /** @addtogroup STM32F4xx_HAL_Driver
00056   * @{
00057   */
00058 
00059 /** @addtogroup NOR
00060   * @{
00061   */ 
00062 
00063 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
00064     defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00065     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) ||\
00066     defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
00067 
00068 /* Exported typedef ----------------------------------------------------------*/
00069 /** @defgroup NOR_Exported_Types NOR Exported Types
00070   * @{
00071   */
00072 
00073 /** 
00074   * @brief  HAL SRAM State structures definition  
00075   */ 
00076 typedef enum
00077 {  
00078   HAL_NOR_STATE_RESET             = 0x00U,  /*!< NOR not yet initialized or disabled  */
00079   HAL_NOR_STATE_READY             = 0x01U,  /*!< NOR initialized and ready for use    */
00080   HAL_NOR_STATE_BUSY              = 0x02U,  /*!< NOR internal processing is ongoing   */
00081   HAL_NOR_STATE_ERROR             = 0x03U,  /*!< NOR error state                      */
00082   HAL_NOR_STATE_PROTECTED         = 0x04U   /*!< NOR NORSRAM device write protected   */
00083 }HAL_NOR_StateTypeDef;
00084 
00085 /**
00086   * @brief  FMC NOR Status typedef
00087   */
00088 typedef enum
00089 {
00090   HAL_NOR_STATUS_SUCCESS  = 0U,
00091   HAL_NOR_STATUS_ONGOING,
00092   HAL_NOR_STATUS_ERROR,
00093   HAL_NOR_STATUS_TIMEOUT
00094 }HAL_NOR_StatusTypeDef;
00095 
00096 /**
00097   * @brief  FMC NOR ID typedef
00098   */
00099 typedef struct
00100 {
00101   uint16_t Manufacturer_Code;  /*!< Defines the device's manufacturer code used to identify the memory       */
00102 
00103   uint16_t Device_Code1;
00104 
00105   uint16_t Device_Code2;
00106 
00107   uint16_t Device_Code3;       /*!< Defines the device's codes used to identify the memory. 
00108                                     These codes can be accessed by performing read operations with specific 
00109                                     control signals and addresses set.They can also be accessed by issuing 
00110                                     an Auto Select command                                                   */
00111 }NOR_IDTypeDef;
00112 
00113 /**
00114   * @brief  FMC NOR CFI typedef
00115   */
00116 typedef struct
00117 {
00118   /*!< Defines the information stored in the memory's Common flash interface
00119        which contains a description of various electrical and timing parameters, 
00120        density information and functions supported by the memory                   */
00121 
00122   uint16_t CFI_1;
00123 
00124   uint16_t CFI_2;
00125 
00126   uint16_t CFI_3;
00127 
00128   uint16_t CFI_4;
00129 }NOR_CFITypeDef;
00130 
00131 /** 
00132   * @brief  NOR handle Structure definition
00133   */ 
00134 typedef struct
00135 {
00136   FMC_NORSRAM_TypeDef           *Instance;    /*!< Register base address                        */
00137 
00138   FMC_NORSRAM_EXTENDED_TypeDef  *Extended;    /*!< Extended mode register base address          */
00139 
00140   FMC_NORSRAM_InitTypeDef       Init;         /*!< NOR device control configuration parameters  */
00141 
00142   HAL_LockTypeDef               Lock;         /*!< NOR locking object                           */
00143 
00144   __IO HAL_NOR_StateTypeDef     State;        /*!< NOR device access state                      */
00145 
00146 }NOR_HandleTypeDef;
00147 /**
00148   * @}
00149   */
00150   
00151 /* Exported constants --------------------------------------------------------*/
00152 /* Exported macros ------------------------------------------------------------*/
00153 /** @defgroup NOR_Exported_Macros NOR Exported Macros
00154   * @{
00155   */
00156 /** @brief Reset NOR handle state
00157   * @param  __HANDLE__ specifies the NOR handle.
00158   * @retval None
00159   */
00160 #define __HAL_NOR_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_NOR_STATE_RESET)
00161 /**
00162   * @}
00163   */
00164 
00165 /* Exported functions --------------------------------------------------------*/
00166 /** @addtogroup NOR_Exported_Functions 
00167  *  @{
00168  */
00169 
00170 /** @addtogroup NOR_Exported_Functions_Group1
00171  *  @{
00172  */
00173 /* Initialization/de-initialization functions  ********************************/
00174 HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming);
00175 HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor);
00176 void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor);
00177 void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor);
00178 void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout);
00179 /**
00180   * @}
00181   */
00182   
00183 /** @addtogroup NOR_Exported_Functions_Group2
00184  *  @{
00185  */
00186 /* I/O operation functions  ***************************************************/
00187 HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID);
00188 HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor);
00189 HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
00190 HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData);
00191 
00192 HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
00193 HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize);
00194 
00195 HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address);
00196 HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address);
00197 HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI);
00198 /**
00199   * @}
00200   */
00201   
00202 /** @addtogroup NOR_Exported_Functions_Group3
00203  *  @{
00204  */
00205 /* NOR Control functions  *****************************************************/
00206 HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor);
00207 HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor);
00208 /**
00209   * @}
00210   */
00211   
00212 /** @addtogroup NOR_Exported_Functions_Group4
00213  *  @{
00214  */
00215 /* NOR State functions ********************************************************/
00216 HAL_NOR_StateTypeDef  HAL_NOR_GetState(NOR_HandleTypeDef *hnor);
00217 HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout);
00218 /**
00219   * @}
00220   */
00221     
00222 /**
00223   * @}
00224   */
00225   
00226 /* Private types -------------------------------------------------------------*/
00227 /* Private variables ---------------------------------------------------------*/
00228 /* Private constants ---------------------------------------------------------*/
00229 /** @defgroup NOR_Private_Constants NOR Private Constants
00230   * @{
00231   */
00232 /* NOR device IDs addresses */
00233 #define MC_ADDRESS               ((uint16_t)0x0000)
00234 #define DEVICE_CODE1_ADDR        ((uint16_t)0x0001)
00235 #define DEVICE_CODE2_ADDR        ((uint16_t)0x000E)
00236 #define DEVICE_CODE3_ADDR        ((uint16_t)0x000F)
00237 
00238 /* NOR CFI IDs addresses */
00239 #define CFI1_ADDRESS             ((uint16_t)0x0061)
00240 #define CFI2_ADDRESS             ((uint16_t)0x0062)
00241 #define CFI3_ADDRESS             ((uint16_t)0x0063)
00242 #define CFI4_ADDRESS             ((uint16_t)0x0064)
00243 
00244 /* NOR operation wait timeout */
00245 #define NOR_TMEOUT               ((uint16_t)0xFFFF)
00246    
00247 /* NOR memory data width */
00248 #define NOR_MEMORY_8B            ((uint8_t)0x00)
00249 #define NOR_MEMORY_16B           ((uint8_t)0x01)
00250 
00251 /* NOR memory device read/write start address */
00252 #define NOR_MEMORY_ADRESS1       0x60000000U
00253 #define NOR_MEMORY_ADRESS2       0x64000000U
00254 #define NOR_MEMORY_ADRESS3       0x68000000U
00255 #define NOR_MEMORY_ADRESS4       0x6C000000U
00256 /**
00257   * @}
00258   */
00259 
00260 /* Private macros ------------------------------------------------------------*/
00261 /** @defgroup NOR_Private_Macros NOR Private Macros
00262   * @{
00263   */
00264 /**
00265   * @brief  NOR memory address shifting.
00266   * @param  __NOR_ADDRESS__ NOR base address 
00267   * @param  NOR_MEMORY_WIDTH NOR memory width
00268   * @param  ADDRESS NOR memory address 
00269   * @retval NOR shifted address value
00270   */
00271 #define NOR_ADDR_SHIFT(__NOR_ADDRESS__, NOR_MEMORY_WIDTH, ADDRESS)    (uint32_t)(((NOR_MEMORY_WIDTH) == NOR_MEMORY_16B)? ((uint32_t)((__NOR_ADDRESS__) + (2U * (ADDRESS)))):\
00272                                                                                  ((uint32_t)((__NOR_ADDRESS__) + (ADDRESS))))
00273  
00274 /**
00275   * @brief  NOR memory write data to specified address.
00276   * @param  ADDRESS NOR memory address 
00277   * @param  DATA Data to write
00278   * @retval None
00279   */
00280 #define NOR_WRITE(ADDRESS, DATA)  (*(__IO uint16_t *)((uint32_t)(ADDRESS)) = (DATA))
00281 
00282 /**
00283   * @}
00284   */
00285 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\
00286           STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||\
00287           STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx ||\
00288           STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */
00289 /**
00290   * @}
00291   */ 
00292 
00293 /**
00294   * @}
00295   */
00296 
00297 #ifdef __cplusplus
00298 }
00299 #endif
00300 
00301 #endif /* __STM32F4xx_HAL_NOR_H */
00302 
00303 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/