mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
149:156823d33999
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**************************************************************************//**
<> 149:156823d33999 2 * @file fmc.c
<> 149:156823d33999 3 * @version V3.00
<> 149:156823d33999 4 * $Revision: 7 $
<> 149:156823d33999 5 * $Date: 15/08/11 10:26a $
<> 149:156823d33999 6 * @brief M451 series FMC driver source file
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * @note
<> 149:156823d33999 9 * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved.
<> 149:156823d33999 10 *****************************************************************************/
<> 149:156823d33999 11
<> 149:156823d33999 12 //* Includes ------------------------------------------------------------------*/
<> 149:156823d33999 13 #include <stdio.h>
<> 149:156823d33999 14 #include "M451Series.h"
<> 149:156823d33999 15
<> 149:156823d33999 16 /** @addtogroup Standard_Driver Standard Driver
<> 149:156823d33999 17 @{
<> 149:156823d33999 18 */
<> 149:156823d33999 19
<> 149:156823d33999 20 /** @addtogroup FMC_Driver FMC Driver
<> 149:156823d33999 21 @{
<> 149:156823d33999 22 */
<> 149:156823d33999 23
<> 149:156823d33999 24
<> 149:156823d33999 25 /** @addtogroup FMC_EXPORTED_FUNCTIONS FMC Exported Functions
<> 149:156823d33999 26 @{
<> 149:156823d33999 27 */
<> 149:156823d33999 28
<> 149:156823d33999 29
<> 149:156823d33999 30 /**
<> 149:156823d33999 31 * @brief Set boot source from LDROM or APROM after next software reset
<> 149:156823d33999 32 *
<> 149:156823d33999 33 * @param[in] i32BootSrc
<> 149:156823d33999 34 * 1: Boot from LDROM,
<> 149:156823d33999 35 * 0: Boot from APROM
<> 149:156823d33999 36 *
<> 149:156823d33999 37 * @return None
<> 149:156823d33999 38 *
<> 149:156823d33999 39 * @details This function is used to switch APROM boot or LDROM boot. User need to call
<> 149:156823d33999 40 * FMC_SetBootSource to select boot source first, then use CPU reset or
<> 149:156823d33999 41 * System Reset Request to reset system.
<> 149:156823d33999 42 *
<> 149:156823d33999 43 */
<> 149:156823d33999 44 void FMC_SetBootSource(int32_t i32BootSrc)
<> 149:156823d33999 45 {
<> 149:156823d33999 46 if(i32BootSrc)
<> 149:156823d33999 47 FMC->ISPCTL |= FMC_ISPCTL_BS_Msk; /* Boot from LDROM */
<> 149:156823d33999 48 else
<> 149:156823d33999 49 FMC->ISPCTL &= ~FMC_ISPCTL_BS_Msk;/* Boot from APROM */
<> 149:156823d33999 50 }
<> 149:156823d33999 51
<> 149:156823d33999 52
<> 149:156823d33999 53 /**
<> 149:156823d33999 54 * @brief Disable ISP Functions
<> 149:156823d33999 55 *
<> 149:156823d33999 56 * @param None
<> 149:156823d33999 57 *
<> 149:156823d33999 58 * @return None
<> 149:156823d33999 59 *
<> 149:156823d33999 60 * @details This function will clear ISPEN bit of ISPCTL to disable ISP function
<> 149:156823d33999 61 *
<> 149:156823d33999 62 */
<> 149:156823d33999 63 void FMC_Close(void)
<> 149:156823d33999 64 {
<> 149:156823d33999 65 FMC->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk;
<> 149:156823d33999 66 }
<> 149:156823d33999 67
<> 149:156823d33999 68
<> 149:156823d33999 69 /**
<> 149:156823d33999 70 * @brief Disable APROM update function
<> 149:156823d33999 71 *
<> 149:156823d33999 72 * @param None
<> 149:156823d33999 73 *
<> 149:156823d33999 74 * @return None
<> 149:156823d33999 75 *
<> 149:156823d33999 76 * @details Disable APROM update function will forbid APROM programming when boot form APROM.
<> 149:156823d33999 77 * APROM update is default to be disable.
<> 149:156823d33999 78 *
<> 149:156823d33999 79 */
<> 149:156823d33999 80 void FMC_DisableAPUpdate(void)
<> 149:156823d33999 81 {
<> 149:156823d33999 82 FMC->ISPCTL &= ~FMC_ISPCTL_APUEN_Msk;
<> 149:156823d33999 83 }
<> 149:156823d33999 84
<> 149:156823d33999 85
<> 149:156823d33999 86 /**
<> 149:156823d33999 87 * @brief Disable User Configuration update function
<> 149:156823d33999 88 *
<> 149:156823d33999 89 * @param None
<> 149:156823d33999 90 *
<> 149:156823d33999 91 * @return None
<> 149:156823d33999 92 *
<> 149:156823d33999 93 * @details Disable User Configuration update function will forbid User Configuration programming.
<> 149:156823d33999 94 * User Configuration update is default to be disable.
<> 149:156823d33999 95 */
<> 149:156823d33999 96 void FMC_DisableConfigUpdate(void)
<> 149:156823d33999 97 {
<> 149:156823d33999 98 FMC->ISPCTL &= ~FMC_ISPCTL_CFGUEN_Msk;
<> 149:156823d33999 99 }
<> 149:156823d33999 100
<> 149:156823d33999 101
<> 149:156823d33999 102 /**
<> 149:156823d33999 103 * @brief Disable LDROM update function
<> 149:156823d33999 104 *
<> 149:156823d33999 105 * @param None
<> 149:156823d33999 106 *
<> 149:156823d33999 107 * @return None
<> 149:156823d33999 108
<> 149:156823d33999 109 * @details Disable LDROM update function will forbid LDROM programming.
<> 149:156823d33999 110 * LDROM update is default to be disable.
<> 149:156823d33999 111 */
<> 149:156823d33999 112 void FMC_DisableLDUpdate(void)
<> 149:156823d33999 113 {
<> 149:156823d33999 114 FMC->ISPCTL &= ~FMC_ISPCTL_LDUEN_Msk;
<> 149:156823d33999 115 }
<> 149:156823d33999 116
<> 149:156823d33999 117
<> 149:156823d33999 118 /**
<> 149:156823d33999 119 * @brief Enable APROM update function
<> 149:156823d33999 120 *
<> 149:156823d33999 121 * @param None
<> 149:156823d33999 122 *
<> 149:156823d33999 123 * @return None
<> 149:156823d33999 124 *
<> 149:156823d33999 125 * @details Enable APROM to be able to program when boot from APROM.
<> 149:156823d33999 126 *
<> 149:156823d33999 127 */
<> 149:156823d33999 128 void FMC_EnableAPUpdate(void)
<> 149:156823d33999 129 {
<> 149:156823d33999 130 FMC->ISPCTL |= FMC_ISPCTL_APUEN_Msk;
<> 149:156823d33999 131 }
<> 149:156823d33999 132
<> 149:156823d33999 133
<> 149:156823d33999 134 /**
<> 149:156823d33999 135 * @brief Enable User Configuration update function
<> 149:156823d33999 136 *
<> 149:156823d33999 137 * @param None
<> 149:156823d33999 138 *
<> 149:156823d33999 139 * @return None
<> 149:156823d33999 140 *
<> 149:156823d33999 141 * @details Enable User Configuration to be able to program.
<> 149:156823d33999 142 *
<> 149:156823d33999 143 */
<> 149:156823d33999 144 void FMC_EnableConfigUpdate(void)
<> 149:156823d33999 145 {
<> 149:156823d33999 146 FMC->ISPCTL |= FMC_ISPCTL_CFGUEN_Msk;
<> 149:156823d33999 147 }
<> 149:156823d33999 148
<> 149:156823d33999 149
<> 149:156823d33999 150 /**
<> 149:156823d33999 151 * @brief Enable LDROM update function
<> 149:156823d33999 152 *
<> 149:156823d33999 153 * @param None
<> 149:156823d33999 154 *
<> 149:156823d33999 155 * @return None
<> 149:156823d33999 156 *
<> 149:156823d33999 157 * @details Enable LDROM to be able to program.
<> 149:156823d33999 158 *
<> 149:156823d33999 159 */
<> 149:156823d33999 160 void FMC_EnableLDUpdate(void)
<> 149:156823d33999 161 {
<> 149:156823d33999 162 FMC->ISPCTL |= FMC_ISPCTL_LDUEN_Msk;
<> 149:156823d33999 163 }
<> 149:156823d33999 164
<> 149:156823d33999 165
<> 149:156823d33999 166 /**
<> 149:156823d33999 167 * @brief Get the current boot source
<> 149:156823d33999 168 *
<> 149:156823d33999 169 * @param None
<> 149:156823d33999 170 *
<> 149:156823d33999 171 * @retval 0 This chip is currently booting from APROM
<> 149:156823d33999 172 * @retval 1 This chip is currently booting from LDROM
<> 149:156823d33999 173 *
<> 149:156823d33999 174 * @note This function only show the boot source.
<> 149:156823d33999 175 * User need to read ISPSTA register to know if IAP mode supported or not in relative boot.
<> 149:156823d33999 176 */
<> 149:156823d33999 177 int32_t FMC_GetBootSource(void)
<> 149:156823d33999 178 {
<> 149:156823d33999 179 if(FMC->ISPCTL & FMC_ISPCTL_BS_Msk)
<> 149:156823d33999 180 return 1;
<> 149:156823d33999 181 else
<> 149:156823d33999 182 return 0;
<> 149:156823d33999 183 }
<> 149:156823d33999 184
<> 149:156823d33999 185
<> 149:156823d33999 186 /**
<> 149:156823d33999 187 * @brief Enable FMC ISP function
<> 149:156823d33999 188 *
<> 149:156823d33999 189 * @param None
<> 149:156823d33999 190 *
<> 149:156823d33999 191 * @return None
<> 149:156823d33999 192 *
<> 149:156823d33999 193 * @details ISPEN bit of ISPCTL must be set before we can use ISP commands.
<> 149:156823d33999 194 * Therefore, To use all FMC function APIs, user needs to call FMC_Open() first to enable ISP functions.
<> 149:156823d33999 195 *
<> 149:156823d33999 196 * @note ISP functions are write-protected. user also needs to unlock it by calling SYS_UnlockReg() before using all ISP functions.
<> 149:156823d33999 197 *
<> 149:156823d33999 198 */
<> 149:156823d33999 199 void FMC_Open(void)
<> 149:156823d33999 200 {
<> 149:156823d33999 201 FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk;
<> 149:156823d33999 202 }
<> 149:156823d33999 203
<> 149:156823d33999 204 /**
<> 149:156823d33999 205 * @brief Get the base address of Data Flash if enabled.
<> 149:156823d33999 206 *
<> 149:156823d33999 207 * @param None
<> 149:156823d33999 208 *
<> 149:156823d33999 209 * @return The base address of Data Flash
<> 149:156823d33999 210 *
<> 149:156823d33999 211 * @details This function is used to return the base address of Data Flash.
<> 149:156823d33999 212 *
<> 149:156823d33999 213 */
<> 149:156823d33999 214 uint32_t FMC_ReadDataFlashBaseAddr(void)
<> 149:156823d33999 215 {
<> 149:156823d33999 216 return FMC->DFBA;
<> 149:156823d33999 217 }
<> 149:156823d33999 218
<> 149:156823d33999 219
<> 149:156823d33999 220 /**
<> 149:156823d33999 221 * @brief Read the User Configuration words.
<> 149:156823d33999 222 *
<> 149:156823d33999 223 * @param[out] u32Config The word buffer to store the User Configuration data.
<> 149:156823d33999 224 * @param[in] u32Count The word count to be read.
<> 149:156823d33999 225 *
<> 149:156823d33999 226 * @retval 0 Success
<> 149:156823d33999 227 * @retval -1 Failed
<> 149:156823d33999 228 *
<> 149:156823d33999 229 * @details This function is used to read the settings of user configuration.
<> 149:156823d33999 230 * if u32Count = 1, Only CONFIG0 will be returned to the buffer specified by u32Config.
<> 149:156823d33999 231 * if u32Count = 2, Both CONFIG0 and CONFIG1 will be returned.
<> 149:156823d33999 232 */
<> 149:156823d33999 233 int32_t FMC_ReadConfig(uint32_t *u32Config, uint32_t u32Count)
<> 149:156823d33999 234 {
<> 149:156823d33999 235 int32_t i;
<> 149:156823d33999 236
<> 149:156823d33999 237 for(i = 0; i < u32Count; i++)
<> 149:156823d33999 238 u32Config[i] = FMC_Read(FMC_CONFIG_BASE + i * 4);
<> 149:156823d33999 239
<> 149:156823d33999 240 return 0;
<> 149:156823d33999 241 }
<> 149:156823d33999 242
<> 149:156823d33999 243
<> 149:156823d33999 244 /**
<> 149:156823d33999 245 * @brief Write User Configuration
<> 149:156823d33999 246 *
<> 149:156823d33999 247 * @param[in] u32Config The word buffer to store the User Configuration data.
<> 149:156823d33999 248 * @param[in] u32Count The word count to program to User Configuration.
<> 149:156823d33999 249 *
<> 149:156823d33999 250 * @retval 0 Success
<> 149:156823d33999 251 * @retval -1 Failed
<> 149:156823d33999 252 *
<> 149:156823d33999 253 * @details User must enable User Configuration update before writing it.
<> 149:156823d33999 254 * User must erase User Configuration before writing it.
<> 149:156823d33999 255 * User Configuration is also be page erase. User needs to backup necessary data
<> 149:156823d33999 256 * before erase User Configuration.
<> 149:156823d33999 257 */
<> 149:156823d33999 258 int32_t FMC_WriteConfig(uint32_t *u32Config, uint32_t u32Count)
<> 149:156823d33999 259 {
<> 149:156823d33999 260 int32_t i;
<> 149:156823d33999 261
<> 149:156823d33999 262 for(i = 0; i < u32Count; i++)
<> 149:156823d33999 263 {
<> 149:156823d33999 264 FMC_Write(FMC_CONFIG_BASE + i * 4, u32Config[i]);
<> 149:156823d33999 265 if(FMC_Read(FMC_CONFIG_BASE + i * 4) != u32Config[i])
<> 149:156823d33999 266 return -1;
<> 149:156823d33999 267 }
<> 149:156823d33999 268
<> 149:156823d33999 269 return 0;
<> 149:156823d33999 270 }
<> 149:156823d33999 271
<> 149:156823d33999 272 /**
<> 149:156823d33999 273 * @brief Enable Flash Access Frequency Optimization Mode
<> 149:156823d33999 274 *
<> 149:156823d33999 275 * @param[in] u32Mode Optimize flash access cycle mode
<> 149:156823d33999 276 * - \ref FMC_FTCTL_OPTIMIZE_DISABLE
<> 149:156823d33999 277 * - \ref FMC_FTCTL_OPTIMIZE_12MHZ
<> 149:156823d33999 278 * - \ref FMC_FTCTL_OPTIMIZE_36MHZ
<> 149:156823d33999 279 * - \ref FMC_FTCTL_OPTIMIZE_60MHZ
<> 149:156823d33999 280 * - \ref FMC_FTCTL_OPTIMIZE_72MHZ
<> 149:156823d33999 281 *
<> 149:156823d33999 282 * @return None
<> 149:156823d33999 283 *
<> 149:156823d33999 284 * @details This function will set FOM bit fields of FTCTL register to set flash access frequency optimization mode.
<> 149:156823d33999 285 *
<> 149:156823d33999 286 * @note The flash optimization mode (FOM) bits are write protect.
<> 149:156823d33999 287 *
<> 149:156823d33999 288 */
<> 149:156823d33999 289 void FMC_EnableFreqOptimizeMode(uint32_t u32Mode)
<> 149:156823d33999 290 {
<> 149:156823d33999 291 FMC->FTCTL &= ~FMC_FTCTL_FOM_Msk;
<> 149:156823d33999 292 FMC->FTCTL |= (u32Mode << FMC_FTCTL_FOM_Pos);
<> 149:156823d33999 293 }
<> 149:156823d33999 294
<> 149:156823d33999 295 /**
<> 149:156823d33999 296 * @brief Disable Flash Access Frequency Optimization Mode
<> 149:156823d33999 297 *
<> 149:156823d33999 298 * @param None
<> 149:156823d33999 299 *
<> 149:156823d33999 300 * @return None
<> 149:156823d33999 301 *
<> 149:156823d33999 302 * @details This function will clear FOM bit fields of FTCTL register to disable flash access frequency optimization mode.
<> 149:156823d33999 303 *
<> 149:156823d33999 304 * @note The flash optimization mode (FOM) bits are write protect.
<> 149:156823d33999 305 *
<> 149:156823d33999 306 */
<> 149:156823d33999 307 void FMC_DisableFreqOptimizeMode(void)
<> 149:156823d33999 308 {
<> 149:156823d33999 309 FMC->FTCTL &= ~FMC_FTCTL_FOM_Msk;
<> 149:156823d33999 310 }
<> 149:156823d33999 311
<> 149:156823d33999 312 /*@}*/ /* end of group FMC_EXPORTED_FUNCTIONS */
<> 149:156823d33999 313
<> 149:156823d33999 314 /*@}*/ /* end of group FMC_Driver */
<> 149:156823d33999 315
<> 149:156823d33999 316 /*@}*/ /* end of group Standard_Driver */
<> 149:156823d33999 317
<> 149:156823d33999 318 /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/
<> 149:156823d33999 319
<> 149:156823d33999 320