|
| 1 | +# AIOTED related changes, see https://github.com/jomjol/AI-on-the-edge-device/pull/2781 |
| 2 | +These files/folders were copied from `[email protected]/components/` and adapted to our own needs. |
| 3 | +Since not every SD/MMC was recognized and this was due to the implementation of ATA trim support, this was revised. |
| 4 | +Furthermore, files that we don't need were deleted from it. |
| 5 | + |
| 6 | +## The most relevant changes are: |
| 7 | +### fatfs/diskio/diskio_sdmmc.c |
| 8 | +DRESULT ff_sdmmc_ioctl (BYTE pdrv, BYTE cmd, void* buff), at lines 106 to 110 changed from: |
| 9 | +```c |
| 10 | +#if FF_USE_TRIM |
| 11 | + case CTRL_TRIM: |
| 12 | + return ff_sdmmc_trim (pdrv, *((DWORD*)buff), //start_sector |
| 13 | + (*((DWORD*)buff + 1) - *((DWORD*)buff) + 1)); //sector_count |
| 14 | +#endif //FF_USE_TRIM |
| 15 | +``` |
| 16 | +to: |
| 17 | +```c |
| 18 | +#if (FF_USE_TRIM) |
| 19 | + case CTRL_TRIM: |
| 20 | + if(FF_CAN_TRIM){ |
| 21 | + return ff_sdmmc_trim (pdrv, *((DWORD*)buff), //start_sector |
| 22 | + (*((DWORD*)buff + 1) - *((DWORD*)buff) + 1)); //sector_count |
| 23 | + } |
| 24 | + else{ |
| 25 | + return RES_ERROR; |
| 26 | + } |
| 27 | +#endif //FF_USE_TRIM |
| 28 | +``` |
| 29 | + |
| 30 | +### fatfs/src/ff.c |
| 31 | +added: |
| 32 | +```c |
| 33 | +#include "sdmmc_cmd.h" |
| 34 | +``` |
| 35 | + |
| 36 | +static FRESULT remove_chain(FFOBJID* obj, DWORD clst, DWORD pclst), at lines 1437 to 1454 changed from: |
| 37 | +```c |
| 38 | +#if FF_FS_EXFAT || FF_USE_TRIM |
| 39 | + if (ecl + 1 == nxt) { /* Is next cluster contiguous? */ |
| 40 | + ecl = nxt; |
| 41 | + } else { /* End of contiguous cluster block */ |
| 42 | +#if FF_FS_EXFAT |
| 43 | + if (fs->fs_type == FS_EXFAT) { |
| 44 | + res = change_bitmap(fs, scl, ecl - scl + 1, 0); /* Mark the cluster block 'free' on the bitmap */ |
| 45 | + if (res != FR_OK) return res; |
| 46 | + } |
| 47 | +#endif |
| 48 | +#if FF_USE_TRIM |
| 49 | + rt[0] = clst2sect(fs, scl); /* Start of data area to be freed */ |
| 50 | + rt[1] = clst2sect(fs, ecl) + fs->csize - 1; /* End of data area to be freed */ |
| 51 | + disk_ioctl(fs->pdrv, CTRL_TRIM, rt); /* Inform storage device that the data in the block may be erased */ |
| 52 | +#endif |
| 53 | + scl = ecl = nxt; |
| 54 | + } |
| 55 | +#endif |
| 56 | +``` |
| 57 | + |
| 58 | +to: |
| 59 | +```c |
| 60 | +#if FF_FS_EXFAT || FF_USE_TRIM |
| 61 | + if(FF_FS_EXFAT || FF_CAN_TRIM){ |
| 62 | + if (ecl + 1 == nxt) { /* Is next cluster contiguous? */ |
| 63 | + ecl = nxt; |
| 64 | + } |
| 65 | + else { /* End of contiguous cluster block */ |
| 66 | +#if FF_FS_EXFAT |
| 67 | + if (fs->fs_type == FS_EXFAT) { |
| 68 | + res = change_bitmap(fs, scl, ecl - scl + 1, 0); /* Mark the cluster block 'free' on the bitmap */ |
| 69 | + if (res != FR_OK) return res; |
| 70 | + } |
| 71 | +#endif |
| 72 | +#if FF_USE_TRIM |
| 73 | + if(FF_CAN_TRIM){ |
| 74 | + rt[0] = clst2sect(fs, scl); /* Start of data area to be freed */ |
| 75 | + rt[1] = clst2sect(fs, ecl) + fs->csize - 1; /* End of data area to be freed */ |
| 76 | + disk_ioctl(fs->pdrv, CTRL_TRIM, rt); /* Inform storage device that the data in the block may be erased */ |
| 77 | + } |
| 78 | +#endif |
| 79 | + scl = ecl = nxt; |
| 80 | + } |
| 81 | + } |
| 82 | +#endif |
| 83 | +``` |
| 84 | + |
| 85 | +FRESULT f_mkfs(const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len), at lines 5946 to 5949 changed from: |
| 86 | +```c |
| 87 | +#if FF_USE_TRIM |
| 88 | + lba[0] = b_vol; lba[1] = b_vol + sz_vol - 1; /* Inform storage device that the volume area may be erased */ |
| 89 | + disk_ioctl(pdrv, CTRL_TRIM, lba); |
| 90 | +#endif |
| 91 | +``` |
| 92 | +to: |
| 93 | +```c |
| 94 | +#if FF_USE_TRIM |
| 95 | + if(FF_CAN_TRIM){ |
| 96 | + lba[0] = b_vol; lba[1] = b_vol + sz_vol - 1; /* Inform storage device that the volume area may be erased */ |
| 97 | + disk_ioctl(pdrv, CTRL_TRIM, lba); |
| 98 | + } |
| 99 | +#endif |
| 100 | +``` |
| 101 | + |
| 102 | +FRESULT f_mkfs(const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len), at lines 6175 to 6178 changed from: |
| 103 | +```c |
| 104 | +#if FF_USE_TRIM |
| 105 | + lba[0] = b_vol; lba[1] = b_vol + sz_vol - 1; /* Inform storage device that the volume area may be erased */ |
| 106 | + disk_ioctl(pdrv, CTRL_TRIM, lba); |
| 107 | +#endif |
| 108 | +``` |
| 109 | +to: |
| 110 | +```c |
| 111 | +#if FF_USE_TRIM |
| 112 | + if(FF_CAN_TRIM){ |
| 113 | + lba[0] = b_vol; lba[1] = b_vol + sz_vol - 1; /* Inform storage device that the volume area may be erased */ |
| 114 | + disk_ioctl(pdrv, CTRL_TRIM, lba); |
| 115 | + } |
| 116 | +#endif |
| 117 | +``` |
| 118 | + |
| 119 | +### sdmmc/sdmmc_cmd.c |
| 120 | +added: |
| 121 | +```c |
| 122 | +int FF_CAN_TRIM = 0; |
| 123 | +``` |
| 124 | + |
| 125 | +esp_err_t sdmmc_can_trim(sdmmc_card_t* card), at lines 630 to 636 changed from: |
| 126 | +```c |
| 127 | +esp_err_t sdmmc_can_trim(sdmmc_card_t* card) |
| 128 | +{ |
| 129 | + if ((card->is_mmc) && (card->ext_csd.sec_feature & EXT_CSD_SEC_GB_CL_EN)) { |
| 130 | + return ESP_OK; |
| 131 | + } |
| 132 | + return ESP_FAIL; |
| 133 | +} |
| 134 | +``` |
| 135 | +to: |
| 136 | +```c |
| 137 | +esp_err_t sdmmc_can_trim(sdmmc_card_t* card) |
| 138 | +{ |
| 139 | + if ((card->is_mmc) && (card->ext_csd.sec_feature & EXT_CSD_SEC_GB_CL_EN)) { |
| 140 | + FF_CAN_TRIM = 1; |
| 141 | + return ESP_OK; |
| 142 | + } |
| 143 | + FF_CAN_TRIM = 0; |
| 144 | + return ESP_FAIL; |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +### sdmmc/include/sdmmc_cmd.h |
| 149 | + |
| 150 | +added: |
| 151 | +```c |
| 152 | +extern int FF_CAN_TRIM; |
| 153 | +``` |
| 154 | + |
| 155 | +# Espressif IoT Development Framework |
| 156 | + |
| 157 | +* [中文版](./README_CN.md) |
| 158 | + |
| 159 | +ESP-IDF is the development framework for Espressif SoCs supported on Windows, Linux and macOS. |
| 160 | + |
| 161 | +# ESP-IDF Release Support Schedule |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +- Please read [the support policy](SUPPORT_POLICY.md) and [the documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/versions.html) for more information about ESP-IDF versions. |
| 166 | +- Please see the [End-of-Life Advisories](https://www.espressif.com/en/support/documents/advisories?keys=&field_type_of_advisory_tid%5B%5D=817) for information about ESP-IDF releases with discontinued support. |
| 167 | + |
| 168 | +# ESP-IDF Release and SoC Compatibility |
| 169 | + |
| 170 | +The following table shows ESP-IDF support of Espressif SoCs where ![alt text][preview] and ![alt text][supported] denote preview status and support, respectively. The preview support is usually limited in time and intended for beta versions of chips. Please use an ESP-IDF release where the desired SoC is already supported. |
| 171 | + |
| 172 | +|Chip | v4.1 | v4.2 | v4.3 | v4.4 | v5.0 | | |
| 173 | +|:----------- |:---------------------:| :---------------------:| :---------------------:| :---------------------:| :---------------------:|:------------------------------------------------------------------------------------ | |
| 174 | +|ESP32 |![alt text][supported] | ![alt text][supported] | ![alt text][supported] | ![alt text][supported] | ![alt text][supported] | | |
| 175 | +|ESP32-S2 | | ![alt text][supported] | ![alt text][supported] | ![alt text][supported] | ![alt text][supported] | | |
| 176 | +|ESP32-C3 | | | ![alt text][supported] | ![alt text][supported] | ![alt text][supported] | | |
| 177 | +|ESP32-S3 | | | | ![alt text][supported] | ![alt text][supported] | [Announcement](https://www.espressif.com/en/news/ESP32_S3) | |
| 178 | +|ESP32-C2 | | | | | ![alt text][supported] | [Announcement](https://blog.espressif.com/esp32-c2-and-why-it-matter-s-bcf4d7d0b2c6) | |
| 179 | +|ESP32-H2 | | | | ![alt text][preview] | ![alt text][preview] | [Announcement](https://www.espressif.com/en/news/ESP32_H2) | |
| 180 | + |
| 181 | +[supported]: https://img.shields.io/badge/-supported-green "supported" |
| 182 | +[preview]: https://img.shields.io/badge/-preview-orange "preview" |
| 183 | + |
| 184 | +Espressif SoCs released before 2016 (ESP8266 and ESP8285) are supported by [RTOS SDK](https://github.com/espressif/ESP8266_RTOS_SDK) instead. |
| 185 | + |
| 186 | +# Developing With ESP-IDF |
| 187 | + |
| 188 | +## Setting Up ESP-IDF |
| 189 | + |
| 190 | +See https://idf.espressif.com/ for links to detailed instructions on how to set up the ESP-IDF depending on chip you use. |
| 191 | + |
| 192 | +**Note:** Each SoC series and each ESP-IDF release has its own documentation. Please see Section [Versions](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/versions.html) on how to find documentation and how to checkout specific release of ESP-IDF. |
| 193 | + |
| 194 | +### Non-GitHub forks |
| 195 | + |
| 196 | +ESP-IDF uses relative locations as its submodules URLs ([.gitmodules](.gitmodules)). So they link to GitHub. If ESP-IDF is forked to a Git repository which is not on GitHub, you will need to run the script [tools/set-submodules-to-github.sh](tools/set-submodules-to-github.sh) after git clone. |
| 197 | + |
| 198 | +The script sets absolute URLs for all submodules, allowing `git submodule update --init --recursive` to complete. If cloning ESP-IDF from GitHub, this step is not needed. |
| 199 | + |
| 200 | +## Finding a Project |
| 201 | + |
| 202 | +As well as the [esp-idf-template](https://github.com/espressif/esp-idf-template) project mentioned in Getting Started, ESP-IDF comes with some example projects in the [examples](examples) directory. |
| 203 | + |
| 204 | +Once you've found the project you want to work with, change to its directory and you can configure and build it. |
| 205 | + |
| 206 | +To start your own project based on an example, copy the example project directory outside of the ESP-IDF directory. |
| 207 | + |
| 208 | +# Quick Reference |
| 209 | + |
| 210 | +See the Getting Started guide links above for a detailed setup guide. This is a quick reference for common commands when working with ESP-IDF projects: |
| 211 | + |
| 212 | +## Setup Build Environment |
| 213 | + |
| 214 | +(See the Getting Started guide listed above for a full list of required steps with more details.) |
| 215 | + |
| 216 | +* Install host build dependencies mentioned in the Getting Started guide. |
| 217 | +* Run the install script to set up the build environment. The options include `install.bat` or `install.ps1` for Windows, and `install.sh` or `install.fish` for Unix shells. |
| 218 | +* Run the export script on Windows (`export.bat`) or source it on Unix (`source export.sh`) in every shell environment before using ESP-IDF. |
| 219 | + |
| 220 | +## Configuring the Project |
| 221 | + |
| 222 | +* `idf.py set-target <chip_name>` sets the target of the project to `<chip_name>`. Run `idf.py set-target` without any arguments to see a list of supported targets. |
| 223 | +* `idf.py menuconfig` opens a text-based configuration menu where you can configure the project. |
| 224 | + |
| 225 | +## Compiling the Project |
| 226 | + |
| 227 | +`idf.py build` |
| 228 | + |
| 229 | +... will compile app, bootloader and generate a partition table based on the config. |
| 230 | + |
| 231 | +## Flashing the Project |
| 232 | + |
| 233 | +When the build finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this automatically by running: |
| 234 | + |
| 235 | +`idf.py -p PORT flash` |
| 236 | + |
| 237 | +Replace PORT with the name of your serial port (like `COM3` on Windows, `/dev/ttyUSB0` on Linux, or `/dev/cu.usbserial-X` on MacOS. If the `-p` option is left out, `idf.py flash` will try to flash the first available serial port. |
| 238 | + |
| 239 | +This will flash the entire project (app, bootloader and partition table) to a new chip. The settings for serial port flashing can be configured with `idf.py menuconfig`. |
| 240 | + |
| 241 | +You don't need to run `idf.py build` before running `idf.py flash`, `idf.py flash` will automatically rebuild anything which needs it. |
| 242 | + |
| 243 | +## Viewing Serial Output |
| 244 | + |
| 245 | +The `idf.py monitor` target uses the [idf_monitor tool](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/idf-monitor.html) to display serial output from Espressif SoCs. idf_monitor also has a range of features to decode crash output and interact with the device. [Check the documentation page for details](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/idf-monitor.html). |
| 246 | + |
| 247 | +Exit the monitor by typing Ctrl-]. |
| 248 | + |
| 249 | +To build, flash and monitor output in one pass, you can run: |
| 250 | + |
| 251 | +`idf.py flash monitor` |
| 252 | + |
| 253 | +## Compiling & Flashing Only the App |
| 254 | + |
| 255 | +After the initial flash, you may just want to build and flash just your app, not the bootloader and partition table: |
| 256 | + |
| 257 | +* `idf.py app` - build just the app. |
| 258 | +* `idf.py app-flash` - flash just the app. |
| 259 | + |
| 260 | +`idf.py app-flash` will automatically rebuild the app if any source files have changed. |
| 261 | + |
| 262 | +(In normal development there's no downside to reflashing the bootloader and partition table each time, if they haven't changed.) |
| 263 | + |
| 264 | +## Erasing Flash |
| 265 | + |
| 266 | +The `idf.py flash` target does not erase the entire flash contents. However it is sometimes useful to set the device back to a totally erased state, particularly when making partition table changes or OTA app updates. To erase the entire flash, run `idf.py erase-flash`. |
| 267 | + |
| 268 | +This can be combined with other targets, ie `idf.py -p PORT erase-flash flash` will erase everything and then re-flash the new app, bootloader and partition table. |
| 269 | + |
| 270 | +# Resources |
| 271 | + |
| 272 | +* Documentation for the latest version: https://docs.espressif.com/projects/esp-idf/. This documentation is built from the [docs directory](docs) of this repository. |
| 273 | + |
| 274 | +* The [esp32.com forum](https://esp32.com/) is a place to ask questions and find community resources. |
| 275 | + |
| 276 | +* [Check the Issues section on github](https://github.com/espressif/esp-idf/issues) if you find a bug or have a feature request. Please check existing Issues before opening a new one. |
| 277 | + |
| 278 | +* If you're interested in contributing to ESP-IDF, please check the [Contributions Guide](https://docs.espressif.com/projects/esp-idf/en/latest/contribute/index.html). |
0 commit comments