1 /** 2 * @file 3 * @brief Flash Controler 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_MAX32650_FLC_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_FLC_H_ 29 30 /* **** Includes **** */ 31 #include "flc_regs.h" 32 #include "mxc_sys.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /** 39 * @defgroup flc Flash Controller 40 * @ingroup periphlibs 41 * @{ 42 */ 43 44 /***** Definitions *****/ 45 46 /// Bit mask that can be used to find the starting address of a page in flash 47 #define MXC_FLASH_PAGE_MASK ~(MXC_FLASH_PAGE_SIZE - 1) 48 49 /// Calculate the address of a page in flash from the page number 50 #define MXC_FLASH_PAGE_ADDR(page) (MXC_FLASH_MEM_BASE + ((uint32_t)page * MXC_FLASH_PAGE_SIZE)) 51 52 /***** Function Prototypes *****/ 53 54 /** 55 * @brief Initializes the flash controller for erase/write operations 56 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful. 57 */ 58 int MXC_FLC_Init(void); 59 60 /** 61 * @brief Checks if Flash controller is busy. 62 * @details Reading or executing from flash is not possible if flash is busy 63 * with an erase or write operation. 64 * @return If non-zero, flash operation is in progress 65 */ 66 int MXC_FLC_Busy(void); 67 68 /** 69 * @brief Erases the entire flash array. 70 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful. 71 */ 72 int MXC_FLC_MassErase(void); 73 74 /** 75 * @brief Erases the page of flash at the specified address. 76 * @param address Any address within the page to erase. 77 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful. 78 */ 79 int MXC_FLC_PageErase(uint32_t address); 80 81 /** 82 * @brief Read Data out of Flash from an address 83 * 84 * @param[in] address The address to read from 85 * @param buffer The buffer to read the data into 86 * @param[in] len The length of the buffer 87 * 88 */ 89 void MXC_FLC_Read(int address, void *buffer, int len); 90 91 /** 92 * @brief Writes data to flash. 93 * @param address Address in flash to start writing from. 94 * @param length Number of bytes to be written. 95 * @param buffer Pointer to data to be written to flash. 96 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if 97 * unsuccessful. 98 */ 99 int MXC_FLC_Write(uint32_t address, uint32_t length, uint32_t *buffer); 100 101 /** 102 * @brief Writes the specified 32-bit value to flash. 103 * @param address 32-bit aligned address in flash to write. 104 * @param data value to be written to flash. 105 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if 106 * unsuccessful. 107 */ 108 int MXC_FLC_Write32(uint32_t address, uint32_t data); 109 110 /** 111 * @brief Writes the specified 128-bits of data to flash. 112 * @param address 128-bit aligned address in flash to write. 113 * @param data pointer to data to be written to flash. 114 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if 115 * unsuccessful. 116 */ 117 int MXC_FLC_Write128(uint32_t address, uint32_t *data); 118 119 /** 120 * @brief Enable flash interrupts 121 * @param flags Interrupts to enable 122 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if 123 * unsuccessful. 124 */ 125 int MXC_FLC_EnableInt(uint32_t flags); 126 127 /** 128 * @brief Disable flash interrupts 129 * @param flags Interrupts to disable 130 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if 131 * unsuccessful. 132 */ 133 int MXC_FLC_DisableInt(uint32_t flags); 134 135 /** 136 * @brief Retrieve flash interrupt flags 137 * @return Mask of active flags. 138 */ 139 int MXC_FLC_GetFlags(void); 140 141 /** 142 * @brief Clear flash interrupt flags 143 * @note Provide the bit position to clear, even if the flag is write-0-to-clear 144 * @param flags Mask of flags to clear 145 * @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if 146 * unsuccessful. 147 */ 148 int MXC_FLC_ClearFlags(uint32_t flags); 149 150 /** 151 * @brief Unlock info block 152 * @param[in] address The address in the info block needing written to 153 * @return #E_NO_ERROR If function is successful. 154 */ 155 int MXC_FLC_UnlockInfoBlock(uint32_t address); 156 157 /** 158 * @brief Lock info block 159 * @param[in] address The address in the info block needing written to 160 * @return #E_NO_ERROR If function is successful. 161 */ 162 int MXC_FLC_LockInfoBlock(uint32_t address); 163 /**@} end of group flc */ 164 165 #ifdef __cplusplus 166 } 167 #endif 168 169 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_FLC_H_ 170