mirror of
https://github.com/m5stack/aws-iot-kit-tutorials.git
synced 2026-05-20 10:49:00 -07:00
168 lines
14 KiB
HTML
168 lines
14 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.3"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Core2 for AWS IoT Kit BSP: SD-Card</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="custom.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr id="projectrow">
|
|
<td id="projectlogo"><img alt="Logo" src="AWS_logo_RGB.png"/></td>
|
|
<td id="projectalign">
|
|
<div id="projectname">Core2 for AWS IoT Kit BSP<span id="projectnumber"> 1.5.1</span>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.3 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
</div><!-- top -->
|
|
<div><div class="header">
|
|
<div class="headertitle"><div class="title">SD-Card </div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="textblock"><p >The SD Card functions wraps Espressif's virtual file drivers for the SD card slot. Reading/writing to an inserted SD card can use the standard C functions fopen or fprintf. The SD Card must be unmounted before removing if the device is on to avoid data corruption. Visit Espressif's virtual <a href="https://docs.espressif.com/projects/esp-idf/en/release-v4.2/esp32/api-reference/storage/vfs.html">file system component</a> docs for usage. Maximum supported SD is 16GB and requires the use of a FAT/FAT32 partition table and the feature's symbol must be enabled.</p>
|
|
<p ><a class="anchor" id="sd"></a></p>
|
|
<p ><a href="./block_diagram-sdcard.png"><img src="./block_diagram-sdcard.png" alt="Circuit Block Diagram for the SD card slot" class="center" class="inline"/></a></p>
|
|
<p >To enable this feature using KConfig, use the command <code>pio run --environment core2foraws --target menuconfig</code> from within the root of the project directoy in your <a href="/en/blinky-hello-world/prerequisites.html#open-the-platformio-cli-terminal-window">PlatformIO terminal window</a> and go to the menu <code>Component Config --> Core2 for AWS features</code> to set the features you want to enable.</p>
|
|
<dl class="section note"><dt>Note</dt><dd>This feature requires the ILI9342 display to be enabled.</dd></dl>
|
|
<p>The SD card and the screen share the same SPI bus. In order to avoid conflicts with the screen, you must take the <a class="el" href="disp__spi_8c.html#a76c0525d646735793add25b18043e600">spi_mutex</a> semaphore, and then call <a class="el" href="disp__spi_8h.html#a3dc6a7525e5a0b34e37a3a64478ec9ee">spi_poll()</a> before accessing the SD card. Once done, give the semaphore so that the display can go back to using it.</p>
|
|
<h1><a class="anchor" id="sdcard_example"></a>
|
|
Example</h1>
|
|
<p >The example code below, mounts the SD card, writes a file named <code>hello.txt</code> on the path <code>/sdcard</code> with the contents "Hello <<YOUR SD CARD'S PRODUCT NAME>>!", reads back the file and outputs the contents to the serial output, and then unmounts the card:</p>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include "esp_log.h"</span></div>
|
|
<div class="line"><span class="preprocessor">#include "<a class="code" href="core2for_a_w_s_8h.html">core2forAWS.h</a>"</span></div>
|
|
<div class="line"> </div>
|
|
<div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a> = <span class="stringliteral">"EXAMPLE"</span>;</div>
|
|
<div class="line"> </div>
|
|
<div class="line"><span class="preprocessor">#define MOUNT_POINT "/sdcard"</span></div>
|
|
<div class="line"> </div>
|
|
<div class="line"><span class="keywordtype">void</span> app_main(<span class="keywordtype">void</span>){</div>
|
|
<div class="line"> <a class="code hl_function" href="core2for_a_w_s_8c.html#a3d850a3f56bbe0685b60726d8b53bece">Core2ForAWS_Init</a>();</div>
|
|
<div class="line"> sdmmc_card_t* card;</div>
|
|
<div class="line"> esp_err_t err;</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="keywordtype">char</span> file_path[] = MOUNT_POINT<span class="stringliteral">"/hello.txt"</span>;</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> xSemaphoreTake(<a class="code hl_variable" href="disp__spi_8h.html#a76c0525d646735793add25b18043e600">spi_mutex</a>, portMAX_DELAY);</div>
|
|
<div class="line"> <a class="code hl_function" href="disp__spi_8h.html#a3dc6a7525e5a0b34e37a3a64478ec9ee">spi_poll</a>();</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> err = <a class="code hl_function" href="core2for_a_w_s_8c.html#a714fd9c7943bbec98c54dfa17d778853">Core2ForAWS_SDcard_Mount</a>(MOUNT_POINT, &card);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="keywordflow">if</span>(err == ESP_OK){</div>
|
|
<div class="line"> ESP_LOGI(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"SD Card mounted"</span>);</div>
|
|
<div class="line"> } </div>
|
|
<div class="line"> <span class="keywordflow">else</span>{</div>
|
|
<div class="line"> ESP_LOGI(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"SD Card mount error code: %d"</span>, err);</div>
|
|
<div class="line"> xSemaphoreGive(<a class="code hl_variable" href="disp__spi_8h.html#a76c0525d646735793add25b18043e600">spi_mutex</a>);</div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> FILE* f = fopen(file_path, <span class="stringliteral">"w+"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> (f == NULL) {</div>
|
|
<div class="line"> ESP_LOGE(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"Failed to open file for writing"</span>);</div>
|
|
<div class="line"> xSemaphoreGive(<a class="code hl_variable" href="disp__spi_8h.html#a76c0525d646735793add25b18043e600">spi_mutex</a>);</div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> fprintf(f, <span class="stringliteral">"Hello %s!\n"</span>, card->cid.name);</div>
|
|
<div class="line"> fclose(f);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> ESP_LOGI(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"Reading file %s"</span>, file_path);</div>
|
|
<div class="line"> f = fopen(file_path, <span class="stringliteral">"r"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> (f == NULL) {</div>
|
|
<div class="line"> ESP_LOGE(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"Failed to open file for reading"</span>);</div>
|
|
<div class="line"> xSemaphoreGive(<a class="code hl_variable" href="disp__spi_8h.html#a76c0525d646735793add25b18043e600">spi_mutex</a>);</div>
|
|
<div class="line"> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> <span class="keywordtype">char</span> line[64];</div>
|
|
<div class="line"> fgets(line, <span class="keyword">sizeof</span>(line), f);</div>
|
|
<div class="line"> fclose(f);</div>
|
|
<div class="line"> ESP_LOGI(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"Read <- %s"</span>, line);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> err = <a class="code hl_function" href="core2for_a_w_s_8c.html#a4c9c5029e08899a3b75a61e22cfa84a7">Core2ForAWS_SDcard_Unmount</a>(MOUNT_POINT, card);</div>
|
|
<div class="line"> xSemaphoreGive(<a class="code hl_variable" href="disp__spi_8h.html#a76c0525d646735793add25b18043e600">spi_mutex</a>);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="keywordflow">if</span>(err == ESP_OK){</div>
|
|
<div class="line"> ESP_LOGI(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"Ejected the SDCard"</span>);</div>
|
|
<div class="line"> } </div>
|
|
<div class="line"> <span class="keywordflow">else</span>{</div>
|
|
<div class="line"> ESP_LOGI(<a class="code hl_define" href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a>, <span class="stringliteral">"SDCard eject error code: %d"</span>, err);</div>
|
|
<div class="line"> }</div>
|
|
<div class="line">}</div>
|
|
<div class="ttc" id="acore2for_a_w_s_8c_html_a3d850a3f56bbe0685b60726d8b53bece"><div class="ttname"><a href="core2for_a_w_s_8c.html#a3d850a3f56bbe0685b60726d8b53bece">Core2ForAWS_Init</a></div><div class="ttdeci">void Core2ForAWS_Init(void)</div><div class="ttdoc">Initializes the power chip with default values, enables battery charging, and initializes all enabled...</div><div class="ttdef"><b>Definition:</b> core2forAWS.c:32</div></div>
|
|
<div class="ttc" id="acore2for_a_w_s_8c_html_a4c9c5029e08899a3b75a61e22cfa84a7"><div class="ttname"><a href="core2for_a_w_s_8c.html#a4c9c5029e08899a3b75a61e22cfa84a7">Core2ForAWS_SDcard_Unmount</a></div><div class="ttdeci">esp_err_t Core2ForAWS_SDcard_Unmount(const char *mount_path, sdmmc_card_t *out_card)</div><div class="ttdoc">Removes the FAT partition and unmounts the SD-Card.</div><div class="ttdef"><b>Definition:</b> core2forAWS.c:132</div></div>
|
|
<div class="ttc" id="acore2for_a_w_s_8c_html_a714fd9c7943bbec98c54dfa17d778853"><div class="ttname"><a href="core2for_a_w_s_8c.html#a714fd9c7943bbec98c54dfa17d778853">Core2ForAWS_SDcard_Mount</a></div><div class="ttdeci">esp_err_t Core2ForAWS_SDcard_Mount(const char *mount_path, sdmmc_card_t **out_card)</div><div class="ttdoc">Initializes and mounts the SD-Card.</div><div class="ttdef"><b>Definition:</b> core2forAWS.c:102</div></div>
|
|
<div class="ttc" id="acore2for_a_w_s_8h_html"><div class="ttname"><a href="core2for_a_w_s_8h.html">core2forAWS.h</a></div><div class="ttdoc">Functions to initialize and access Core2 for AWS IoT Kit hardware features.</div></div>
|
|
<div class="ttc" id="adisp__spi_8h_html_a3dc6a7525e5a0b34e37a3a64478ec9ee"><div class="ttname"><a href="disp__spi_8h.html#a3dc6a7525e5a0b34e37a3a64478ec9ee">spi_poll</a></div><div class="ttdeci">void spi_poll()</div><div class="ttdoc">Polls the SPI bus for a pending SPI transaction to complete.</div><div class="ttdef"><b>Definition:</b> disp_spi.c:34</div></div>
|
|
<div class="ttc" id="adisp__spi_8h_html_a76c0525d646735793add25b18043e600"><div class="ttname"><a href="disp__spi_8h.html#a76c0525d646735793add25b18043e600">spi_mutex</a></div><div class="ttdeci">SemaphoreHandle_t spi_mutex</div><div class="ttdoc">Semaphore for the shared SPI bus.</div><div class="ttdef"><b>Definition:</b> disp_spi.c:21</div></div>
|
|
<div class="ttc" id="ai2c__device_8c_html_afc3d101f633a076cc1ca84b85b6224b2"><div class="ttname"><a href="i2c__device_8c.html#afc3d101f633a076cc1ca84b85b6224b2">TAG</a></div><div class="ttdeci">#define TAG</div><div class="ttdef"><b>Definition:</b> i2c_device.c:10</div></div>
|
|
</div><!-- fragment --><h1><a class="anchor" id="sdcard_variables"></a>
|
|
Variables</h1>
|
|
<ul>
|
|
<li><a class="el" href="spi_mutex_variable.html">spi_mutex</a> <br />
|
|
</li>
|
|
</ul>
|
|
<h1><a class="anchor" id="sdcard_functions"></a>
|
|
Functions</h1>
|
|
<ul>
|
|
<li><a class="el" href="spi_poll_function.html">spi_poll</a> <br />
|
|
</li>
|
|
<li><a class="el" href="core2foraws_sdcard_mount_function.html">Core2ForAWS_SDcard_Mount</a> <br />
|
|
</li>
|
|
<li><a class="el" href="core2foraws_sdcard_unmount_function.html">Core2ForAWS_SDcard_Unmount</a> </li>
|
|
</ul>
|
|
</div></div><!-- contents -->
|
|
</div><!-- PageDoc -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3
|
|
</small></address>
|
|
</body>
|
|
</html>
|