Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
SystemStorage.cpp
00001 /* 00002 * Copyright (c) 2018 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "features/storage/blockdevice/BlockDevice.h" 00017 #include "features/storage/filesystem/FileSystem.h" 00018 #include "features/storage/filesystem/fat/FATFileSystem.h" 00019 #include "features/storage/filesystem/littlefs/LittleFileSystem.h" 00020 #include "mbed_error.h" 00021 00022 00023 #if COMPONENT_SPIF 00024 #include "components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.h" 00025 #endif 00026 00027 #if COMPONENT_RSPIF 00028 #include "components/storage/blockdevice/COMPONENT_RSPIF/SPIFReducedBlockDevice.h" 00029 #endif 00030 00031 #if COMPONENT_QSPIF 00032 #include "components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h" 00033 #endif 00034 00035 #if COMPONENT_DATAFLASH 00036 #include "components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.h" 00037 #endif 00038 00039 #if COMPONENT_SD 00040 #include "components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h" 00041 00042 #if (STATIC_PINMAP_READY) 00043 const spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, NC); 00044 #endif 00045 #endif 00046 00047 #if COMPONENT_FLASHIAP 00048 #include "components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h" 00049 #endif 00050 00051 using namespace mbed; 00052 00053 // Align a value to a specified size. 00054 // Parameters : 00055 // val - [IN] Value. 00056 // size - [IN] Size. 00057 // Return : Aligned value. 00058 static inline uint32_t align_up(uint32_t val, uint32_t size) 00059 { 00060 return (((val - 1) / size) + 1) * size; 00061 } 00062 00063 MBED_WEAK BlockDevice *BlockDevice::get_default_instance() 00064 { 00065 #if COMPONENT_SPIF 00066 00067 static SPIFBlockDevice default_bd( 00068 MBED_CONF_SPIF_DRIVER_SPI_MOSI, 00069 MBED_CONF_SPIF_DRIVER_SPI_MISO, 00070 MBED_CONF_SPIF_DRIVER_SPI_CLK, 00071 MBED_CONF_SPIF_DRIVER_SPI_CS, 00072 MBED_CONF_SPIF_DRIVER_SPI_FREQ 00073 ); 00074 00075 return &default_bd; 00076 00077 #elif COMPONENT_RSPIF 00078 00079 static SPIFReducedBlockDevice default_bd( 00080 MBED_CONF_RSPIF_DRIVER_SPI_MOSI, 00081 MBED_CONF_RSPIF_DRIVER_SPI_MISO, 00082 MBED_CONF_RSPIF_DRIVER_SPI_CLK, 00083 MBED_CONF_RSPIF_DRIVER_SPI_CS, 00084 MBED_CONF_RSPIF_DRIVER_SPI_FREQ 00085 ); 00086 00087 return &default_bd; 00088 00089 #elif COMPONENT_QSPIF 00090 00091 static QSPIFBlockDevice default_bd( 00092 MBED_CONF_QSPIF_QSPI_IO0, 00093 MBED_CONF_QSPIF_QSPI_IO1, 00094 MBED_CONF_QSPIF_QSPI_IO2, 00095 MBED_CONF_QSPIF_QSPI_IO3, 00096 MBED_CONF_QSPIF_QSPI_SCK, 00097 MBED_CONF_QSPIF_QSPI_CSN, 00098 MBED_CONF_QSPIF_QSPI_POLARITY_MODE, 00099 MBED_CONF_QSPIF_QSPI_FREQ 00100 ); 00101 00102 return &default_bd; 00103 00104 #elif COMPONENT_DATAFLASH 00105 00106 static DataFlashBlockDevice default_bd( 00107 MBED_CONF_DATAFLASH_SPI_MOSI, 00108 MBED_CONF_DATAFLASH_SPI_MISO, 00109 MBED_CONF_DATAFLASH_SPI_CLK, 00110 MBED_CONF_DATAFLASH_SPI_CS 00111 ); 00112 00113 return &default_bd; 00114 00115 #elif COMPONENT_SD 00116 00117 #if (STATIC_PINMAP_READY) 00118 static SDBlockDevice default_bd( 00119 static_spi_pinmap, 00120 MBED_CONF_SD_SPI_CS 00121 ); 00122 #else 00123 static SDBlockDevice default_bd( 00124 MBED_CONF_SD_SPI_MOSI, 00125 MBED_CONF_SD_SPI_MISO, 00126 MBED_CONF_SD_SPI_CLK, 00127 MBED_CONF_SD_SPI_CS 00128 ); 00129 #endif 00130 00131 return &default_bd; 00132 00133 #elif COMPONENT_FLASHIAP 00134 00135 #if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF) 00136 00137 size_t flash_size; 00138 uint32_t start_address; 00139 uint32_t bottom_address; 00140 FlashIAP flash; 00141 00142 int ret = flash.init(); 00143 if (ret != 0) { 00144 return 0; 00145 } 00146 00147 //Find the start of first sector after text area 00148 bottom_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR)); 00149 start_address = flash.get_flash_start(); 00150 flash_size = flash.get_flash_size(); 00151 00152 ret = flash.deinit(); 00153 00154 static FlashIAPBlockDevice default_bd(bottom_address, start_address + flash_size - bottom_address); 00155 00156 #else 00157 00158 static FlashIAPBlockDevice default_bd; 00159 00160 #endif 00161 00162 return &default_bd; 00163 00164 #else 00165 00166 return NULL; 00167 00168 #endif 00169 00170 } 00171 00172 MBED_WEAK FileSystem *FileSystem::get_default_instance() 00173 { 00174 #if COMPONENT_SPIF || COMPONENT_QSPIF || COMPONENT_DATAFLASH 00175 00176 static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); 00177 flash.set_as_default(); 00178 00179 return &flash; 00180 00181 #elif COMPONENT_SD 00182 00183 static FATFileSystem sdcard("sd", BlockDevice::get_default_instance()); 00184 sdcard.set_as_default(); 00185 00186 return &sdcard; 00187 00188 #elif COMPONENT_FLASHIAP 00189 00190 static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); 00191 flash.set_as_default(); 00192 00193 return &flash; 00194 00195 #else 00196 00197 return NULL; 00198 00199 #endif 00200 00201 }
Generated on Tue Jul 12 2022 13:54:55 by
