1 /** 2 ****************************************************************************** 3 * @file bflb_sf_cfg.h 4 * @version V1.0 5 * @date 6 * @brief This file is the standard driver header file 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© COPYRIGHT(c) 2020 Bouffalo Lab</center></h2> 11 * 12 * Redistribution and use in source and binary forms, with or without modification, 13 * are permitted provided that the following conditions are met: 14 * 1. Redistributions of source code must retain the above copyright notice, 15 * this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright notice, 17 * this list of conditions and the following disclaimer in the documentation 18 * and/or other materials provided with the distribution. 19 * 3. Neither the name of Bouffalo Lab nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 ****************************************************************************** 35 */ 36 #ifndef __BL628_SF_CFG_H__ 37 #define __BL628_SF_CFG_H__ 38 39 #include "bflb_gpio.h" 40 #include "bflb_sflash.h" 41 42 /** @addtogroup BL628_Peripheral_Driver 43 * @{ 44 */ 45 46 /** @addtogroup SF_CFG 47 * @{ 48 */ 49 50 /** @defgroup SF_CFG_Public_Types 51 * @{ 52 */ 53 54 /*@} end of group SF_CFG_Public_Types */ 55 56 /** @defgroup SF_CFG_Public_Constants 57 * @{ 58 */ 59 60 /*@} end of group SF_CFG_Public_Constants */ 61 62 /** @defgroup SF_CFG_Public_Macros 63 * @{ 64 */ 65 #define BFLB_GPIO_FUNC_SF 2 66 #if defined(BL628) || defined(BL616) 67 /* Flash option sf2 */ 68 /* Flash CLK */ 69 #define BFLB_EXTFLASH_CLK0_GPIO GPIO_PIN_8 70 /* FLASH CS */ 71 #define BFLB_EXTFLASH_CS0_GPIO GPIO_PIN_4 72 /* FLASH DATA */ 73 #define BFLB_EXTFLASH_DATA00_GPIO GPIO_PIN_7 74 #define BFLB_EXTFLASH_DATA10_GPIO GPIO_PIN_5 75 #define BFLB_EXTFLASH_DATA20_GPIO GPIO_PIN_6 76 #define BFLB_EXTFLASH_DATA30_GPIO GPIO_PIN_9 77 /* Flash option sf3 */ 78 /* Flash CLK */ 79 #define BFLB_EXTFLASH_CLK1_GPIO GPIO_PIN_15 80 /* FLASH CS */ 81 #define BFLB_EXTFLASH_CS1_GPIO GPIO_PIN_20 82 /* FLASH DATA */ 83 #define BFLB_EXTFLASH_DATA01_GPIO GPIO_PIN_16 84 #define BFLB_EXTFLASH_DATA11_GPIO GPIO_PIN_19 85 #define BFLB_EXTFLASH_DATA21_GPIO GPIO_PIN_18 86 #define BFLB_EXTFLASH_DATA31_GPIO GPIO_PIN_14 87 #elif defined(BL808) || defined(BL606P) 88 /* Flash option sf2 */ 89 /* Flash CLK */ 90 #define BFLB_EXTFLASH_CLK0_GPIO GPIO_PIN_34 91 /* FLASH CS */ 92 #define BFLB_EXTFLASH_CS0_GPIO GPIO_PIN_35 93 /* FLASH DATA */ 94 #define BFLB_EXTFLASH_DATA00_GPIO GPIO_PIN_36 95 #define BFLB_EXTFLASH_DATA10_GPIO GPIO_PIN_37 96 #define BFLB_EXTFLASH_DATA20_GPIO GPIO_PIN_38 97 #define BFLB_EXTFLASH_DATA30_GPIO GPIO_PIN_39 98 #elif defined(BL702L) 99 /* Flash option */ 100 /* Flash CLK */ 101 #define BFLB_EXTFLASH_CLK0_GPIO GPIO_PIN_27 102 /* FLASH CS */ 103 #define BFLB_EXTFLASH_CS0_GPIO GPIO_PIN_26 104 /* FLASH DATA */ 105 #define BFLB_EXTFLASH_DATA00_GPIO GPIO_PIN_23 106 #define BFLB_EXTFLASH_DATA10_GPIO GPIO_PIN_25 107 #define BFLB_EXTFLASH_DATA20_GPIO GPIO_PIN_24 108 #define BFLB_EXTFLASH_DATA30_GPIO GPIO_PIN_28 109 #elif defined(BL702) 110 /* Flash option 0 */ 111 /* Flash CLK */ 112 #define BFLB_EXTFLASH_CLK0_GPIO GPIO_PIN_21 113 /* FLASH CS */ 114 #define BFLB_EXTFLASH_CS0_GPIO GPIO_PIN_19 115 /* FLASH DATA */ 116 #define BFLB_EXTFLASH_DATA00_GPIO GPIO_PIN_17 117 #define BFLB_EXTFLASH_DATA10_GPIO GPIO_PIN_18 118 #define BFLB_EXTFLASH_DATA20_GPIO GPIO_PIN_22 119 #define BFLB_EXTFLASH_DATA30_GPIO GPIO_PIN_20 120 /* Flash option 1 */ 121 /* Flash CLK */ 122 #define BFLB_EXTFLASH_CLK1_GPIO GPIO_PIN_27 123 /* FLASH CS */ 124 #define BFLB_EXTFLASH_CS1_GPIO GPIO_PIN_25 125 /* FLASH DATA */ 126 #define BFLB_EXTFLASH_DATA01_GPIO GPIO_PIN_28 127 #define BFLB_EXTFLASH_DATA11_GPIO GPIO_PIN_24 128 #define BFLB_EXTFLASH_DATA21_GPIO GPIO_PIN_23 129 #define BFLB_EXTFLASH_DATA31_GPIO GPIO_PIN_26 130 /* Flash option 2 */ 131 /* Flash CLK */ 132 #define BFLB_EXTFLASH_CLK2_GPIO GPIO_PIN_36 133 /* FLASH CS */ 134 #define BFLB_EXTFLASH_CS2_GPIO GPIO_PIN_35 135 /* FLASH DATA */ 136 #define BFLB_EXTFLASH_DATA02_GPIO GPIO_PIN_32 137 #define BFLB_EXTFLASH_DATA12_GPIO GPIO_PIN_34 138 #define BFLB_EXTFLASH_DATA22_GPIO GPIO_PIN_33 139 #define BFLB_EXTFLASH_DATA32_GPIO GPIO_PIN_37 140 #define BFLB_FLASH_CFG_SF2_EXT_23_28 0 141 #define BFLB_FLASH_CFG_SF2_INT_512K 1 142 #define BFLB_FLASH_CFG_SF2_INT_1M 2 143 #define BFLB_FLASH_CFG_SF1_EXT_17_22 3 144 #define BFLB_SF2_SWAP_NONE 0 145 #define BFLB_SF2_SWAP_CS_IO2 1 146 #define BFLB_SF2_SWAP_IO0_IO3 2 147 #define BFLB_SF2_SWAP_BOTH 3 148 #elif defined(BL602) 149 /*Flash option 0*/ 150 /*Flash CLK*/ 151 #define BFLB_EXTFLASH_CLK0_GPIO GPIO_PIN_22 152 /*FLASH CS*/ 153 #define BFLB_EXTFLASH_CS0_GPIO GPIO_PIN_21 154 /*FLASH DATA*/ 155 #define BFLB_EXTFLASH_DATA00_GPIO GPIO_PIN_20 156 #define BFLB_EXTFLASH_DATA10_GPIO GPIO_PIN_19 157 #define BFLB_EXTFLASH_DATA20_GPIO GPIO_PIN_18 158 #define BFLB_EXTFLASH_DATA30_GPIO GPIO_PIN_17 159 /*Flash option 1*/ 160 /*Flash CLK*/ 161 #define BFLB_EXTFLASH_CLK1_GPIO GPIO_PIN_22 162 /*FLASH CS*/ 163 #define BFLB_EXTFLASH_CS1_GPIO GPIO_PIN_21 164 /*FLASH DATA*/ 165 #define BFLB_EXTFLASH_DATA01_GPIO GPIO_PIN_20 166 #define BFLB_EXTFLASH_DATA11_GPIO GPIO_PIN_0 167 #define BFLB_EXTFLASH_DATA21_GPIO GPIO_PIN_1 168 #define BFLB_EXTFLASH_DATA31_GPIO GPIO_PIN_2 169 #define BFLB_FLASH_CFG_DESWAP 1 170 #define BFLB_FLASH_CFG_EXT0_17_22 2 171 #define BFLB_FLASH_CFG_EXT1_0_2_20_22 3 172 #endif 173 #define BFLB_FLASH_ID_VALID_FLAG 0x80000000 174 #define BFLB_FLASH_ID_VALID_MASK 0x7FFFFFFF 175 176 /*@} end of group SF_CFG_Public_Macros */ 177 178 /** @defgroup SF_CFG_Public_Functions 179 * @{ 180 */ 181 int bflb_sf_cfg_get_flash_cfg_need_lock(uint32_t flash_id, spi_flash_cfg_type *p_flash_cfg, 182 uint8_t group, uint8_t bank); 183 int bflb_sf_cfg_get_flash_cfg_need_lock_ext(uint32_t flash_id, spi_flash_cfg_type *p_flash_cfg, 184 uint8_t group, uint8_t bank); 185 #if defined(BL702L) || defined(BL702) 186 void bflb_sf_cfg_init_internal_flash_gpio(void); 187 #endif 188 #if defined(BL602) 189 void bflb_sf_cfg_restore_gpio17_fun(uint8_t fun); 190 #endif 191 int bflb_sf_cfg_init_flash_gpio(uint8_t flash_pin_cfg, uint8_t restore_default); 192 #ifdef BFLB_SF_CTRL_SBUS2_ENABLE 193 int bflb_sf_cfg_init_flash2_gpio(uint8_t swap); 194 #endif 195 int bflb_sf_cfg_init_ext_flash_gpio(uint8_t ext_flash_pin); 196 int bflb_sf_cfg_deinit_ext_flash_gpio(uint8_t ext_flash_pin); 197 uint32_t bflb_sf_cfg_flash_identify(uint8_t call_from_flash, uint8_t flash_pin_cfg, uint8_t restore_default, 198 spi_flash_cfg_type *p_flash_cfg, uint8_t group, uint8_t bank); 199 uint32_t bflb_sf_cfg_flash_identify_ext(uint8_t callfromflash, uint8_t flash_pin_cfg, uint8_t restore_default, 200 spi_flash_cfg_type *p_flash_cfg, uint8_t group, uint8_t bank); 201 #ifdef BFLB_SF_CTRL_SBUS2_ENABLE 202 int bflb_sf_cfg_flash_init(uint8_t sel, const struct sf_ctrl_cfg_type *p_sfctrl_cfg, 203 const struct sf_ctrl_bank2_cfg *p_bank2_cfg); 204 int bflb_sf_cfg_sbus2_flash_init(uint8_t sel, const struct sf_ctrl_bank2_cfg *p_bank2_cfg); 205 #else 206 int bflb_sf_cfg_flash_init(uint8_t sel, const struct sf_ctrl_cfg_type *p_sfctrl_cfg); 207 #endif 208 209 /*@} end of group SF_CFG_Public_Functions */ 210 211 /*@} end of group SF_CFG */ 212 213 /*@} end of group BL628_Peripheral_Driver */ 214 215 #endif /* __BL628_SF_CFG_H__ */ 216