1 /** 2 * @file flc.h 3 * @brief Flash Controller driver. 4 * @details This driver can be used to operate on the embedded flash memory. 5 */ 6 7 /****************************************************************************** 8 * 9 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 10 * Analog Devices, Inc.), 11 * Copyright (C) 2023-2024 Analog Devices, Inc. 12 * 13 * Licensed under the Apache License, Version 2.0 (the "License"); 14 * you may not use this file except in compliance with the License. 15 * You may obtain a copy of the License at 16 * 17 * http://www.apache.org/licenses/LICENSE-2.0 18 * 19 * Unless required by applicable law or agreed to in writing, software 20 * distributed under the License is distributed on an "AS IS" BASIS, 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the License for the specific language governing permissions and 23 * limitations under the License. 24 * 25 ******************************************************************************/ 26 27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_FLC_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_FLC_H_ 29 30 /* **** Includes **** */ 31 #include "flc_regs.h" 32 #include "mxc_sys.h" 33 #include "mxc_errors.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** 40 * @defgroup flc Flash Controller (FLC) 41 * @ingroup periphlibs 42 * @{ 43 */ 44 45 /***** Definitions *****/ 46 47 /// Bit mask that can be used to find the starting address of a page in flash 48 #define MXC_FLASH_PAGE_MASK ~(MXC_FLASH_PAGE_SIZE - 1) 49 50 /// Calculate the address of a page in flash from the page number 51 #define MXC_FLASH_PAGE_ADDR(page) (MXC_FLASH_MEM_BASE + ((uint32_t)page * MXC_FLASH_PAGE_SIZE)) 52 53 /***** Function Prototypes *****/ 54 55 /** 56 * @brief Initializes the Flash Controller for erase/write operations 57 * @return #E_NO_ERROR if successful. 58 */ 59 int MXC_FLC_Init(void); 60 61 /** 62 * @brief Checks if Flash Controller is busy. 63 * @details Reading or executing from flash is not possible if flash is busy 64 * with an erase or write operation. 65 * @return If non-zero, flash operation is in progress 66 */ 67 int MXC_FLC_Busy(void); 68 69 /** 70 * @brief Erases the entire flash array. 71 * @note This function must be executed from RAM. 72 * @return #E_NO_ERROR If function is successful. 73 */ 74 int MXC_FLC_MassErase(void); 75 76 /** 77 * @brief Erases the page of flash at the specified address. 78 * @note This function must be executed from RAM. 79 * @param address Any address within the page to erase. 80 * @return #E_NO_ERROR If function is successful. 81 */ 82 int MXC_FLC_PageErase(uint32_t address); 83 84 /** 85 * @brief Read Data out of Flash from an address 86 * 87 * @param[in] address The address to read from 88 * @param buffer The buffer to read the data into 89 * @param[in] len The length of the buffer 90 * 91 */ 92 void MXC_FLC_Read(int address, void *buffer, int len); 93 94 /** 95 * @brief Writes data to flash. 96 * @note This function must be executed from RAM. 97 * @param address Address in flash to start writing from. 98 * @param length Number of bytes to be written. 99 * @param buffer Pointer to data to be written to flash. 100 * @return #E_NO_ERROR If function is successful. 101 * @note make sure to disable ICC with ICC_Disable(); before Running this function 102 */ 103 int MXC_FLC_Write(uint32_t address, uint32_t length, uint32_t *buffer); 104 105 /** 106 * @brief Writes 32 bits of data to flash. 107 * @note This function must be executed from RAM. 108 * @param address Address in flash to start writing from. 109 * @param data Pointer to data to be written to flash. 110 * @return #E_NO_ERROR If function is successful. 111 * @note make sure to disable ICC with ICC_Disable(); before Running this function 112 */ 113 int MXC_FLC_Write32(uint32_t address, uint32_t data); 114 115 /** 116 * @brief Writes 128 bits of data to flash. 117 * @note This function must be executed from RAM. 118 * @param address Address in flash to start writing from. 119 * @param data Pointer to data to be written to flash. 120 * @return #E_NO_ERROR If function is successful. 121 * @note make sure to disable ICC with ICC_Disable(); before Running this function 122 */ 123 int MXC_FLC_Write128(uint32_t address, uint32_t *data); 124 125 /** 126 * @brief Set FLC Instance used for Interrupts functions. 127 * @note Default is set to MXC_FLC0 if you don't run this. 128 * @param flc Pointer to FLC instance. 129 */ 130 void MXC_FLC_SetFLCInt(mxc_flc_regs_t *flc); 131 132 /** 133 * @brief Receive the currently set FLC instances used for Interrupts. 134 * @return Pointer to set FLC instance. 135 */ 136 mxc_flc_regs_t *MXC_FLC_GetFLCInt(void); 137 138 /** 139 * @brief Enable flash interrupts 140 * @param flags Interrupts to enable 141 * @return #E_NO_ERROR If function is successful. 142 */ 143 int MXC_FLC_EnableInt(uint32_t flags); 144 145 /** 146 * @brief Disable flash interrupts 147 * @param flags Interrupts to disable 148 * @return #E_NO_ERROR If function is successful. 149 */ 150 int MXC_FLC_DisableInt(uint32_t flags); 151 152 /** 153 * @brief Retrieve flash interrupt flags 154 * @return Interrupt flags registers 155 */ 156 int MXC_FLC_GetFlags(void); 157 158 /** 159 * @brief Clear flash interrupt flags 160 * @note Provide the bit position to clear, even if the flag is write-0-to-clear 161 * @param flags Flag bit(s) to clear 162 * @return #E_NO_ERROR If function is successful. 163 */ 164 int MXC_FLC_ClearFlags(uint32_t flags); 165 166 /** 167 * @brief Unlock info block 168 * 169 * @param[in] address The address in the info block needing written to 170 * 171 * @return #E_NO_ERROR If function is successful. 172 */ 173 int MXC_FLC_UnlockInfoBlock(uint32_t address); 174 175 /** 176 * @brief Lock info block 177 * 178 * @param[in] address The address in the info block that was written to 179 * @return #E_NO_ERROR If function is successful. 180 */ 181 int MXC_FLC_LockInfoBlock(uint32_t address); 182 183 /**@} end of group flc */ 184 185 #ifdef __cplusplus 186 } 187 #endif 188 189 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_FLC_H_ 190